From 3eacc0fb7c989916b1bbb7946c125bdef3038939 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Thu, 4 Aug 2022 23:18:19 +0200 Subject: [PATCH] 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 --- Library/Homebrew/dev-cmd/pr-pull.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index fb49a6d4bd..eb9935f14a 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -369,41 +369,43 @@ module Homebrew end def pr_check_conflicts(user, repo, pr) - hash_template = proc { |h, k| h[k] = [] } long_build_pr_files = GitHub.search_issues( "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"] GitHub.get_pull_request_changed_files("#{user}/#{repo}", number).each do |file| key = file["filename"] + hash[key] ||= [] hash[key] << number end end 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"] next unless long_build_pr_files.key?(filename) long_build_pr_files[filename].each do |pr_number| key = "#{user}/#{repo}/pull/#{pr_number}" + hash[key] ||= [] hash[key] << filename end end + return if conflicts.blank? # Raise an error, display the conflicting PR. For example: # Error: You are trying to merge a pull request that conflicts with a long running build in: - # { - # "homebrew-core/pull/98809": [ - # "Formula/icu4c.rb", - # "Formula/node@10.rb" - # ] - # } + # { + # "homebrew-core/pull/98809": [ + # "Formula/icu4c.rb", + # "Formula/node@10.rb" + # ] + # } odie <<~EOS You are trying to merge a pull request that conflicts with a long running build in: - #{JSON.pretty_generate(conflicts)} + #{JSON.pretty_generate(conflicts)} EOS end