-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create tool for getting DCO sign off emails
This tool digs through commit messages and parses out names and email addresses from the `Signed-off-by:` tags, collects all unique email addresses and outputs a CSV of name/email pairs. Signed-off-by: Andrew Ross <[email protected]>
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Commit < Item | ||
# Association list of all name/email pairs extracted from the DCO sign off | ||
# in the commit message | ||
def dco_signoff_names_and_mails | ||
commit.message.scan(/Signed-off-by: (.+) <([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+)>/) | ||
end | ||
|
||
def to_s | ||
"#{repository.full_name} - #{commit.author.email} - #{sha}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Commits < Items | ||
def initialize(arr_or_options) | ||
super arr_or_options, GitHub::Commit | ||
end | ||
|
||
def unique_dco_signers_csv | ||
# Create an association list of all name->email pairs, e.g: | ||
# [['John Lennon', '[email protected]'], ['Paul McCartney', '[email protected]']] | ||
signers_list = each.map(&:dco_signoff_names_and_mails).flatten(1) | ||
|
||
# De-dupe all entries by email address into an email=>[name1,name2] hash | ||
email_to_names = {} | ||
signers_list.each do |signer| | ||
name = signer[0] | ||
email = signer[1] | ||
email_to_names[email] = [] unless email_to_names.include?(email) | ||
email_to_names[email].push(name) | ||
end | ||
|
||
email_to_names.to_a | ||
# For each email pick the best name and then reverse the association | ||
.map { |e| [single_best_name(e[1]), e[0]] } | ||
# Sort all "noreply" email addresses to the bottom (for manual curation), then sort by name | ||
.sort_by { |e| [e[1].include?('noreply') ? 1 : 0, e[0].downcase] } | ||
.map { |e| e.join(',') } | ||
.join("\n") | ||
end | ||
|
||
def page(options) | ||
data = $github.search_commits(query(options), per_page: 1000).items | ||
raise 'There are 1000+ commits returned from a single query, reduce --page.' if data.size >= 1000 | ||
|
||
data.reject do |commit| | ||
commit.commit.author.email.include?('[bot]') | ||
end | ||
end | ||
|
||
def query(options = {}) | ||
GitHub::Searchables.new(options).to_a.concat( | ||
[ | ||
"committer-date:#{options[:from]}..#{options[:to]}" | ||
] | ||
).compact.join(' ') | ||
end | ||
|
||
private | ||
|
||
# This is a simple heuristic for picking the "best" name by choosing the | ||
# one with the most words. For example, if we find both "paul" and | ||
# "Paul McCartney" then we'll choose "Paul McCartney". | ||
def single_best_name(names) | ||
names.max { |a, b| a.split.length <=> b.split.length } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters