Skip to content

Commit

Permalink
Consider contractors and students as external in metrics.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Mar 25, 2024
1 parent 25c77e2 commit 4a7a5d2
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 71 deletions.
44 changes: 23 additions & 21 deletions bin/commands/maintainers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,34 @@ class Commands
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, where #{maintainers.external_unique_percent}% (#{maintainers.external_unique_count}/#{maintainers.unique_count}) are external."
puts "A total of #{repos.external_maintainers_percent}% (#{repos.external_maintained_size}/#{repos.count}) of repos have 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 "As of #{dt || Date.today}, #{repos.count} repos have #{maintainers.unique_count} maintainers, where #{maintainers.all_external_unique_percent}% (#{maintainers.all_external_unique_count}/#{maintainers.unique_count}) are external."
puts "A total of #{repos.all_external_maintainers_percent}% (#{repos.all_external_maintained_size}/#{repos.count}) of repos have at least one of #{maintainers.all_external_unique_count} external maintainers."

puts "\n# External Maintainers\n"
repos.maintained[:external]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:external]} (#{repo.maintainers.external_unique_percent}%, #{repo.maintainers.external_unique_count}/#{repo.maintainers.unique_count})"
repos.externally_maintained.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers.all_external} (#{repo.maintainers.all_external_unique_percent}%, #{repo.maintainers.all_external_unique_count}/#{repo.maintainers.unique_count})"
end

puts "\n# Student Maintainers\n"
repos.maintained[:students]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:students]}"
end
# GitHub::Maintainers::ALL_EXTERNAL.each do |bucket|
# repos.maintained[bucket]&.sort_by(&:name)&.each do |repo|
# puts "#{repo.html_url}: #{repo.maintainers.all_external} (#{repo.maintainers.all_external_unique_percent}%, #{repo.maintainers.all_external_unique_count}/#{repo.maintainers.unique_count})"
# end
# end

puts "\n# Contractor Maintainers\n"
repos.maintained[:contractors]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:contractors]}"
end
# puts "\n# All 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# Unknown Maintainers\n"
repos.maintained[:unknown]&.sort_by(&:name)&.each do |repo|
puts "#{repo.html_url}: #{repo.maintainers[:unknown]}"
end
# %i[external students contractors unknown].each do |bucket|
# next unless repos.maintained[bucket]&.any?

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

Expand Down
2 changes: 1 addition & 1 deletion bin/commands/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Commands
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|
GitHub::User.wrap(GitHub::Data.members_data).each do |contributor|
unless contributor.member?
puts "#{contributor.login}: #{[contributor.company,
contributor.bio].compact.join(' ')}"
Expand Down
4 changes: 2 additions & 2 deletions bin/commands/org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Commands
org = GitHub::Organization.new(options)
puts "org: #{org.name}"
puts "members: #{org.members.count}"
puts "missing in data/users/members.txt: #{(org.members.logins - GitHub::Data.members).join(' ')}"
puts "no longer members: #{(GitHub::Data.members - org.members.logins).join(' ')}"
puts "missing in data/users/members.txt: #{(org.members.logins - GitHub::Data.members_data).join(' ')}"
puts "no longer members: #{(GitHub::Data.members_data - org.members.logins).join(' ')}"
end
end

Expand Down
20 changes: 13 additions & 7 deletions lib/github/buckets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ def all_humans
end

def all_members
members.to_a + contractors.to_a
members.to_a

Check warning on line 38 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L38

Added line #L38 was not covered by tests
end

def all_external
external.to_a + students.to_a
all = []
Maintainers::ALL_EXTERNAL.each do |bucket|
next unless buckets[bucket]

Check warning on line 44 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L42-L44

Added lines #L42 - L44 were not covered by tests

all.concat(buckets[bucket].to_a)

Check warning on line 46 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L46

Added line #L46 was not covered by tests
end
all

Check warning on line 48 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L48

Added line #L48 was not covered by tests
end

def all_external_percent
Expand All @@ -56,15 +62,15 @@ def percent
end

def self.bucket(username)
if GitHub::Data.members.include?(username.to_s)
if GitHub::Data.members_data.include?(username.to_s)

