Skip to content

Commit

Permalink
Added suport for maintainers stats --repo.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Mar 19, 2024
1 parent 95c7789 commit 96b8529
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 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 2023-12-22 16:34:02 UTC using RuboCop version 1.59.0.
# on 2024-03-19 16:59:49 UTC using RuboCop version 1.59.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 @@ -51,7 +51,7 @@ Lint/UselessAssignment:
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 106
Max: 122

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ You can pass a date to find out stats for a given point in time.
As of 2023-06-01, 103 repos have 202 maintainers, including 18% (19/103) of repos with at least one of 17 external maintainers.
```

You can limit to a list of repos using `--repo`.

```
./bin/project maintainers stats --repo=opensearch-project/OpenSearch --repo=opensearch-project/opensearch-py
```

Shows missing MAINTAINERS.md.

```
Expand Down
53 changes: 35 additions & 18 deletions bin/commands/maintainers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@ class Commands
g.desc 'Show MAINTAINERS.md stats.'
g.command 'stats' do |c|
c.flag %i[date], desc: 'Date at.', default_value: nil
g.flag %i[repo], multiple: true, desc: 'Search a specific repo within the org.'
c.action do |_global_options, options, _args|
org = GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project'))
dt = options[:date] ? Chronic.parse(options[:date]).to_date : nil
maintainers = org.repos.maintainers(dt)
puts "As of #{dt || Date.today}, #{org.repos.count} repos have #{maintainers.unique_count} maintainers, including #{org.repos.external_maintainers_percent}% (#{org.repos.external_maintained_size}/#{org.repos.count}) of repos with at least one of #{maintainers.external_unique_count} external maintainers."
repos = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
maintainers = repos.maintainers(dt)
puts "As of #{dt || Date.today}, #{repos.count} repos have #{maintainers.unique_count} maintainers, including #{repos.external_maintainers_percent}% (#{repos.external_maintained_size}/#{repos.count}) of repos with at least one of #{maintainers.external_unique_count} external maintainers."
puts "\n# Maintainers\n"
puts "unique: #{maintainers.unique_count}"
maintainers.each_pair do |bucket, logins|
puts "#{bucket}: #{logins.size} (#{logins.map(&:to_s).join(', ')})"
end
puts "\n# External Maintainers\n"
org.repos.maintained[:external]&.sort_by(&:name)&.each do |repo|
repos.maintained[:external]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:external]}"
end

puts "\n# Student Maintainers\n"
org.repos.maintained[:students]&.sort_by(&:name)&.each do |repo|
repos.maintained[:students]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:students]}"
end

puts "\n# Unknown Maintainers\n"
org.repos.maintained[:unknown]&.sort_by(&:name)&.each do |repo|
repos.maintained[:unknown]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:unknown]}"
end
end
Expand All @@ -37,9 +42,12 @@ class Commands
g.desc 'Audit repos for missing MAINTAINERS.md.'
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|
repos = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
repos.sort_by(&:name).select { |repo| repo.maintainers.nil? }.each do |repo|
puts repo.html_url
end
end
Expand All @@ -48,9 +56,12 @@ class Commands
g.desc 'Audit MAINTAINERS.md and CODEOWNERS.'
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|
repos = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
repos.sort_by(&:name).each do |repo|
problems = {}
repo.maintainers&.each do |user|
next if repo.codeowners&.include?(user)
Expand All @@ -77,12 +88,15 @@ class Commands
g.desc 'Audit MAINTAINERS.md that have never contributed.'
g.command 'contributors' 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 = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
total_users = 0
total_repos = 0
unique_users = Set.new
repos.each do |repo|
repos.sort_by(&:name).each do |repo|
users = repo.maintainers&.map do |user|
commits = $github.commits(repo.full_name, author: user)
next if commits.any?
Expand All @@ -103,9 +117,12 @@ class Commands
g.desc 'Compare MAINTAINERS.md and CODEOWNERS with repo permissions.'
g.command 'permissions' 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|
repos = if options[:repo]&.any?
GitHub::Repos.new(options[:repo])
else
GitHub::Organization.new(options.merge(org: options['org'] || 'opensearch-project')).repos
end
repos.sort_by(&:name).each do |repo|
if repo.oss_problems.any?
puts "#{repo.html_url}"
repo.oss_problems.each_pair do |problem, desc|
Expand Down

0 comments on commit 96b8529

Please sign in to comment.