Skip to content

Commit

Permalink
Merge pull request #16664 from Homebrew/bump_no_force
Browse files Browse the repository at this point in the history
dev-cmd/bump*: do not allow forcing multiple PRs.
  • Loading branch information
MikeMcQuaid authored Feb 16, 2024
2 parents b71b054 + 7df07b9 commit eebd844
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 27 deletions.
7 changes: 4 additions & 3 deletions Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def bump_cask_pr_args
flag "--fork-org=",
description: "Use the specified GitHub organization for forking."
switch "-f", "--force",
description: "Ignore duplicate open PRs."
hidden: true

conflicts "--dry-run", "--write"
conflicts "--no-audit", "--online"
Expand All @@ -68,6 +68,7 @@ def bump_cask_pr
args = bump_cask_pr_args.parse

odeprecated "brew bump-cask-pr --online" if args.online?
odisabled "brew bump-cask-pr --force" if args.force?

# This will be run by `brew audit` or `brew style` later so run it first to
# not start spamming during normal output.
Expand Down Expand Up @@ -252,7 +253,7 @@ def check_pull_requests(cask, args:, new_version:)
state: "open",
version: nil,
file: cask.sourcefile_path.relative_path_from(cask.tap.path).to_s,
args: args)
quiet: args.quiet?)

# if we haven't already found open requests, try for an exact match across closed requests
new_version.instance_variables.each do |version_type|
Expand All @@ -265,7 +266,7 @@ def check_pull_requests(cask, args:, new_version:)
state: "closed",
version: shortened_version(version, cask: cask),
file: cask.sourcefile_path.relative_path_from(cask.tap.path).to_s,
args: args,
quiet: args.quiet?,
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def bump_formula_pr_args
description: "Specify the new commit <revision> corresponding to the specified git <tag> " \
"or specified <version>."
switch "-f", "--force",
description: "Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified."
description: "Remove all mirrors if `--mirror` was not specified."
flag "--python-package-name=",
description: "Use the specified <package-name> when finding Python resources for <formula>. " \
"If no package name is specified, it will be inferred from the formula's stable URL."
Expand Down Expand Up @@ -433,7 +433,7 @@ def check_open_pull_requests(formula, tap_remote_repo, args:)
GitHub.check_for_duplicate_pull_requests(formula.name, tap_remote_repo,
state: "open",
file: formula.path.relative_path_from(formula.tap.path).to_s,
args: args)
quiet: args.quiet?)
end

def check_new_version(formula, tap_remote_repo, args:, version: nil, url: nil, tag: nil)
Expand Down Expand Up @@ -464,7 +464,7 @@ def check_closed_pull_requests(formula, tap_remote_repo, args:, version:)
version: version,
state: "closed",
file: formula.path.relative_path_from(formula.tap.path).to_s,
args: args)
quiet: args.quiet?)
end

def alias_update_pair(formula, new_formula_version)
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/dev-cmd/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def bump_args
flag "--start-with=",
description: "Letter or word that the list of package results should alphabetically follow."
switch "-f", "--force",
description: "Ignore duplicate open PRs.",
hidden: true

conflicts "--cask", "--formula"
Expand All @@ -64,6 +63,8 @@ def bump
raise UsageError, "`--limit` must be used with either `--formula` or `--cask`."
end

odisabled "brew bump --force" if args.force?

Homebrew.with_no_api_env do
formulae_and_casks = if args.installed?
formulae = args.cask? ? [] : Formula.installed
Expand Down Expand Up @@ -492,7 +493,7 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
return
end

return if !args.force? && (open_pull_requests.present? || closed_pull_requests.present?)
return if open_pull_requests.present? || closed_pull_requests.present?

version_args = if version_info.multiple_versions
%W[--version-arm=#{new_version.arm} --version-intel=#{new_version.intel}]
Expand All @@ -507,7 +508,6 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
"--no-browse",
"--message=Created by `brew bump`",
]
bump_cask_pr_args << "--force" if args.force?

system HOMEBREW_BREW_FILE, *bump_cask_pr_args
end
Expand Down
14 changes: 9 additions & 5 deletions Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def self.fetch_open_pull_requests(name, tap_remote_repo, version: nil)
@open_pull_requests[cache_key].select { |pr| regex.match?(pr["title"]) }
end

