dev-cmd/contributions: Use methods to get arguments
- I got these with hash syntax because I couldn't figure out Sorbet, but there's `args.rbi` to add the CLI args methods to. Nice! - In doing this I realised that `--repositories` is required again, we no longer infer `--repositories=all` from no `--repositories` passed as we did in a previous version of this.
This commit is contained in:
parent
5d312d25d0
commit
c02e03a179
@ -300,6 +300,15 @@ module Homebrew
|
|||||||
sig { returns(T.nilable(String)) }
|
sig { returns(T.nilable(String)) }
|
||||||
def screen_saverdir; end
|
def screen_saverdir; end
|
||||||
|
|
||||||
|
sig { returns(T::Array[String])}
|
||||||
|
def repositories; end
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
|
def from; end
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
|
def to; end
|
||||||
|
|
||||||
sig { returns(T.nilable(T::Array[String])) }
|
sig { returns(T.nilable(T::Array[String])) }
|
||||||
def groups; end
|
def groups; end
|
||||||
|
|
||||||
|
@ -40,12 +40,13 @@ module Homebrew
|
|||||||
sig { returns(NilClass) }
|
sig { returns(NilClass) }
|
||||||
def contributions
|
def contributions
|
||||||
args = contributions_args.parse
|
args = contributions_args.parse
|
||||||
|
return ofail "Please specify `--repositories` to search, or `--repositories=all`." unless args[:repositories].empty?
|
||||||
|
|
||||||
commits = 0
|
commits = 0
|
||||||
coauthorships = 0
|
coauthorships = 0
|
||||||
|
|
||||||
all_repos = args[:repositories].first == "all"
|
all_repos = args.repositories.first == "all"
|
||||||
repos = all_repos ? SUPPORTED_REPOS : args[:repositories]
|
repos = all_repos ? SUPPORTED_REPOS : args.repositories
|
||||||
repos.each do |repo|
|
repos.each do |repo|
|
||||||
if SUPPORTED_REPOS.exclude?(repo)
|
if SUPPORTED_REPOS.exclude?(repo)
|
||||||
return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
|
return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
|
||||||
@ -66,12 +67,12 @@ 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 " \
|
||||||
"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}"
|
||||||
elsif args[:from]
|
elsif args.from
|
||||||
" after #{args[:from]}"
|
" after #{args.from}"
|
||||||
elsif args[:to]
|
elsif args.to
|
||||||
" before #{args[:to]}"
|
" before #{args.to}"
|
||||||
else
|
else
|
||||||
" in all time"
|
" in all time"
|
||||||
end
|
end
|
||||||
@ -90,8 +91,8 @@ module Homebrew
|
|||||||
sig { params(repo_path: Pathname, 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
|
||||||
cmd << "--after=#{args[:from]}" if args[:from]
|
cmd << "--after=#{args.from}" if args.from
|
||||||
|
|
||||||
Utils.safe_popen_read(*cmd).lines.count
|
Utils.safe_popen_read(*cmd).lines.count
|
||||||
end
|
end
|
||||||
@ -100,8 +101,8 @@ module Homebrew
|
|||||||
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:)'"
|
||||||
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
|
||||||
|
|
||||||
Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(args.named.first) }
|
Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(args.named.first) }
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user