From 9250a6705ef9d30c348efe2b833aa4596658927b Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 1 Mar 2023 23:38:49 +0000 Subject: [PATCH] dev-cmd/contributions: Count the number of commits a user committed - The GitHub list commits API now supports this filtering (https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits--parameters), because I wrote it. :-) - Authoring a commit and committing a commit are two separate concepts: author is the person who wrote the code and, in old parlance, the committer is the person who applied the patch (remember when we sent patches to mailing lists?). - In practice for us in Homebrew, this occurs when we make a change in GitHub's web editor, or, more obviously, when BrewTestBot pushes `homebrew-core` commits from users (then, `BrewTestBot` is the `committer`). --- Library/Homebrew/dev-cmd/contributions.rb | 15 +++++++++------ Library/Homebrew/utils/github.rb | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index d7fbf333f0..e6df85892b 100755 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -108,7 +108,7 @@ module Homebrew sig { params(totals: Hash).returns(String) } def generate_maintainers_csv(totals) CSV.generate do |csv| - csv << %w[user repo commits coauthorships reviews total] + csv << %w[user repo author committer coauthorships reviews total] totals.sort_by { |_, v| -v.values.sum }.each do |user, total| csv << grand_total_row(user, total) @@ -119,12 +119,13 @@ module Homebrew sig { params(user: String, results: Hash, grand_total: Hash).returns(String) } def generate_csv(user, results, grand_total) CSV.generate do |csv| - csv << %w[user repo commits coauthorships reviews total] + csv << %w[user repo author committer coauthorships reviews total] results.each do |repo, counts| csv << [ user, repo, - counts[:commits], + counts[:author], + counts[:committer], counts[:coauthorships], counts[:reviews], counts.values.sum, @@ -139,7 +140,8 @@ module Homebrew [ user, "all", - grand_total[:commits], + grand_total[:author], + grand_total[:committer], grand_total[:coauthorships], grand_total[:reviews], grand_total.values.sum, @@ -170,7 +172,8 @@ module Homebrew puts "Determining contributions for #{person} on #{repo_full_name}..." if args.verbose? data[repo] = { - commits: GitHub.repo_commit_count_for_user(repo_full_name, person, args), + author: GitHub.repo_commit_count_for_user(repo_full_name, person, "author", args), + committer: GitHub.repo_commit_count_for_user(repo_full_name, person, "committer", args), coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args), reviews: GitHub.count_issues( "", @@ -188,7 +191,7 @@ module Homebrew sig { params(results: Hash).returns(Hash) } def total(results) - totals = { commits: 0, coauthorships: 0, reviews: 0 } + totals = { author: 0, committer: 0, coauthorships: 0, reviews: 0 } # { # "brew"=>{:commits=>9,:coauthorships=>6,:reviews=>1}, diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 6e04b3548d..d4bf5b7027 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -717,10 +717,10 @@ module GitHub output[/^Status: (200)/, 1] != "200" end - def repo_commit_count_for_user(nwo, user, args) + def repo_commit_count_for_user(nwo, user, filter, args) return if Homebrew::EnvConfig.no_github_api? - params = ["author=#{user}"] + params = ["#{filter}=#{user}"] params << "since=#{DateTime.parse(args.from).iso8601}" if args.from params << "until=#{DateTime.parse(args.to).iso8601}" if args.to