Check warning on line 65 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L65

Added line #L65 was not covered by tests
:members
elsif GitHub::Data.contractors.include?(username.to_s)
elsif GitHub::Data.contractors_data.include?(username.to_s)

Check warning on line 67 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L67

Added line #L67 was not covered by tests
:contractors
elsif GitHub::Data.college_contributors.include?(username.to_s)
elsif GitHub::Data.students_data.include?(username.to_s)

Check warning on line 69 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L69

Added line #L69 was not covered by tests
:students
elsif GitHub::Data.external_users.include?(username.to_s)
elsif GitHub::Data.external_data.include?(username.to_s)

Check warning on line 71 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L71

Added line #L71 was not covered by tests
:external
elsif GitHub::Data.bots.include?(username.to_s)
elsif GitHub::Data.bots_data.include?(username.to_s)

Check warning on line 73 in lib/github/buckets.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/buckets.rb#L73

Added line #L73 was not covered by tests
:bots
else
:unknown
Expand Down
14 changes: 7 additions & 7 deletions lib/github/contributors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ def initialize(arr)
end

def humans
reject { |item| item.type == 'Bot' || GitHub::Data.bots.include?(item.to_s) }
reject { |item| item.type == 'Bot' || GitHub::Data.bots_data.include?(item.to_s) }

Check warning on line 13 in lib/github/contributors.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/contributors.rb#L13

Added line #L13 was not covered by tests
end

def all
humans
end

def self.bucket(username)
if GitHub::Data.members.include?(username.to_s)
if GitHub::Data.members_data.include?(username.to_s)
:members
elsif GitHub::Data.contractors.include?(username.to_s)
elsif GitHub::Data.contractors_data.include?(username.to_s)
:contractors
elsif GitHub::Data.students.include?(username.to_s)
:external # :students
elsif GitHub::Data.external_users.include?(username.to_s)
elsif GitHub::Data.students_data.include?(username.to_s)
:students

Check warning on line 26 in lib/github/contributors.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/contributors.rb#L26

Added line #L26 was not covered by tests
elsif GitHub::Data.external_data.include?(username.to_s)
:external
elsif GitHub::Data.bots.include?(username.to_s)
elsif GitHub::Data.bots_data.include?(username.to_s)
:bots
else
:unknown
Expand Down
52 changes: 28 additions & 24 deletions lib/github/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,52 @@ def data
DATA
end

def backports
@backports ||= load_list(BACKPORTS)
def backports_data
@backports_data ||= load_list(BACKPORTS)
end

def members
@members ||= load_list(MEMBERS)
def members_data
@members_data ||= load_list(MEMBERS)
end

def contractors
@contractors ||= load_list(CONTRACTORS)
def contractors_data
@contractors_data ||= load_list(CONTRACTORS)
end

def external_users
@external_users ||= load_list(EXTERNAL)
def external_data
@external_data ||= load_list(EXTERNAL)
end

def students
@students ||= load_list(STUDENTS)
def students_data
@students_data ||= load_list(STUDENTS)
end

def check_dups!
%i[members contractors students external_users].combination(2).each do |l, r|
send(l).intersection(send(r)).each do |user|
warn "WARNING: #{user} is found in both #{l} and #{r}"
end
end
def bots_data
@bots_data ||= load_list(BOTS)
end

def bots
@bots ||= load_list(BOTS)
def companies_data
@companies_data ||= load_list(COMPANIES)

Check warning on line 54 in lib/github/data.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/data.rb#L54

Added line #L54 was not covered by tests
end

def companies
@companies ||= load_list(COMPANIES)
def all_members_data
members_data

Check warning on line 58 in lib/github/data.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/data.rb#L58

Added line #L58 was not covered by tests
end

def all_members
members + contractors
def check_dups!
%i[members_data contractors_data students_data external_data].combination(2).each do |l, r|
send(l).intersection(send(r)).each do |user|
warn "WARNING: #{user} is found in both #{l} and #{r}"

Check warning on line 64 in lib/github/data.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/data.rb#L62-L64

