From a8ee2b7746e4ea359599a6a51829bda3bc5d1b62 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Thu, 19 Jan 2023 17:06:42 -0800 Subject: [PATCH] Add closed PR check to bump cmds Currently we only check for closed PRs in `bump-cask-pr`. This adds that check to `bump` and `bump-formula-pr`. The idea is that this check can warn users about already updated packages or those that can't be updated easily and should be updated manually instead. --- Library/Homebrew/dev-cmd/bump-cask-pr.rb | 13 ++++++++----- Library/Homebrew/dev-cmd/bump.rb | 21 ++++++++++++++------- Library/Homebrew/utils/github.rb | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-cask-pr.rb b/Library/Homebrew/dev-cmd/bump-cask-pr.rb index 3bea9c2fcc9dd..b971235e914c3 100644 --- a/Library/Homebrew/dev-cmd/bump-cask-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-cask-pr.rb @@ -91,7 +91,9 @@ def bump_cask_pr old_version = cask.version old_hash = cask.sha256 - check_open_pull_requests(cask, args: args) + check_pull_requests(cask, state: "open", args: args) + # if we haven't already found open requests, try for an exact match across closed requests + check_pull_requests(cask, state: "closed", args: args, version: new_version) if new_version.present? old_contents = File.read(cask.sourcefile_path) @@ -193,12 +195,13 @@ def bump_cask_pr GitHub.create_bump_pr(pr_info, args: args) end - def check_open_pull_requests(cask, args:) + def check_pull_requests(cask, state:, args:, version: nil) tap_remote_repo = cask.tap.remote_repo || cask.tap.full_name GitHub.check_for_duplicate_pull_requests(cask.token, tap_remote_repo, - state: "open", - file: cask.sourcefile_path.relative_path_from(cask.tap.path).to_s, - args: args) + state: state, + version: version, + file: cask.sourcefile_path.relative_path_from(cask.tap.path).to_s, + args: args) end def run_cask_audit(cask, old_contents, args:) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 6d403c297e7ca..e12702f415522 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -26,7 +26,7 @@ def bump_args switch "--cask", "--casks", description: "Check only casks." switch "--open-pr", - description: "Open a pull request for the new version if there are none already open." + description: "Open a pull request for the new version if none have been opened yet." flag "--limit=", description: "Limit number of package results returned." flag "--start-with=", @@ -213,9 +213,9 @@ def livecheck_result(formula_or_cask) "error: #{e}" end - def retrieve_pull_requests(formula_or_cask, name) + def retrieve_pull_requests(formula_or_cask, name, state:, version: nil) tap_remote_repo = formula_or_cask.tap&.remote_repo || formula_or_cask.tap&.full_name - pull_requests = GitHub.fetch_pull_requests(name, tap_remote_repo, state: "open") + pull_requests = GitHub.fetch_pull_requests(name, tap_remote_repo, state: state, version: version) if pull_requests.try(:any?) pull_requests = pull_requests.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }.join(", ") end @@ -248,8 +248,13 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a repology_latest end.presence - pull_requests = if !args.no_pull_requests? && (args.named.present? || new_version) - retrieve_pull_requests(formula_or_cask, name) + open_pull_requests = if !args.no_pull_requests? && (args.named.present? || new_version) + retrieve_pull_requests(formula_or_cask, name, state: "open") + end.presence + + closed_pull_requests = if !args.no_pull_requests? && !open_pull_requests && new_version.present? + # if we haven't already found open requests, try for an exact match across closed requests + retrieve_pull_requests(formula_or_cask, name, state: "closed", version: new_version) end.presence title_name = ambiguous_cask ? "#{name} (cask)" : name @@ -265,7 +270,8 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a Current #{version_name}: #{current_version} Latest livecheck version: #{livecheck_latest} Latest Repology version: #{repology_latest} - Open pull requests: #{pull_requests || "none"} + Open pull requests: #{open_pull_requests || "none"} + Closed pull requests: #{closed_pull_requests || "none"} EOS return unless args.open_pr? @@ -278,7 +284,8 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a end return unless new_version - return if pull_requests + return if open_pull_requests + return if closed_pull_requests system HOMEBREW_BREW_FILE, "bump-#{type}-pr", "--no-browse", "--message=Created by `brew bump`", "--version=#{new_version}", name diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index ca04835918b16..4cbd0e94df05f 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -511,7 +511,7 @@ def check_for_duplicate_pull_requests(name, tap_remote_repo, state:, file:, args return if pull_requests.blank? duplicates_message = <<~EOS - These pull requests may be duplicates: + These #{state} pull requests may be duplicates: #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} EOS error_message = "Duplicate PRs should not be opened. Use --force to override this error."