Merge pull request #18150 from Homebrew/pr-count-fix
utils/github: fix `too_many_open_prs?`
This commit is contained in:
commit
a208b1bee4
@ -890,46 +890,46 @@ module GitHub
|
||||
odie "Cannot count PRs, HOMEBREW_NO_GITHUB_API set!" if Homebrew::EnvConfig.no_github_api?
|
||||
|
||||
query = <<~EOS
|
||||
query {
|
||||
query($after: String) {
|
||||
viewer {
|
||||
login
|
||||
pullRequests(first: 100, states: OPEN) {
|
||||
pullRequests(first: 100, states: OPEN, after: $after) {
|
||||
totalCount
|
||||
nodes {
|
||||
headRepositoryOwner {
|
||||
baseRepository {
|
||||
owner {
|
||||
login
|
||||
}
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOS
|
||||
graphql_result = API.open_graphql(query)
|
||||
puts
|
||||
|
||||
github_user = graphql_result.dig("viewer", "login")
|
||||
odie "Cannot count PRs, cannot get GitHub username from GraphQL API!" if github_user.blank?
|
||||
homebrew_prs_count = 0
|
||||
|
||||
API.paginate_graphql(query) do |result|
|
||||
data = result.fetch("viewer")
|
||||
github_user = data.fetch("login")
|
||||
|
||||
# BrewTestBot can open as many PRs as it wants.
|
||||
return false if github_user.casecmp("brewtestbot").zero?
|
||||
return false if data.dig("pullRequests", "totalCount") < MAXIMUM_OPEN_PRS
|
||||
|
||||
prs = graphql_result.dig("viewer", "pullRequests", "nodes")
|
||||
more_graphql_data = graphql_result.dig("viewer", "pullRequests", "pageInfo", "hasNextPage")
|
||||
return false if !more_graphql_data && prs.length < MAXIMUM_OPEN_PRS
|
||||
|
||||
homebrew_prs_count = graphql_result.dig("viewer", "pullRequests", "nodes").count do |pr|
|
||||
pr["headRepositoryOwner"]["login"] == "Homebrew"
|
||||
homebrew_prs_count += data.dig("pullRequests", "nodes").count do |node|
|
||||
node.dig("baseRepository", "owner", "login").casecmp?("homebrew")
|
||||
end
|
||||
return true if homebrew_prs_count >= MAXIMUM_OPEN_PRS
|
||||
return false unless more_graphql_data
|
||||
return false if tap.nil?
|
||||
|
||||
url = "#{API_URL}/repos/#{tap.full_name}/issues?state=open&creator=#{github_user}"
|
||||
rest_result = API.open_rest(url)
|
||||
repo_prs_count = rest_result.count { |issue_or_pr| issue_or_pr.key?("pull_request") }
|
||||
data.dig("pullRequests", "pageInfo")
|
||||
end
|
||||
|
||||
repo_prs_count >= MAXIMUM_OPEN_PRS
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user