Merge pull request #14860 from issyl0/contributions-commits-committed
dev-cmd/contributions: Count the number of commits a user committed
This commit is contained in:
commit
42c9ad1447
@ -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,
|
||||||
@ -169,8 +171,14 @@ 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?
|
||||||
|
|
||||||
|
commits_authored = GitHub.repo_commit_count_for_user(repo_full_name, person, "author", args)
|
||||||
|
commits_committed = GitHub.repo_commit_count_for_user(repo_full_name, person, "committer", args)
|
||||||
|
# Only count committers where the author is not the same person. Avoid negative numbers or subtracting zero.
|
||||||
|
commits_committed = commits_authored - commits_committed if commits_authored > commits_committed
|
||||||
|
|
||||||
data[repo] = {
|
data[repo] = {
|
||||||
commits: GitHub.repo_commit_count_for_user(repo_full_name, person, args),
|
author: commits_authored,
|
||||||
|
committer: commits_committed,
|
||||||
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,19 +196,15 @@ 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},
|
|
||||||
# "core"=>{:commits=>15,:coauthorships=>10,:reviews=>2}
|
|
||||||
# }
|
|
||||||
results.each_value do |counts|
|
results.each_value do |counts|
|
||||||
counts.each do |kind, count|
|
counts.each do |kind, count|
|
||||||
totals[kind] += count
|
totals[kind] += count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
totals # {:commits=>24,:coauthorships=>16,:reviews=>3}
|
totals
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(repo_path: Pathname, person: String, trailer: String, args: Homebrew::CLI::Args).returns(Integer) }
|
sig { params(repo_path: Pathname, person: String, trailer: String, args: Homebrew::CLI::Args).returns(Integer) }
|
||||||
|
|||||||
@ -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