Class: Danger::DangerMissingCodeowners

Inherits:
Plugin
  • Object
show all
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.

Examples:

Verifying files missing codeowners.


missing_codeowners.verify

See Also:

  • andre-alves/danger-missing_codeowners

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#files_missing_codeownersArray<String>

The list of files that are missing owners.

Returns:

  • (Array<String>)


21
22
23
# File 'lib/missing_codeowners/plugin.rb', line 21

def files_missing_codeowners
  @files_missing_codeowners
end

#max_number_of_files_to_reportInt

The maximum number of files missing owners Danger should report. Default is 100.

Returns:

  • (Int)


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

#severityString

Defines the severity level of the execution. Possible values are: ‘error’ or ‘warning’. Default is ‘error’.

Returns:

  • (String)


36
37
38
# File 'lib/missing_codeowners/plugin.rb', line 36

def severity
  @severity
end

#verboseBool

Provides additional logging diagnostic information. Default is false.

Returns:

  • (Bool)


41
42
43
# File 'lib/missing_codeowners/plugin.rb', line 41

def verbose
  @verbose
end

#verify_all_filesBool

Whether all files or only ones in PR diff to be reported. Default is false.

Returns:

  • (Bool)


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.

Parameters:

  • files (String) (defaults to: nil)

    The list of files you want to verify, defaults to nil. if nil, modified and added files from the diff will be used.



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 format_missing_owners_message(@files_missing_codeowners, @max_number_of_files_to_report)
    danger_message = "Add CODEOWNERS rules to match all files."
    @severity == "error" ? (fail danger_message) : (warn danger_message)
  else
    log "No files missing CODEOWNERS."
  end

  log "-----"
end