From fc0bdab7675978e9d9a0775262a2b7054b81cabf Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 27 May 2024 18:16:12 -0400 Subject: [PATCH] Display pull requests for external contributors w/DCO emails. Signed-off-by: dblock --- bin/commands/contributors.rb | 28 +++++++++++++++++++--------- lib/github/pull_request.rb | 12 ++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bin/commands/contributors.rb b/bin/commands/contributors.rb index 8defeff..9e6b87c 100644 --- a/bin/commands/contributors.rb +++ b/bin/commands/contributors.rb @@ -2,6 +2,8 @@ module Bin class Commands + extend GitHub::RateLimited + desc 'Data about contributors.' command 'contributors' do |g| g.flag %i[page], desc: 'Size of page in days.', default_value: 7, type: Integer @@ -51,16 +53,24 @@ class Commands c.action do |_global_options, options, _args| org = GitHub::Organization.new(options) GitHub::User.wrap(GitHub::Data.external_data) do |contributor| - puts "https://github.com/#{contributor.login}" - company = contributor.company&.strip&.gsub("\n\r ", ' ') - puts " #{company}" unless company.blank? - bio = contributor.bio&.strip&.gsub("\n\r ", ' ') - puts " #{bio}" unless bio.blank? - prs = GitHub::PullRequests.new({ org: org.name, status: :merged, author: contributor }.merge(options)) - prs.each do |pr| - puts " #{pr}" + rate_limited do + company = contributor.company&.strip&.gsub("\n\r ", ' ') + bio = contributor.bio&.strip&.gsub("\n\r ", ' ') + prs = GitHub::PullRequests.new({ org: org.name, status: :merged, author: contributor }.merge(options)) + email = prs.map(&:dco_signers).flatten.reject do |s| + s.email.ends_with?('@users.noreply.github.com') || + s.email.ends_with?('@amazon.com') + end.first + puts "https://github.com/#{contributor.login}" + puts " #{email.name} <#{email.email}>" if email + puts " #{company}" unless company.blank? + puts " #{bio}" unless bio.blank? + prs.each do |pr| + puts " #{pr}" + end end - puts + rescue StandardError => e + puts "https://github.com/#{contributor.login}: #{e}\n" end end end diff --git a/lib/github/pull_request.rb b/lib/github/pull_request.rb index d5f4788..130df8d 100644 --- a/lib/github/pull_request.rb +++ b/lib/github/pull_request.rb @@ -6,6 +6,18 @@ def short_url html_url.split('/')[4..].join('/').gsub('/pull/', '#') end + def repo_url + repository_url.split('/')[4, 2].join('/') + end + + def dco_signers + commits.dco_signers + end + + def commits(options = {}) + @commits ||= GitHub::Commits.new($github.pull_request_commits(repo_url, number, options)) + end + def to_s "#{html_url}: #{title} - [@#{user.login}]" end