dev-cmd/contributions: Appease brew typecheck

This commit is contained in:
Issy Long 2022-07-24 23:41:00 +01:00
parent 441df3d866
commit 8a67ce76b5
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -37,7 +37,7 @@ module Homebrew
def contributions def contributions
args = contributions_args.parse args = contributions_args.parse
return ofail "`--repos` is required." if args.repos.empty? return ofail "`--repos` is required." if args[:repos].empty?
commits = 0 commits = 0
coauthorships = 0 coauthorships = 0
@ -50,8 +50,8 @@ module Homebrew
repo_path = find_repo_path_for_repo(repo) repo_path = find_repo_path_for_repo(repo)
return ofail "Couldn't find repo #{repo} locally. Run `brew tap homebrew/#{repo}`." unless repo_path.exist? return ofail "Couldn't find repo #{repo} locally. Run `brew tap homebrew/#{repo}`." unless repo_path.exist?
commits += git_log_author_cmd(repo_path, args) commits += git_log_author_cmd(T.must(repo_path), args)
coauthorships += git_log_coauthor_cmd(repo_path, args) coauthorships += git_log_coauthor_cmd(T.must(repo_path), args)
end end
sentence = "Person #{args.named.first} directly authored #{commits} commits" sentence = "Person #{args.named.first} directly authored #{commits} commits"
@ -71,14 +71,14 @@ module Homebrew
puts sentence puts sentence
end end
sig { params(repo: String).returns(T.nilable(String)) } sig { params(repo: String).returns(Pathname) }
def find_repo_path_for_repo(repo) def find_repo_path_for_repo(repo)
return HOMEBREW_REPOSITORY if repo == "brew" return HOMEBREW_REPOSITORY if repo == "brew"
Tap.fetch("homebrew", repo).path Tap.fetch("homebrew", repo).path
end end
sig { params(repo_path: String, args: Homebrew::CLI::Args).returns(Integer) } sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_author_cmd(repo_path, args) def git_log_author_cmd(repo_path, args)
cmd = "git -C #{repo_path} log --oneline --author=#{args.named.first}" cmd = "git -C #{repo_path} log --oneline --author=#{args.named.first}"
cmd += " --before=#{args[:to]}" if args[:to] cmd += " --before=#{args[:to]}" if args[:to]
@ -87,7 +87,7 @@ module Homebrew
`#{cmd} | wc -l`.strip.to_i `#{cmd} | wc -l`.strip.to_i
end end
sig { params(repo_path: String, args: Homebrew::CLI::Args).returns(Integer) } sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_coauthor_cmd(repo_path, args) def git_log_coauthor_cmd(repo_path, 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=Co-authored-by:)'"