pr-pull: fix check conflicts

The previous refactorings broke the conflict check.
Go back to the initially proposed syntax to fill the hashes/arrays,
which is more readable, and which works (the proc syntax does not seem to work for our purpose here)

Remove space before the error message, else only the first line of the output has 2 spaces
and this looks weird
This commit is contained in:
Michka Popoff 2022-08-04 23:18:19 +02:00
parent b556db72fb
commit 3eacc0fb7c
No known key found for this signature in database
GPG Key ID: 033D03F151030611

View File

@ -369,28 +369,30 @@ module Homebrew
end end
def pr_check_conflicts(user, repo, pr) def pr_check_conflicts(user, repo, pr)
hash_template = proc { |h, k| h[k] = [] }
long_build_pr_files = GitHub.search_issues( long_build_pr_files = GitHub.search_issues(
"org:#{user}", repo: repo, state: "open", label: "\"no long build conflict\"" "org:#{user}", repo: repo, state: "open", label: "\"no long build conflict\""
).each_with_object(Hash.new(hash_template)) do |long_build_pr, hash| ).each_with_object({}) do |long_build_pr, hash|
number = long_build_pr["number"] number = long_build_pr["number"]
GitHub.get_pull_request_changed_files("#{user}/#{repo}", number).each do |file| GitHub.get_pull_request_changed_files("#{user}/#{repo}", number).each do |file|
key = file["filename"] key = file["filename"]
hash[key] ||= []
hash[key] << number hash[key] << number
end end
end end
this_pr_files = GitHub.get_pull_request_changed_files("#{user}/#{repo}", pr) this_pr_files = GitHub.get_pull_request_changed_files("#{user}/#{repo}", pr)
conflicts = this_pr_files.each_with_object(Hash.new(hash_template)) 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 = "#{user}/#{repo}/pull/#{pr_number}"
hash[key] ||= []
hash[key] << filename hash[key] << filename
end end
end end
return if conflicts.blank? return if conflicts.blank?
# Raise an error, display the conflicting PR. For example: # Raise an error, display the conflicting PR. For example: