Merge pull request #14975 from issyl0/count-issues-handle-hidden-stats

dev-cmd/contributions: Don't fall over if a user's profile is private
This commit is contained in:
Mike McQuaid 2023-03-15 17:52:04 -04:00 committed by GitHub
commit ff33d34ae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,14 +175,7 @@ module Homebrew
author: GitHub.count_repo_commits(repo_full_name, person, "author", args),
committer: GitHub.count_repo_commits(repo_full_name, person, "committer", args),
coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args),
reviews: GitHub.count_issues(
"",
is: "pr",
repo: repo_full_name,
reviewed_by: person,
review: "approved",
args: args,
),
reviews: count_reviews(repo_full_name, person, args),
}
end
@ -211,4 +204,14 @@ module Homebrew
Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(person) }
end
sig { params(repo_full_name: String, person: String, args: Homebrew::CLI::Args).returns(Integer) }
def count_reviews(repo_full_name, person, args)
GitHub.count_issues("", is: "pr", repo: repo_full_name, reviewed_by: person, review: "approved", args: args)
rescue GitHub::API::ValidationFailedError
if args.verbose?
onoe "Couldn't search GitHub for PRs by #{person}. Their profile might be private. Defaulting to 0."
end
0 # Users who have made their contributions private are not searchable to determine counts.
end
end