Skip to content

Commit

Permalink
Display % in a table format and add support for :unmerged (#33)
Browse files Browse the repository at this point in the history
* Refactor buckets into a module.

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>

* Show stats for all categories.

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>

* Added --status=merged/unmerged.

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>

* Correct % totals.

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>

Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
  • Loading branch information
dblock authored Nov 9, 2022
1 parent 29256b6 commit 8abfdfd
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GITHUB_API_TOKEN=

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.cache
data
.DS_Store
coverage
.env




24 changes: 15 additions & 9 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-10-31 20:37:54 UTC using RuboCop version 1.36.0.
# on 2022-11-09 00:31:07 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 @@ -53,7 +53,7 @@ Naming/MethodParameterName:
Exclude:
- 'lib/github/item.rb'

# Offense count: 18
# Offense count: 20
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand Down Expand Up @@ -83,7 +83,7 @@ RSpec/DescribeClass:
- 'spec/project/commands/repos_spec.rb'
- 'spec/project/project_spec.rb'

# Offense count: 16
# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
Expand All @@ -107,7 +107,7 @@ RSpec/EmptyExampleGroup:
- 'spec/project/commands/members_spec.rb'
- 'spec/project/commands/repos_spec.rb'

# Offense count: 4
# Offense count: 5
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 6
Expand Down Expand Up @@ -138,11 +138,11 @@ RSpec/InstanceVariable:
Exclude:
- 'spec/github/progress_spec.rb'

# Offense count: 6
# Offense count: 7
RSpec/MultipleExpectations:
Max: 5

# Offense count: 24
# Offense count: 27
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
Expand All @@ -151,10 +151,10 @@ RSpec/NamedSubject:
- 'spec/github/progress_spec.rb'
- 'spec/github/pull_requests_spec.rb'

# Offense count: 6
# Offense count: 8
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4
Max: 5

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand All @@ -170,7 +170,7 @@ Style/ClassAndModuleChildren:
Exclude:
- 'spec/support/without_data_files.rb'

# Offense count: 3
# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Expand All @@ -187,6 +187,12 @@ Style/IdenticalConditionalBranches:
Exclude:
- 'lib/github/repo.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapToHash:
Exclude:
- 'lib/github/buckets.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns, IgnoredMethods.
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ Shows bucketed contributions.
Between 2022-10-03 and 2022-10-09, 5% of contributions (18/346) were made by 9 external contributors (9/102).
members: 69%
external: 5%
contractors: 8%
https://github.com/opensearch-project/project-website/pull/1024: add tracetest as a partner - [@mathnogueira]
https://github.com/opensearch-project/project-website/pull/1023: Add Hyland as partner - [@aborroy]
https://github.com/opensearch-project/opensearch-php/pull/85: Unset port for SigV4Handler, fixes #84 - [@shyim]
Expand Down Expand Up @@ -214,6 +218,12 @@ Get the stats for an entire org and several repos.
./bin/project prs stats --org=opensearch-project --repo=aws/aws-cli --repo=aws/deep-learning-containers
```

Get the stats for unmerged (open and closed without being merged) PRs.

```
./bin/project prs stats --status=unmerged
```

#### Issues

Shows issues bucketed by label.
Expand Down
12 changes: 10 additions & 2 deletions bin/commands/pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.switch %i[ignore-unknown], desc: 'Ignore unknown users.', default_value: false
g.flag %i[status], desc: 'Query for opened or merged pull requests.', default_value: :merged, must_match: %i[merged unmerged]

g.desc 'List pull requests in the organization.'
g.command 'list' do |c|
Expand All @@ -23,6 +24,7 @@
g.command 'stats' do |c|
c.action do |_global_options, options, _args|
prs = GitHub::PullRequests.new(options)

if !options['ignore-unknown'] && prs.contributors[:unknown]&.any?
puts 'Add the following users to either data/users/members.txt, external.txt or contractors.txt and re-run.'
prs.contributors[:unknown].keys.take(10).each do |user|
Expand All @@ -32,8 +34,14 @@
else
puts "Between #{Chronic.parse(options[:from]).to_date} and #{Chronic.parse(options[:to]).to_date}, #{prs.all_external_percent}% of contributions (#{prs.all_external.size}/#{prs.size}) were made by #{prs.contributors.all_external.size} external contributors (#{prs.contributors.all_external.size}/#{prs.contributors.humans.uniq.size})."
puts ''
prs[:external]&.each do |pr|
puts pr
prs.percent.each_pair do |k, v|
puts "#{k}: #{v}% (#{prs.buckets[k].size})"
end
if prs[:external]&.size&.< 25
puts ''
prs[:external]&.each do |pr|
puts pr
end
end
end
end
Expand Down
66 changes: 66 additions & 0 deletions lib/github/buckets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

module GitHub
module Buckets
def members
buckets[:members] || []
end

def contractors
buckets[:contractors] || []
end

def external
buckets[:external] || []
end

def unknown
buckets[:unknown] || []
end

def all
to_a
end

def all_members
members.concat(contractors)
end

def all_external
external
end

def all_external_percent
return 0 unless all.any?

((all_external.size.to_f / all.size) * 100).to_i
end

def percent
buckets.map do |k, v|
pc = ((v.size.to_f / all.size) * 100).round(1)
[k, pc]
end.to_h
end

def self.bucket(username)
if GitHub::Data.members.include?(username.to_s)
:members
elsif GitHub::Data.contractors.include?(username.to_s)
:contractors
elsif GitHub::Data.external_users.include?(username.to_s)
:external
else
:unknown
end
end

def [](bucket)
buckets[bucket]
end

def buckets
raise NotImplementedError, :buckets
end
end
end
31 changes: 1 addition & 30 deletions lib/github/contributors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module GitHub
class Contributors < Items
extend GitHub::Data
include GitHub::Buckets

def initialize(arr)
super arr, Contributor
Expand All @@ -12,40 +13,10 @@ def humans
reject { |item| item.type == 'Bot' || GitHub::Data.bots.include?(item.to_s) }
end

def members
buckets[:members] || []
end

def contractors
buckets[:contractors] || []
end

def external
buckets[:external] || []
end

def unknown
buckets[:unknown] || []
end

def all
humans
end

def all_members
members.concat(contractors)
end

def all_external
external
end

def all_external_percent
return 0 unless all.any?

((all_external.size.to_f / all.size) * 100).to_i
end

def self.bucket(username)
if GitHub::Data.members.include?(username.to_s)
:members
Expand Down
2 changes: 1 addition & 1 deletion lib/github/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(id_or_obj, m = nil)
def self.wrap(collection)
result = []
rate_limited do
collection.each do |obj|
collection&.each do |obj|
result.push(new(obj))
end
end
Expand Down
38 changes: 1 addition & 37 deletions lib/github/maintainers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,7 @@

module GitHub
class Maintainers < Array
def members
buckets[:members] || []
end

def contractors
buckets[:contractors] || []
end

def external
buckets[:external] || []
end

def unknown
buckets[:unknown] || []
end

def [](bucket)
buckets[bucket] || []
end

def all
to_a
end

def internal
members.concat(contractors)
end

def all_external
external
end

def all_external_percent
return 0 unless all.any?

((all_external.size.to_f / all.size) * 100).to_i
end
include GitHub::Buckets

def buckets
@buckets ||= begin
Expand Down
2 changes: 1 addition & 1 deletion lib/github/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def teams
end

def pull_requests(options = {})
@pull_requests ||= GitHub::PullRequests.new({ org: name }.merge(options))
@pull_requests ||= GitHub::PullRequests.new({ org: name, status: :merged }.merge(options))
end

def issues(options = {})
Expand Down
Loading

0 comments on commit 8abfdfd

Please sign in to comment.