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`).
This commit is contained in:
parent
10dd6a30ca
commit
9250a6705e
@ -108,7 +108,7 @@ module Homebrew
|
|||||||
sig { params(totals: Hash).returns(String) }
|
sig { params(totals: Hash).returns(String) }
|
||||||
def generate_maintainers_csv(totals)
|
def generate_maintainers_csv(totals)
|
||||||
CSV.generate do |csv|
|
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|
|
totals.sort_by { |_, v| -v.values.sum }.each do |user, total|
|
||||||
csv << grand_total_row(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) }
|
sig { params(user: String, results: Hash, grand_total: Hash).returns(String) }
|
||||||
def generate_csv(user, results, grand_total)
|
def generate_csv(user, results, grand_total)
|
||||||
CSV.generate do |csv|
|
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|
|
results.each do |repo, counts|
|
||||||
csv << [
|
csv << [
|
||||||
user,
|
user,
|
||||||
repo,
|
repo,
|
||||||
counts[:commits],
|
counts[:author],
|
||||||
|
counts[:committer],
|
||||||
counts[:coauthorships],
|
counts[:coauthorships],
|
||||||
counts[:reviews],
|
counts[:reviews],
|
||||||
counts.values.sum,
|
counts.values.sum,
|
||||||
@ -139,7 +140,8 @@ module Homebrew
|
|||||||
[
|
[
|
||||||
user,
|
user,
|
||||||
"all",
|
"all",
|
||||||
grand_total[:commits],
|
grand_total[:author],
|
||||||
|
grand_total[:committer],
|
||||||
grand_total[:coauthorships],
|
grand_total[:coauthorships],
|
||||||
grand_total[:reviews],
|
grand_total[:reviews],
|
||||||
grand_total.values.sum,
|
grand_total.values.sum,
|
||||||
@ -170,7 +172,8 @@ module Homebrew
|
|||||||
puts "Determining contributions for #{person} on #{repo_full_name}..." if args.verbose?
|
puts "Determining contributions for #{person} on #{repo_full_name}..." if args.verbose?
|
||||||
|
|
||||||
data[repo] = {
|
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),
|
coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args),
|
||||||
reviews: GitHub.count_issues(
|
reviews: GitHub.count_issues(
|
||||||
"",
|
"",
|
||||||
@ -188,7 +191,7 @@ module Homebrew
|
|||||||
|
|
||||||
sig { params(results: Hash).returns(Hash) }
|
sig { params(results: Hash).returns(Hash) }
|
||||||
def total(results)
|
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},
|
# "brew"=>{:commits=>9,:coauthorships=>6,:reviews=>1},
|
||||||
|
@ -717,10 +717,10 @@ module GitHub
|
|||||||
output[/^Status: (200)/, 1] != "200"
|
output[/^Status: (200)/, 1] != "200"
|
||||||
end
|
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?
|
return if Homebrew::EnvConfig.no_github_api?
|
||||||
|
|
||||||
params = ["author=#{user}"]
|
params = ["#{filter}=#{user}"]
|
||||||
params << "since=#{DateTime.parse(args.from).iso8601}" if args.from
|
params << "since=#{DateTime.parse(args.from).iso8601}" if args.from
|
||||||
params << "until=#{DateTime.parse(args.to).iso8601}" if args.to
|
params << "until=#{DateTime.parse(args.to).iso8601}" if args.to
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user