dev-cmd/contributions: Add --all to scan everything, plus auto-tapping

This commit is contained in:
Issy Long 2022-07-28 11:28:14 +01:00
parent 8e5a5672fb
commit be08b773f1
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -8,7 +8,11 @@ module Homebrew
module_function module_function
SUPPORTED_REPOS = %w[brew core cask bundle].freeze SUPPORTED_REPOS = (
%w[brew core cask] +
OFFICIAL_CMD_TAPS.keys.map { |t| t.delete_prefix("homebrew/") } +
OFFICIAL_CASK_TAPS
).freeze
sig { returns(CLI::Parser) } sig { returns(CLI::Parser) }
def contributions_args def contributions_args
@ -25,10 +29,15 @@ module Homebrew
flag "--to=", flag "--to=",
description: "Date (ISO-8601 format) to stop searching contributions." description: "Date (ISO-8601 format) to stop searching contributions."
flag "--all",
description: "Show contributions across all official Homebrew formula, cask and command repos."
comma_array "--repos=", comma_array "--repos=",
description: "The Homebrew repositories to search for contributions in. " \ description: "The Homebrew repositories to search for contributions in. " \
"Comma separated. Supported repos: #{SUPPORTED_REPOS.join(", ")}." "Comma separated. Supported repos: #{SUPPORTED_REPOS.join(", ")}."
conflicts "--all", "--repos"
named_args :email, number: 1 named_args :email, number: 1
end end
end end
@ -37,18 +46,22 @@ module Homebrew
def contributions def contributions
args = contributions_args.parse args = contributions_args.parse
return ofail "`--repos` is required." if args[:repos].empty?
commits = 0 commits = 0
coauthorships = 0 coauthorships = 0
args[:repos].each do |repo| repos = args[:repos] || SUPPORTED_REPOS
if SUPPORTED_REPOS.exclude?(repo) repos.each do |repo|
if !args[:all] && SUPPORTED_REPOS.exclude?(repo)
return ofail "Unsupported repo: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." return ofail "Unsupported repo: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
end end
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? if !repo_path.exist?
next if repo == "versions" # This tap is deprecated, tapping it will error.
opoo "Couldn't find repo #{repo} locally. Tapping it now..."
Utils.safe_system("brew", "tap", repo_path) # TODO: Figure out why `exit code 1` happens here.
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_coauthor_cmd(T.must(repo_path), args)
@ -56,7 +69,7 @@ module Homebrew
sentence = "Person #{args.named.first} directly authored #{commits} commits " \ sentence = "Person #{args.named.first} directly authored #{commits} commits " \
"and co-authored #{coauthorships} commits " \ "and co-authored #{coauthorships} commits " \
"to #{args[:repos].join(", ")}" "to #{args[:all] ? "all Homebrew repos" : repos.join(", ")}"
sentence += if args[:from] && args[:to] sentence += if args[:from] && args[:to]
" between #{args[:from]} and #{args[:to]}" " between #{args[:from]} and #{args[:to]}"
elsif args[:from] elsif args[:from]