Class: Danger::DangerMailmap

Inherits:
Plugin
  • Object
show all
Defined in:
lib/danger_plugin.rb

Overview

A Danger plugin to check if .mailmap has a canonical name of author and committer.

Examples:

Check all commits in the pull request against the top-level .mailmap.


mailmap.check

Check against mailmap file in custom location with ignoring some users.


mailmap.allowed_patterns = [
  /.+@(users\.noreply\.)?github\.com/,
  '[email protected]'
]
mailmap.check '/path/to/mailmap'

See Also:

  • manicmaniac/danger-mailmap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ DangerMailmap

Returns a new instance of DangerMailmap.



36
37
38
39
# File 'lib/danger_plugin.rb', line 36

def initialize(*args)
  super(*args)
  self.show_suggestion = true
end

Instance Attribute Details

#allowed_patternsArray<String, Regexp>

Regular expression patterns of email where ‘danger-mailmap` does not warn like allow-list. If a string is set, it is considered as fixed pattern.

Returns:

  • (Array<String, Regexp>)


30
31
32
# File 'lib/danger_plugin.rb', line 30

def allowed_patterns
  @allowed_patterns
end

#show_suggestionBoolean

If ‘true`, `danger-mailmap` will add suggestion comments to a pull request (`true` by default).

Returns:

  • (Boolean)


34
35
36
# File 'lib/danger_plugin.rb', line 34

def show_suggestion
  @show_suggestion
end

Instance Method Details

#check(path = nil) ⇒ void

This method returns an undefined value.

Check whether if an author of each commits has proper email.

Parameters:

  • path (String) (defaults to: nil)

    Path to .mailmap file (default $GIT_WORK_TREE/.mailmap).



45
46
47
48
49
50
51
52
53
# File 'lib/danger_plugin.rb', line 45

def check(path = nil)
  path = path ? File.expand_path(path) : File.join(git_working_dir, '.mailmap')
  mailmap = Mailmap::Map.load(path)
  commits_by_emails = commits_by_unknown_emails(mailmap)
  return if commits_by_emails.empty?

  commits_by_emails.each { |email, commits| warn(format_warning(path, email, commits)) }
  markdown(suggestion(path, commits_by_emails.keys)) if show_suggestion
end