Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/github: Add date filtering to the commit author API query #14775

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions Library/Homebrew/dev-cmd/contributions.rb
Expand Up @@ -70,7 +70,6 @@ def contributions

maintainers = GitHub.members_by_team("Homebrew", "maintainers")
maintainers.each do |username, _|
puts "Determining contributions for #{username}..." if args.verbose?
# TODO: Using the GitHub username to scan the `git log` undercounts some
# contributions as people might not always have configured their Git
# committer details to match the ones on GitHub.
Expand Down Expand Up @@ -143,7 +142,7 @@ def scan_repositories(repos, person, args)
puts "Determining contributions for #{person} on #{repo_full_name}..." if args.verbose?

data[repo] = {
commits: GitHub.repo_commit_count_for_user(repo_full_name, person),
commits: GitHub.repo_commit_count_for_user(repo_full_name, person, args),
coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args),
signoffs: git_log_trailers_cmd(T.must(repo_path), person, "Signed-off-by", args),
}
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/utils/github.rb
Expand Up @@ -700,11 +700,15 @@ def multiple_short_commits_exist?(user, repo, commit)
output[/^Status: (200)/, 1] != "200"
end

def repo_commit_count_for_user(nwo, user)
def repo_commit_count_for_user(nwo, user, args)
return if Homebrew::EnvConfig.no_github_api?

params = ["author=#{user}"]
params << "since=#{DateTime.parse(args.from).iso8601}" if args.from
params << "until=#{DateTime.parse(args.to).iso8601}" if args.to

commits = 0
API.paginate_rest("#{API_URL}/repos/#{nwo}/commits", additional_query_params: "author=#{user}") do |result|
API.paginate_rest("#{API_URL}/repos/#{nwo}/commits", additional_query_params: params.join("&")) do |result|
commits += result.length
end
commits
Expand Down