From 07d04dd34849f3094a77bc8b64c37d183d6c20b3 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:50:07 +0800 Subject: [PATCH 1/3] dev-cmd/bump: add `--auto` flag This will read from the tap's `.github/autobump.txt` when provided. See discussion at Homebrew/homebrew-core#183126. --- Library/Homebrew/dev-cmd/bump.rb | 21 ++++++++++++++++++- .../sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 2c9986da04..88eb5e392c 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -30,6 +30,9 @@ module Homebrew description: "Print formulae/casks with fully-qualified names." switch "--no-pull-requests", description: "Do not retrieve pull requests from GitHub." + switch "--auto", + description: "Read the list of formulae/casks from .github/autobump.txt.", + hidden: true switch "--formula", "--formulae", description: "Check only formulae." switch "--cask", "--casks", @@ -52,6 +55,7 @@ module Homebrew conflicts "--cask", "--formula" conflicts "--tap=", "--installed" conflicts "--eval-all", "--installed" + conflicts "--installed", "--auto" conflicts "--no-pull-requests", "--open-pr" named_args [:formula, :cask], without_api: true @@ -64,7 +68,22 @@ module Homebrew Homebrew.with_no_api_env do eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all? - formulae_and_casks = if args.tap + formulae_and_casks = if args.auto? + tap_arg = args.tap + raise UsageError, "`--tap=` must be passed with `--auto`." if tap_arg.blank? + raise UsageError, "`--formula` or `--cask` must be passed with `--auto`." if !args.formula? && !args.cask? + + tap = Tap.fetch(tap_arg) + autobump_list = tap.path/".github/autobump.txt" + raise UsageError, "No autobump list at .github/autobump.txt found." unless autobump_list.exist? + + autobump_list.readlines(chomp: true).map do |name| + qualified_name = "#{tap.name}/#{name}" + next Cask::CaskLoader.load(qualified_name) if args.cask? + + Formulary.factory(qualified_name) + end + elsif args.tap tap = Tap.fetch(T.must(args.tap)) raise UsageError, "`--tap` cannot be used with official taps." if tap.official? diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi index 6ec2e761a7..a44d6ec955 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi @@ -11,6 +11,9 @@ class Homebrew::DevCmd::Bump end class Homebrew::DevCmd::Bump::Args < Homebrew::CLI::Args + sig { returns(T::Boolean) } + def auto?; end + sig { returns(T::Boolean) } def cask?; end From e6dd9fbd9cdab722c983ce0c58b8b58e283a8d22 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:10:05 +0800 Subject: [PATCH 2/3] Use `tap#autobump` --- Library/Homebrew/dev-cmd/bump.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 88eb5e392c..4647766270 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -31,7 +31,7 @@ module Homebrew switch "--no-pull-requests", description: "Do not retrieve pull requests from GitHub." switch "--auto", - description: "Read the list of formulae/casks from .github/autobump.txt.", + description: "Read the list of formulae/casks from the tap autobump list.", hidden: true switch "--formula", "--formulae", description: "Check only formulae." @@ -69,15 +69,17 @@ module Homebrew eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all? formulae_and_casks = if args.auto? - tap_arg = args.tap - raise UsageError, "`--tap=` must be passed with `--auto`." if tap_arg.blank? raise UsageError, "`--formula` or `--cask` must be passed with `--auto`." if !args.formula? && !args.cask? - tap = Tap.fetch(tap_arg) - autobump_list = tap.path/".github/autobump.txt" - raise UsageError, "No autobump list at .github/autobump.txt found." unless autobump_list.exist? + tap_arg = args.tap + raise UsageError, "`--tap=` must be passed with `--auto`." if tap_arg.blank? - autobump_list.readlines(chomp: true).map do |name| + tap = Tap.fetch(tap_arg) + autobump_list = tap.autobump + what = args.cask? ? "casks" : "formulae" + raise UsageError, "No autobumped #{what} found." if autobump_list.blank? + + autobump_list.map do |name| qualified_name = "#{tap.name}/#{name}" next Cask::CaskLoader.load(qualified_name) if args.cask? @@ -85,7 +87,7 @@ module Homebrew end elsif args.tap tap = Tap.fetch(T.must(args.tap)) - raise UsageError, "`--tap` cannot be used with official taps." if tap.official? + raise UsageError, "`--tap` without `--auto` cannot be used with official taps." if tap.official? formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } From 800df2a2849625a91960d668918face8666c1c52 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:39:55 +0800 Subject: [PATCH 3/3] Improve error message Co-authored-by: Markus Reiter --- Library/Homebrew/dev-cmd/bump.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 4647766270..9cd3ce2706 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -87,7 +87,7 @@ module Homebrew end elsif args.tap tap = Tap.fetch(T.must(args.tap)) - raise UsageError, "`--tap` without `--auto` cannot be used with official taps." if tap.official? + raise UsageError, "`--tap` requires `--auto` for official taps." if tap.official? formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }