dev-cmd/contributions: Count commit signoffs, too

- `BrewTestBot` adds `Signed-off-by` for who approved PRs (1cf53b4281/Library/Homebrew/dev-cmd/pr-pull.rb (L91-L93)).
- Let's count these too, at least until we can get PR approvals from the GitHub API.
This commit is contained in:
Issy Long 2023-02-11 11:39:31 +00:00
parent 1cf53b4281
commit 14f9a2424d
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -44,6 +44,7 @@ module Homebrew
commits = 0 commits = 0
coauthorships = 0 coauthorships = 0
signoffs = 0
all_repos = args.repositories.nil? || args.repositories.include?("all") all_repos = args.repositories.nil? || args.repositories.include?("all")
repos = all_repos ? SUPPORTED_REPOS : args.repositories repos = all_repos ? SUPPORTED_REPOS : args.repositories
@ -61,11 +62,13 @@ module Homebrew
end end
commits += git_log_author_cmd(T.must(repo_path), args) commits += git_log_author_cmd(T.must(repo_path), args)
coauthorships += git_log_coauthor_cmd(T.must(repo_path), args) coauthorships += git_log_trailers_cmd(T.must(repo_path), "Co-authored-by", args)
signoffs += git_log_trailers_cmd(T.must(repo_path), "Signed-off-by", args)
end end
sentence = "#{args.named.first} directly authored #{commits} commits " \ sentence = "#{args.named.first} directly authored #{commits} commits" \
"and co-authored #{coauthorships} commits " \ ", co-authored #{coauthorships} commits" \
", and signed-off #{signoffs} commits " \
"across #{all_repos ? "all Homebrew repos" : repos.to_sentence}" "across #{all_repos ? "all Homebrew repos" : repos.to_sentence}"
sentence += if args.from && args.to sentence += if args.from && args.to
" between #{args.from} and #{args.to}" " between #{args.from} and #{args.to}"
@ -97,10 +100,10 @@ module Homebrew
Utils.safe_popen_read(*cmd).lines.count Utils.safe_popen_read(*cmd).lines.count
end end
sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) } sig { params(repo_path: Pathname, trailer: String, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_coauthor_cmd(repo_path, args) def git_log_trailers_cmd(repo_path, trailer, args)
cmd = ["git", "-C", repo_path, "log", "--oneline"] cmd = ["git", "-C", repo_path, "log", "--oneline"]
cmd << "--format='%(trailers:key=Co-authored-by:)'" cmd << "--format='%(trailers:key=#{trailer}:)'"
cmd << "--before=#{args.to}" if args.to cmd << "--before=#{args.to}" if args.to
cmd << "--after=#{args.from}" if args.from cmd << "--after=#{args.from}" if args.from