From 2071ba47b2d0255da260b195bb952c89c672a9cd Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Mon, 27 May 2024 10:30:40 -0400 Subject: [PATCH] Display pull requests for external contributors. (#86) Signed-off-by: dblock --- README.md | 6 ++++++ bin/commands/contributors.rb | 21 ++++++++++++++++++++- lib/github/item.rb | 4 +++- lib/github/pull_requests.rb | 3 ++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2dd1a0d..d298e01 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,12 @@ Specify multiple repos. ./bin/project contributors list --org=aws --repo=aws-cli --repo=deep-learning-containers ``` +Display pull requests for external contributors. + +``` +./bin/project --quiet contributors prs --from=2021-03-14 --page=365 +``` + #### Pull Requests Show a list of pull requests. diff --git a/bin/commands/contributors.rb b/bin/commands/contributors.rb index 1e95877..8defeff 100644 --- a/bin/commands/contributors.rb +++ b/bin/commands/contributors.rb @@ -35,7 +35,7 @@ class Commands end end - g.desc 'Create a list of all DCO signers' + g.desc 'Create a list of all DCO signers.' g.command 'dco-signers' do |c| c.action do |_global_options, options, _args| org = GitHub::Organization.new(options) @@ -45,6 +45,25 @@ class Commands end end end + + g.desc 'Display pull requests for external contributors.' + g.command 'prs' do |c| + 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}" + end + puts + end + end + end end end end diff --git a/lib/github/item.rb b/lib/github/item.rb index 74c140c..7a0807d 100644 --- a/lib/github/item.rb +++ b/lib/github/item.rb @@ -21,7 +21,9 @@ def self.wrap(collection) rate_limited do collection&.each do |obj| rate_limited do - result.push(obj.is_a?(Item) ? obj : new(obj)) + item = obj.is_a?(Item) ? obj : new(obj) + yield item if block_given? + result.push(item) end end end diff --git a/lib/github/pull_requests.rb b/lib/github/pull_requests.rb index 31ef3a9..8dde5b0 100644 --- a/lib/github/pull_requests.rb +++ b/lib/github/pull_requests.rb @@ -40,7 +40,8 @@ def query(options = {}) 'is:pull-request', 'archived:false', options[:status] == :merged ? 'is:closed' : 'is:unmerged', - options[:status] == :merged ? "merged:#{options[:from]}..#{options[:to]}" : "created:#{options[:from]}..#{options[:to]}" + options[:status] == :merged ? "merged:#{options[:from]}..#{options[:to]}" : "created:#{options[:from]}..#{options[:to]}", + options[:author] ? "author:#{options[:author]}" : nil ].compact ).compact.join(' ') end