dev-cmd/contributions: Better error messages for bad --repos

```
$ brew contributions --email=me@issyl0.co.uk --repos=coreeeee
Error: Unsupported repo: coreeeee. Try one of brew, core, cask, bundle.

$ brew untap homebrew/bundle
$ brew contributions --email=me@issyl0.co.uk --repos=bundle
Error: Couldn't find repo bundle locally. Do you have it tapped?
```
This commit is contained in:
Issy Long 2022-07-24 22:44:25 +01:00
parent 0355c60787
commit 503b51c54f
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -46,14 +46,15 @@ module Homebrew
coauthorships = 0 coauthorships = 0
args[:repos].each do |repo| args[:repos].each do |repo|
repo_location = find_repo_path_for_repo(repo) if SUPPORTED_REPOS.exclude?(repo)
unless repo_location return ofail "Unsupported repo: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
return ofail "Couldn't find location for #{repo}. Do you have it tapped, or is there a typo? " \
"We only support #{SUPPORTED_REPOS.join(", ")} repos so far."
end end
commits += git_log_cmd("author", repo_location, args) repo_path = find_repo_path_for_repo(repo)
coauthorships += git_log_cmd("coauthorships", repo_location, args) return ofail "Couldn't find repo #{repo} locally. Do you have it tapped?" unless Dir.exist?(repo_path)
commits += git_log_cmd("author", repo_path, args)
coauthorships += git_log_cmd("coauthorships", repo_path, args)
end end
sentence = "Person #{args[:email]} directly authored #{commits} commits" sentence = "Person #{args[:email]} directly authored #{commits} commits"
@ -87,9 +88,9 @@ module Homebrew
end end
end end
sig { params(kind: String, repo_location: String, args: Homebrew::CLI::Args).returns(Integer) } sig { params(kind: String, repo_path: String, args: Homebrew::CLI::Args).returns(Integer) }
def git_log_cmd(kind, repo_location, args) def git_log_cmd(kind, repo_path, args)
cmd = "git -C #{repo_location} log --oneline" cmd = "git -C #{repo_path} log --oneline"
cmd += " --author=#{args[:email]}" if kind == "author" cmd += " --author=#{args[:email]}" if kind == "author"
cmd += " --format='%(trailers:key=Co-authored-by:)'" if kind == "coauthorships" cmd += " --format='%(trailers:key=Co-authored-by:)'" if kind == "coauthorships"
cmd += " --before=#{args[:to]}" if args[:to] cmd += " --before=#{args[:to]}" if args[:to]