Skip to content

Commit

Permalink
Fix: GLI usage breaking faraday >= 2.7.0. (#41)
Browse files Browse the repository at this point in the history
* Fix: GLI usage breaking faraday >= 2.7.0.

Signed-off-by: dblock <dblock@amazon.com>

* Use commands_from.

Signed-off-by: dblock <dblock@amazon.com>

Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock authored Dec 22, 2022
1 parent 3b3cb8b commit 3716e3a
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 274 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-12-06 18:50:08 UTC using RuboCop version 1.36.0.
# on 2022-12-22 15:16:51 UTC using RuboCop version 1.36.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -125,7 +125,7 @@ RSpec/InstanceVariable:
Exclude:
- 'spec/github/progress_spec.rb'

# Offense count: 12
# Offense count: 13
RSpec/MultipleExpectations:
Max: 5

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'activesupport'
gem 'chronic'
gem 'codecov'
gem 'dotiw'
gem 'faraday'
gem 'faraday-http-cache'
gem 'faraday-retry'
gem 'gli'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ DEPENDENCIES
chronic
codecov
dotiw
faraday
faraday-http-cache
faraday-retry
gli
Expand Down
72 changes: 38 additions & 34 deletions bin/commands/contributors.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
# frozen_string_literal: true

desc 'Data about contributors.'
command 'contributors' do |g|
g.flag %i[page], desc: 'Size of page in days.', default_value: 7, type: Integer
g.flag %i[from], desc: 'Start at.', default_value: Date.today.beginning_of_week.last_week
g.flag %i[to], desc: 'End at.', default_value: Date.today.beginning_of_week - 1
g.flag %i[o org], desc: 'Name of the GitHub organization.', default_value: 'opensearch-project'
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'
module Bin
class Commands
desc 'Data about contributors.'
command 'contributors' do |g|
g.flag %i[page], desc: 'Size of page in days.', default_value: 7, type: Integer
g.flag %i[from], desc: 'Start at.', default_value: Date.today.beginning_of_week.last_week
g.flag %i[to], desc: 'End at.', default_value: Date.today.beginning_of_week - 1
g.flag %i[o org], desc: 'Name of the GitHub organization.', default_value: 'opensearch-project'
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'

g.desc 'List contributors.'
g.command 'list' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options)
org.pull_requests(options).contributors.humans.sort.uniq.each do |pr|
puts pr
g.desc 'List contributors.'
g.command 'list' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options)
org.pull_requests(options).contributors.humans.sort.uniq.each do |pr|
puts pr
end
end
end
end
end

g.desc 'Show contributor stats.'
g.command 'stats' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options)
buckets = org.pull_requests(options).contributors.buckets
puts "total = #{buckets.values.map(&:size).sum}"
buckets.each_pair do |bucket, logins|
puts "#{bucket} (#{logins.size}):"
logins.sort_by { |_k, v| -v }.each do |login, count|
puts " https://github.com/#{login}: #{count}"
g.desc 'Show contributor stats.'
g.command 'stats' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options)
buckets = org.pull_requests(options).contributors.buckets
puts "total = #{buckets.values.map(&:size).sum}"
buckets.each_pair do |bucket, logins|
puts "#{bucket} (#{logins.size}):"
logins.sort_by { |_k, v| -v }.each do |login, count|
puts " https://github.com/#{login}: #{count}"
end
end
end
end
end
end

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)
signers = org.commits(options).dco_signers
signers.sort_for_display.each do |signer|
puts signer.to_s
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)
signers = org.commits(options).dco_signers
signers.sort_for_display.each do |signer|
puts signer.to_s
end
end
end
end
end
Expand Down
98 changes: 51 additions & 47 deletions bin/commands/issues.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
# frozen_string_literal: true

