mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
dev-cmd/pr-pull: avoid expensive search API calls
This commit is contained in:
parent
f765382cb6
commit
04f6f53b58
@ -368,28 +368,32 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pr_check_conflicts(user, repo, pr)
|
def pr_check_conflicts(repo, pr)
|
||||||
long_build_pr_files = GitHub.search_issues(
|
long_build_pr_files = GitHub.issues(
|
||||||
"org:#{user}", repo: repo, state: "open", label: "\"no long build conflict\""
|
repo: repo, state: "open", labels: "no long build conflict",
|
||||||
).each_with_object({}) do |long_build_pr, hash|
|
).each_with_object({}) do |long_build_pr, hash|
|
||||||
|
next unless long_build_pr.key?("pull_request")
|
||||||
|
|
||||||
number = long_build_pr["number"]
|
number = long_build_pr["number"]
|
||||||
next if number == pr.to_i
|
next if number == pr.to_i
|
||||||
|
|
||||||
GitHub.get_pull_request_changed_files("#{user}/#{repo}", number).each do |file|
|
GitHub.get_pull_request_changed_files(repo, number).each do |file|
|
||||||
key = file["filename"]
|
key = file["filename"]
|
||||||
hash[key] ||= []
|
hash[key] ||= []
|
||||||
hash[key] << number
|
hash[key] << number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
this_pr_files = GitHub.get_pull_request_changed_files("#{user}/#{repo}", pr)
|
return if long_build_pr_files.blank?
|
||||||
|
|
||||||
|
this_pr_files = GitHub.get_pull_request_changed_files(repo, pr)
|
||||||
|
|
||||||
conflicts = this_pr_files.each_with_object({}) do |file, hash|
|
conflicts = this_pr_files.each_with_object({}) do |file, hash|
|
||||||
filename = file["filename"]
|
filename = file["filename"]
|
||||||
next unless long_build_pr_files.key?(filename)
|
next unless long_build_pr_files.key?(filename)
|
||||||
|
|
||||||
long_build_pr_files[filename].each do |pr_number|
|
long_build_pr_files[filename].each do |pr_number|
|
||||||
key = "#{user}/#{repo}/pull/#{pr_number}"
|
key = "#{repo}/pull/#{pr_number}"
|
||||||
hash[key] ||= []
|
hash[key] ||= []
|
||||||
hash[key] << filename
|
hash[key] << filename
|
||||||
end
|
end
|
||||||
@ -440,7 +444,7 @@ module Homebrew
|
|||||||
opoo "Current branch is #{tap.path.git_branch}: do you need to pull inside #{tap.path.git_origin_branch}?"
|
opoo "Current branch is #{tap.path.git_branch}: do you need to pull inside #{tap.path.git_origin_branch}?"
|
||||||
end
|
end
|
||||||
|
|
||||||
pr_check_conflicts(user, repo, pr)
|
pr_check_conflicts("#{user}/#{repo}", pr)
|
||||||
|
|
||||||
ohai "Fetching #{tap} pull request ##{pr}"
|
ohai "Fetching #{tap} pull request ##{pr}"
|
||||||
Dir.mktmpdir pr do |dir|
|
Dir.mktmpdir pr do |dir|
|
||||||
|
@ -15,19 +15,19 @@ describe GitHub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::query_string" do
|
describe "::search_query_string" do
|
||||||
it "builds a query with the given hash parameters formatted as key:value" do
|
it "builds a query with the given hash parameters formatted as key:value" do
|
||||||
query = described_class.query_string(user: "Homebrew", repo: "brew")
|
query = described_class.search_query_string(user: "Homebrew", repo: "brew")
|
||||||
expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100")
|
expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds a variable number of top-level string parameters to the query when provided" do
|
it "adds a variable number of top-level string parameters to the query when provided" do
|
||||||
query = described_class.query_string("value1", "value2", user: "Homebrew")
|
query = described_class.search_query_string("value1", "value2", user: "Homebrew")
|
||||||
expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100")
|
expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "turns array values into multiple key:value parameters" do
|
it "turns array values into multiple key:value parameters" do
|
||||||
query = described_class.query_string(user: ["Homebrew", "caskroom"])
|
query = described_class.search_query_string(user: ["Homebrew", "caskroom"])
|
||||||
expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100")
|
expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,12 @@ module GitHub
|
|||||||
API.open_rest(url_to("repos", repo, "check-runs"), data: data)
|
API.open_rest(url_to("repos", repo, "check-runs"), data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def issues(repo:, **filters)
|
||||||
|
uri = url_to("repos", repo, "issues")
|
||||||
|
uri.query = URI.encode_www_form(filters)
|
||||||
|
API.open_rest(uri)
|
||||||
|
end
|
||||||
|
|
||||||
def search_issues(query, **qualifiers)
|
def search_issues(query, **qualifiers)
|
||||||
search("issues", query, **qualifiers)
|
search("issues", query, **qualifiers)
|
||||||
end
|
end
|
||||||
@ -153,7 +159,7 @@ module GitHub
|
|||||||
API.open_rest(uri) { |json| json["private"] }
|
API.open_rest(uri) { |json| json["private"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_string(*main_params, **qualifiers)
|
def search_query_string(*main_params, **qualifiers)
|
||||||
params = main_params
|
params = main_params
|
||||||
|
|
||||||
params += qualifiers.flat_map do |key, value|
|
params += qualifiers.flat_map do |key, value|
|
||||||
@ -169,7 +175,7 @@ module GitHub
|
|||||||
|
|
||||||
def search(entity, *queries, **qualifiers)
|
def search(entity, *queries, **qualifiers)
|
||||||
uri = url_to "search", entity
|
uri = url_to "search", entity
|
||||||
uri.query = query_string(*queries, **qualifiers)
|
uri.query = search_query_string(*queries, **qualifiers)
|
||||||
API.open_rest(uri) { |json| json.fetch("items", []) }
|
API.open_rest(uri) { |json| json.fetch("items", []) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user