Class: Danger::DangerMissingCodeowners
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerMissingCodeowners
- Defined in:
- lib/missing_codeowners/plugin.rb
Overview
Parses the CODEOWNERS file and verifies if files have at least one owner. Works with GitHub and GitLab. Results are passed out as a table in markdown.
Instance Attribute Summary collapse
-
#files_missing_codeowners ⇒ Array<String>
The list of files that are missing owners.
-
#max_number_of_files_to_report ⇒ Int
The maximum number of files missing owners Danger should report.
-
#severity ⇒ String
Defines the severity level of the execution.
-
#verbose ⇒ Bool
Provides additional logging diagnostic information.
-
#verify_all_files ⇒ Bool
Whether all files or only ones in PR diff to be reported.
Instance Method Summary collapse
-
#verify(files = nil) ⇒ void
Verifies files for missing owners.
Instance Attribute Details
#files_missing_codeowners ⇒ Array<String>
The list of files that are missing owners.
21 22 23 |
# File 'lib/missing_codeowners/plugin.rb', line 21 def files_missing_codeowners @files_missing_codeowners end |
#max_number_of_files_to_report ⇒ Int
The maximum number of files missing owners Danger should report. Default is 100.
31 32 33 |
# File 'lib/missing_codeowners/plugin.rb', line 31 def max_number_of_files_to_report @max_number_of_files_to_report end |
#severity ⇒ String
Defines the severity level of the execution. Possible values are: ‘error’ or ‘warning’. Default is ‘error’.
36 37 38 |
# File 'lib/missing_codeowners/plugin.rb', line 36 def severity @severity end |
#verbose ⇒ Bool
Provides additional logging diagnostic information. Default is false.
41 42 43 |
# File 'lib/missing_codeowners/plugin.rb', line 41 def verbose @verbose end |
#verify_all_files ⇒ Bool
Whether all files or only ones in PR diff to be reported. Default is false.
26 27 28 |
# File 'lib/missing_codeowners/plugin.rb', line 26 def verify_all_files @verify_all_files end |
Instance Method Details
#verify(files = nil) ⇒ void
This method returns an undefined value.
Verifies files for missing owners. Generates a ‘markdown` list of warnings for the prose in a corpus of .markdown and .md files.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/missing_codeowners/plugin.rb', line 53 def verify(files = nil) @verify_all_files ||= false @max_number_of_files_to_report ||= 100 @severity ||= "error" @verbose ||= false files_to_verify = files || files_from_git log "Files to verify:" log files_to_verify.join("\n") codeowners_path = find_codeowners_file codeowners_lines = read_codeowners_file(codeowners_path) codeowners_spec = parse_codeowners_spec(codeowners_lines) @files_missing_codeowners = files_to_verify.reject { |file| codeowners_spec.match file } if @files_missing_codeowners.any? log "Files missing CODEOWNERS:" log @files_missing_codeowners.join("\n") markdown (@files_missing_codeowners, @max_number_of_files_to_report) = "Add CODEOWNERS rules to match all files." @severity == "error" ? (fail ) : (warn ) else log "No files missing CODEOWNERS." end log "-----" end |