Added lines #L62 - L64 were not covered by tests
end
end
end

def all_external
external_users + students
def all_external_data
all = []
Maintainers::ALL_EXTERNAL.each do |bucket|
all.concat(send("#{bucket}_data"))

Check warning on line 72 in lib/github/data.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/data.rb#L70-L72

Added lines #L70 - L72 were not covered by tests
end
all

Check warning on line 74 in lib/github/data.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/data.rb#L74

Added line #L74 was not covered by tests
end
end
end
Expand Down
18 changes: 14 additions & 4 deletions lib/github/maintainers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module GitHub
class Maintainers < Array
include GitHub::Buckets

ALL_EXTERNAL = %i[contractors external students].freeze

def buckets
@buckets ||= begin
buckets = {}
Expand All @@ -16,18 +18,26 @@ def buckets
end
end

def external_unique_percent
def all_external
ALL_EXTERNAL.map do |bucket|
buckets[bucket]

Check warning on line 23 in lib/github/maintainers.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/maintainers.rb#L22-L23

Added lines #L22 - L23 were not covered by tests
end.flatten.compact.uniq
end

def all_external_unique_percent
return 0 unless unique_count

((external_unique_count.to_f / unique_count) * 100).to_i
((all_external_unique_count.to_f / unique_count) * 100).to_i

Check warning on line 30 in lib/github/maintainers.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/maintainers.rb#L30

Added line #L30 was not covered by tests
end

def unique_count
buckets.values.map(&:size).sum
end

def external_unique_count
(buckets[:external]&.size || 0) + (buckets[:students]&.size || 0)
def all_external_unique_count
ALL_EXTERNAL.map do |bucket|
buckets[bucket]&.size || 0

Check warning on line 39 in lib/github/maintainers.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/maintainers.rb#L38-L39

Added lines #L38 - L39 were not covered by tests
end.sum
end

def each_pair(&_block)
Expand Down
2 changes: 1 addition & 1 deletion lib/github/pull_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def page(options)
raise 'There are 1000+ PRs returned from a single query, reduce --page.' if data.size >= 1000

data.reject do |pr|
pr.user.type == 'Bot' || GitHub::Data.backports.any? { |b| pr.title&.downcase&.include?(b) } || project_website_authors?(pr)
pr.user.type == 'Bot' || GitHub::Data.backports_data.any? { |b| pr.title&.downcase&.include?(b) } || project_website_authors?(pr)
end
end

Expand Down
24 changes: 20 additions & 4 deletions lib/github/repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,30 @@ def maintained
end
end

def external_maintained_size
(maintained[:external]&.size || 0) + (maintained[:students]&.size || 0)
def externally_maintained
@externally_maintained ||= begin
all = Set.new
Maintainers::ALL_EXTERNAL.each do |bucket|
each do |repo|
next unless ((repo.maintainers & maintainers[bucket]) || []).any?

Check warning on line 51 in lib/github/repos.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/repos.rb#L47-L51

Added lines #L47 - L51 were not covered by tests

all.add(repo)

Check warning on line 53 in lib/github/repos.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/repos.rb#L53

Added line #L53 was not covered by tests
end
end
all

Check warning on line 56 in lib/github/repos.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/repos.rb#L56

Added line #L56 was not covered by tests
end
end

def all_external_maintained_size
Maintainers::ALL_EXTERNAL.map do |bucket|
maintained[bucket]&.size || 0

Check warning on line 62 in lib/github/repos.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/repos.rb#L61-L62

Added lines #L61 - L62 were not covered by tests
end.sum
end

def external_maintainers_percent
def all_external_maintainers_percent
return 0 unless any?

(((maintained[:external]&.size.to_f + maintained[:students]&.size.to_f) / size) * 100).to_i
(all_external_maintained_size.to_f * 100 / size).to_i

Check warning on line 69 in lib/github/repos.rb

View check run for this annotation

Codecov / codecov/patch

lib/github/repos.rb#L69

Added line #L69 was not covered by tests
end
end
end

0 comments on commit 4a7a5d2

Please sign in to comment.