desc 'Data on GitHub issues.'
command 'issue', 'issues' do |g|
g.flag %i[page], desc: 'Size of page in days.', default_value: 7, type: Integer
g.flag %i[from], desc: 'Start at.', default_value: Date.today.beginning_of_week.last_week
g.flag %i[to], desc: 'End at.', default_value: Date.today.beginning_of_week - 1
g.flag %i[o org], desc: 'Name of the GitHub organization.'
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'
module Bin
class Commands
desc 'Data on GitHub issues.'
command 'issue', 'issues' do |g|
g.flag %i[page], desc: 'Size of page in days.', default_value: 7, type: Integer
g.flag %i[from], desc: 'Start at.', default_value: Date.today.beginning_of_week.last_week
g.flag %i[to], desc: 'End at.', default_value: Date.today.beginning_of_week - 1
g.flag %i[o org], desc: 'Name of the GitHub organization.'
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'

g.desc 'List issue stats in the organization.'
g.command 'labels' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
org.issues(options).labels.sort.each do |label, issues|
puts "#{label}: #{issues.count}"
g.desc 'List issue stats in the organization.'
g.command 'labels' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
org.issues(options).labels.sort.each do |label, issues|
puts "#{label}: #{issues.count}"
end
end
end
end
end

g.desc 'Find oldest untriaged offenders.'
g.command 'untriaged' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
untriaged_issues = org.issues(options.merge(label: 'untriaged'))
puts "There are #{untriaged_issues.count} untriaged issues created between #{Chronic.parse(options[:from]).to_date} and #{Chronic.parse(options[:to]).to_date}, and #{untriaged_issues.created_before(Time.now - 3.months).count} issues older than 3 months."
puts "\n# By Repo\n"
untriaged_issues.repos.each_pair do |repo, issues|
puts "#{repo}: #{issues.count}"
end
puts "\n# Older than 3 Months\n"
untriaged_issues.created_before(Time.now - 3.months).repos.each_pair do |repo, issues|
puts "#{repo.split('/').last}: #{issues.count}"
end
puts "\n# Oldest Issues\n"
untriaged_issues.sort_by { |i| i.created_at }.take(10).each do |issue|
puts "#{issue}, created #{DOTIW::Methods.distance_of_time_in_words(issue.created_at, Time.now, highest_measures: 1)} ago"
g.desc 'Find oldest untriaged offenders.'
g.command 'untriaged' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
untriaged_issues = org.issues(options.merge(label: 'untriaged'))
puts "There are #{untriaged_issues.count} untriaged issues created between #{Chronic.parse(options[:from]).to_date} and #{Chronic.parse(options[:to]).to_date}, and #{untriaged_issues.created_before(Time.now - 3.months).count} issues older than 3 months."
puts "\n# By Repo\n"
untriaged_issues.repos.each_pair do |repo, issues|
puts "#{repo}: #{issues.count}"
end
puts "\n# Older than 3 Months\n"
untriaged_issues.created_before(Time.now - 3.months).repos.each_pair do |repo, issues|
puts "#{repo.split('/').last}: #{issues.count}"
end
puts "\n# Oldest Issues\n"
untriaged_issues.sort_by { |i| i.created_at }.take(10).each do |issue|
puts "#{issue}, created #{DOTIW::Methods.distance_of_time_in_words(issue.created_at, Time.now, highest_measures: 1)} ago"
end
end
end
end
end

g.desc 'Find issues labelled for releases.'
g.command 'released' do |c|
c.action do |_global_options, options, _args|
issues = GitHub::Issues.new(options)
puts "# Label Counts\n"
issues.version_labels.sort.each do |label, issues|
puts "#{label}: #{issues.count}"
end
puts "\n# By Repo\n"
issues.repos_version_labels.sort.each do |repo, version_labels|
puts "#{repo.split('/').last}"
version_labels.sort.each do |label, issues|
puts " #{label}: #{issues.count}"
g.desc 'Find issues labelled for releases.'
g.command 'released' do |c|
c.action do |_global_options, options, _args|
issues = GitHub::Issues.new(options)
puts "# Label Counts\n"
issues.version_labels.sort.each do |label, issues|
puts "#{label}: #{issues.count}"
end
puts "\n# By Repo\n"
issues.repos_version_labels.sort.each do |repo, version_labels|
puts "#{repo.split('/').last}"
version_labels.sort.each do |label, issues|
puts " #{label}: #{issues.count}"
end
end
end
end
end
Expand Down
110 changes: 57 additions & 53 deletions bin/commands/maintainers.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
# frozen_string_literal: true

desc 'Data about repo maintainers.'
command 'maintainers' do |g|
g.desc 'Show MAINTAINERS.md stats.'
g.command 'stats' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
all = Set.new
repos.each do |repo|
maintainers = repo.maintainers
maintainers&.each do |user|
all.add(user)
end
end
buckets = GitHub::Maintainers.new(all.to_a).buckets
puts "\n# Maintainers\n"
puts "unique: #{buckets.values.map(&:size).sum}"
buckets.each_pair do |bucket, logins|
puts "#{bucket}: #{logins.size} (#{logins.map(&:to_s).join(', ')})"
end
puts "\n# External Maintainers\n"
repos.each do |repo|
next unless repo.maintainers
module Bin
class Commands
desc 'Data about repo maintainers.'
command 'maintainers' do |g|
g.desc 'Show MAINTAINERS.md stats.'
g.command 'stats' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
all = Set.new
repos.each do |repo|
maintainers = repo.maintainers
maintainers&.each do |user|
all.add(user)
end
end
buckets = GitHub::Maintainers.new(all.to_a).buckets
puts "\n# Maintainers\n"
puts "unique: #{buckets.values.map(&:size).sum}"
buckets.each_pair do |bucket, logins|
puts "#{bucket}: #{logins.size} (#{logins.map(&:to_s).join(', ')})"
end
puts "\n# External Maintainers\n"
repos.each do |repo|
next unless repo.maintainers

external_maintainers = repo.maintainers & buckets[:external]
next unless external_maintainers&.any?
external_maintainers = repo.maintainers & buckets[:external]
next unless external_maintainers&.any?

puts "#{repo.html_url}: #{external_maintainers}"
end
puts "\n# Unknown Maintainers\n"
repos.each do |repo|
next unless repo.maintainers
puts "#{repo.html_url}: #{external_maintainers}"
end
puts "\n# Unknown Maintainers\n"
repos.each do |repo|
next unless repo.maintainers

unknown_maintainers = repo.maintainers & buckets[:unknown]
next unless unknown_maintainers&.any?
unknown_maintainers = repo.maintainers & buckets[:unknown]
next unless unknown_maintainers&.any?

puts "#{repo.html_url}: #{unknown_maintainers}"
puts "#{repo.html_url}: #{unknown_maintainers}"
end
end
end
end
end

g.command 'missing' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
repos.select { |repo| repo.maintainers.nil? }.each do |repo|
puts repo.html_url
g.command 'missing' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
repos.select { |repo| repo.maintainers.nil? }.each do |repo|
puts repo.html_url
end
end
end
end
end

g.desc 'Audit MAINTAINERS.md for users that have never contributed.'
g.command 'audit' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
repos.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers&.count}"
repo.maintainers&.each do |user|
commits = $github.commits(repo.full_name, author: user)
puts " #{user}: #{commits.count}" if commits.none?
g.desc 'Audit MAINTAINERS.md for users that have never contributed.'
g.command 'audit' do |c|
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
repos = org.repos.sort_by(&:name)
repos.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers&.count}"
repo.maintainers&.each do |user|
commits = $github.commits(repo.full_name, author: user)
puts " #{user}: #{commits.count}" if commits.none?
end
end
end
end
end
Expand Down
22 changes: 13 additions & 9 deletions bin/commands/members.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

desc 'Data about org members.'
command 'members' do |g|
g.desc 'Check GitHub affiliation information for contributors.'
g.command 'check' do |c|
c.action do |_global_options, _options, _args|
GitHub::User.wrap(GitHub::Data.members).each do |contributor|
unless contributor.member?
puts "#{contributor.login}: #{[contributor.company,
contributor.bio].compact.join(' ')}"
module Bin
class Commands
desc 'Data about org members.'
command 'members' do |g|
g.desc 'Check GitHub affiliation information for contributors.'
g.command 'check' do |c|
c.action do |_global_options, _options, _args|
GitHub::User.wrap(GitHub::Data.members).each do |contributor|
unless contributor.member?
puts "#{contributor.login}: #{[contributor.company,
contributor.bio].compact.join(' ')}"
end
end
end
end
end
Expand Down
Loading

0 comments on commit 3716e3a

Please sign in to comment.