def self.check_for_duplicate_pull_requests(name, tap_remote_repo, state:, file:, args:, version: nil)
def self.check_for_duplicate_pull_requests(name, tap_remote_repo, state:, file:, quiet:, version: nil)
# `fetch_open_pull_requests` is more reliable but *really* slow, so let's use it only in CI.
pull_requests = if state == "open" && ENV["CI"].present?
fetch_open_pull_requests(name, tap_remote_repo, version: version)
Expand All @@ -568,16 +568,20 @@ def self.check_for_duplicate_pull_requests(name, tap_remote_repo, state:, file:,
end
return if pull_requests.blank?

force = ENV.fetch("HOMEBREW_TEST_BOT_AUTOBUMP", nil).present?
duplicates_message = <<~EOS
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."
if args.force? && !args.quiet?
error_message = <<~EOS
Duplicate PRs should not be opened.
Manually open these PRs if you are sure that they are not duplicates.
EOS
if force && !quiet
opoo duplicates_message
elsif !args.force? && args.quiet?
elsif !force && quiet
odie error_message
elsif !args.force?
elsif !force
odie <<~EOS
#{duplicates_message.chomp}
#{error_message}
Expand Down
1 change: 0 additions & 1 deletion completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ _brew_bump_cask_pr() {
--commit
--debug
--dry-run
--force
--fork-org
--help
--message
Expand Down
3 changes: 1 addition & 2 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ __fish_brew_complete_cmd 'bump-cask-pr' 'Create a pull request to update cask wi
__fish_brew_complete_arg 'bump-cask-pr' -l commit -d 'When passed with `--write-only`, generate a new commit after writing changes to the cask file'
__fish_brew_complete_arg 'bump-cask-pr' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'bump-cask-pr' -l dry-run -d 'Print what would be done rather than doing it'
__fish_brew_complete_arg 'bump-cask-pr' -l force -d 'Ignore duplicate open PRs'
__fish_brew_complete_arg 'bump-cask-pr' -l fork-org -d 'Use the specified GitHub organization for forking'
__fish_brew_complete_arg 'bump-cask-pr' -l help -d 'Show this message'
__fish_brew_complete_arg 'bump-cask-pr' -l message -d 'Prepend message to the default pull request message'
Expand All @@ -419,7 +418,7 @@ __fish_brew_complete_cmd 'bump-formula-pr' 'Create a pull request to update form
__fish_brew_complete_arg 'bump-formula-pr' -l commit -d 'When passed with `--write-only`, generate a new commit after writing changes to the formula file'
__fish_brew_complete_arg 'bump-formula-pr' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'bump-formula-pr' -l dry-run -d 'Print what would be done rather than doing it'
__fish_brew_complete_arg 'bump-formula-pr' -l force -d 'Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified'
__fish_brew_complete_arg 'bump-formula-pr' -l force -d 'Remove all mirrors if `--mirror` was not specified'
__fish_brew_complete_arg 'bump-formula-pr' -l fork-org -d 'Use the specified GitHub organization for forking'
__fish_brew_complete_arg 'bump-formula-pr' -l help -d 'Show this message'
__fish_brew_complete_arg 'bump-formula-pr' -l message -d 'Prepend message to the default pull request message'
Expand Down
3 changes: 1 addition & 2 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ _brew_bump_cask_pr() {
'--commit[When passed with `--write-only`, generate a new commit after writing changes to the cask file]' \
'--debug[Display any debugging information]' \
'(--write)--dry-run[Print what would be done rather than doing it]' \
'--force[Ignore duplicate open PRs]' \
'--fork-org[Use the specified GitHub organization for forking]' \
'--help[Show this message]' \
'--message[Prepend message to the default pull request message]' \
Expand All @@ -543,7 +542,7 @@ _brew_bump_formula_pr() {
'--commit[When passed with `--write-only`, generate a new commit after writing changes to the formula file]' \
'--debug[Display any debugging information]' \
'(--write-only)--dry-run[Print what would be done rather than doing it]' \
'--force[Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified]' \
'--force[Remove all mirrors if `--mirror` was not specified]' \
'--fork-org[Use the specified GitHub organization for forking]' \
'--help[Show this message]' \
'--message[Prepend message to the default pull request message]' \
Expand Down
4 changes: 1 addition & 3 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,6 @@ supplied by the user.
Specify the *`SHA-256`* checksum of the new download.
* `--fork-org`:
Use the specified GitHub organization for forking.
* `-f`, `--force`:
Ignore duplicate open PRs.

### `bump-formula-pr` [*`options`*] [*`formula`*]

Expand Down Expand Up @@ -1128,7 +1126,7 @@ nor vice versa. It must use whichever style specification the formula already us
* `--revision`:
Specify the new commit *`revision`* corresponding to the specified git *`tag`* or specified *`version`*.
* `-f`, `--force`:
Ignore duplicate open PRs. Remove all mirrors if `--mirror` was not specified.
Remove all mirrors if `--mirror` was not specified.
* `--python-package-name`:
Use the specified *`package-name`* when finding Python resources for *`formula`*. If no package name is specified, it will be inferred from the formula's stable URL.
* `--python-extra-packages`:
Expand Down
6 changes: 1 addition & 5 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,6 @@ Specify the \fISHA\-256\fR checksum of the new download\.
\fB\-\-fork\-org\fR
Use the specified GitHub organization for forking\.
.
.TP
\fB\-f\fR, \fB\-\-force\fR
Ignore duplicate open PRs\.
.
.SS "\fBbump\-formula\-pr\fR [\fIoptions\fR] [\fIformula\fR]"
Create a pull request to update \fIformula\fR with a new URL or a new tag\.
.
Expand Down Expand Up @@ -1619,7 +1615,7 @@ Specify the new commit \fIrevision\fR corresponding to the specified git \fItag\
.
.TP
\fB\-f\fR, \fB\-\-force\fR
Ignore duplicate open PRs\. Remove all mirrors if \fB\-\-mirror\fR was not specified\.
Remove all mirrors if \fB\-\-mirror\fR was not specified\.
.
.TP
\fB\-\-python\-package\-name\fR
Expand Down

0 comments on commit eebd844

Please sign in to comment.