-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create tool for getting DCO sign off emails #34
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Commit < Item | ||
# Creates an array of Signers from all 'Signed-off-by' tags included in the | ||
# commit message | ||
def dco_signers | ||
commit.message.scan(/Signed-off-by: (.+) <([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+)>/).map do |signer| | ||
Signer.new(signer[0], signer[1]) | ||
end | ||
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Commits < Items | ||
def initialize(arr_or_options) | ||
super arr_or_options, GitHub::Commit | ||
end | ||
|
||
# Gets all unique DCO signers (by email address) from all commits | ||
def dco_signers | ||
Signers.new(each.map(&:dco_signers).flatten) | ||
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 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Signer | ||
attr_reader :email, :name | ||
|
||
def initialize(name, email) | ||
@name = name | ||
@email = email | ||
end | ||
|
||
def to_s | ||
"#{name},#{email}" | ||
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitHub | ||
class Signers < Array | ||
def initialize(arr) | ||
# De-dupe by email address, choosing the "best" name | ||
by_email = {} | ||
arr.each do |signer| | ||
by_email[signer.email] = best_signer(by_email[signer.email], signer) | ||
end | ||
super by_email.values | ||
end | ||
|
||
# Sort all "noreply" email addresses to the bottom (for manual curation), then sort by name | ||
def sort_for_display | ||
Signers.new(sort_by { |signer| [signer.email.include?('noreply') ? 1 : 0, signer.name.downcase] }) | ||
end | ||
|
||
private | ||
|
||
def best_signer(left, right) | ||
# The "best" name is defined by the name with the most words. For example, | ||
# if both "dblock" and "Daniel (dB.) Doubrovkine" are encountered, then | ||
# "Daniel (dB.) Doubrovkine" will be chosen. | ||
if left.nil? || right.name.split.length > left.name.split.length | ||
right | ||
else | ||
left | ||
end | ||
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
696 changes: 696 additions & 0 deletions
696
spec/fixtures/search/opensearch-project/commits_2022-01-01_2022-01-31.yml
Large diffs are not rendered by default.
Oops, something went wrong.
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
describe GitHub::Commit do | ||
subject(:commit) do | ||
message = %{Bump opencensus-contrib-http-util from 0.18.0 to 0.31.1 in /plugins/repository-gcs (#3633) | ||
|
||
* Bump opencensus-contrib-http-util in /plugins/repository-gcs | ||
|
||
Bumps [opencensus-contrib-http-util](https://github.com/census-instrumentation/opencensus-java) from 0.18.0 to 0.31.1. | ||
- [Release notes](https://github.com/census-instrumentation/opencensus-java/releases) | ||
- [Changelog](https://github.com/census-instrumentation/opencensus-java/blob/master/CHANGELOG.md) | ||
- [Commits](census-instrumentation/opencensus-java@v0.18.0...v0.31.1) | ||
|
||
--- | ||
updated-dependencies: | ||
- dependency-name: io.opencensus:opencensus-contrib-http-util | ||
dependency-type: direct:production | ||
update-type: version-update:semver-minor | ||
... | ||
|
||
Signed-off-by: dependabot[bot] <support@github.com> | ||
|
||
* Updating SHAs | ||
|
||
Signed-off-by: dependabot[bot] <support@github.com> | ||
|
||
* Adding missing classes | ||
|
||
Signed-off-by: Vacha Shah <vachshah@amazon.com> | ||
|
||
* changelog change | ||
|
||
Signed-off-by: Poojita Raj <poojiraj@amazon.com> | ||
|
||
Signed-off-by: dependabot[bot] <support@github.com> | ||
Signed-off-by: Vacha Shah <vachshah@amazon.com> | ||
Signed-off-by: Poojita Raj <poojiraj@amazon.com> | ||
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | ||
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> | ||
Co-authored-by: Vacha Shah <vachshah@amazon.com> | ||
Co-authored-by: Poojita Raj <poojiraj@amazon.com> | ||
} | ||
resource = Sawyer::Resource.new(Sawyer::Agent.new('fake'), { commit: { message: message } }) | ||
described_class.new(resource) | ||
end | ||
|
||
it 'parses signers from a commit message' do | ||
expect(commit.dco_signers.count).to eq 7 | ||
expect(commit.dco_signers.map(&:name)).to eq ['dependabot[bot]', 'dependabot[bot]', 'Vacha Shah', 'Poojita Raj', 'dependabot[bot]', 'Vacha Shah', 'Poojita Raj'] | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
describe GitHub::Commits do | ||
context 'with contributors' do | ||
context 'with org' do | ||
context 'with january 2022' do | ||
context 'with OpenSearch commits', vcr: { cassette_name: 'search/opensearch-project/commits_2022-01-01_2022-01-31' } do | ||
subject(:commits) do | ||
described_class.new(org: 'opensearch-project', repo: 'OpenSearch', from: Date.new(2022, 1, 1), to: Date.new(2022, 1, 31), page: 7) | ||
end | ||
|
||
it 'fetches commits between two dates' do | ||
expect(commits.count).to eq 62 | ||
expect(commits.first['sha']).to eq 'db23f72a2a5da1f21d674bde3a9d1cbe4fb74b19' | ||
end | ||
|
||
it 'collects DCO signers from commits' do | ||
expect(commits.dco_signers.count).to eq 25 | ||
expect(commits.dco_signers.first.name).to eq 'Tianli Feng' | ||
end | ||
end | ||
end | ||
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
describe GitHub::Signers do | ||
context 'with duplicate emails' do | ||
subject(:signers) do | ||
described_class.new([ | ||
GitHub::Signer.new('dev', 'dev@opensearch.org'), | ||
GitHub::Signer.new('Dev Eloper', 'dev@opensearch.org'), | ||
GitHub::Signer.new('Dev Eloper, Esq.', 'dev@opensearch.org') | ||
]) | ||
end | ||
|
||
it 'chooses the best name' do | ||
expect(signers.size).to eq(1) | ||
expect(signers.first.name).to eq('Dev Eloper, Esq.') | ||
end | ||
end | ||
|
||
context 'with noreply email addresses' do | ||
subject(:signers) do | ||
described_class.new([ | ||
GitHub::Signer.new('Mis Configurer', 'noreply@github.com'), | ||
GitHub::Signer.new('dev', 'dev@opensearch.org') | ||
]) | ||
end | ||
|
||
it 'sorts noreply email addresses to the end' do | ||
expect(signers.size).to eq(2) | ||
expect(signers.sort_for_display.first.email).to eq('dev@opensearch.org') | ||
expect(signers.sort_for_display.last.email).to eq('noreply@github.com') | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue for exporting CSV in a generic way, #18.
How about we change this to be called "emails" and output something non-structured, then implement the CSV thing generically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still looking at what it would take to wire in more generic csv support.