From f4c263f5656b6718a45429a448bb1b04dca7a017 Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Sun, 14 Jul 2024 15:11:39 -0400 Subject: [PATCH 1/2] `brew bump`: do not call repology by default --- Library/Homebrew/dev-cmd/bump.rb | 6 ++++++ Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi | 3 +++ 2 files changed, 9 insertions(+) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index ed54ac5fec48e..578b0ae17d303 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -34,6 +34,8 @@ class VersionBumpInfo < T::Struct description: "Check only formulae." switch "--cask", "--casks", description: "Check only casks." + switch "--eval-all", + description: "Evaluate all formulae and casks." flag "--tap=", description: "Check formulae and casks within the given tap, specified as `/`." switch "--installed", @@ -76,6 +78,10 @@ def run formulae + casks elsif args.named.present? args.named.to_formulae_and_casks_with_taps + else + formulae = args.cask? ? [] : Formula.all(eval_all: args.eval_all?) + casks = args.formula? ? [] : Cask::Cask.all(eval_all: args.eval_all?) + formulae + casks end formulae_and_casks = formulae_and_casks&.sort_by do |formula_or_cask| 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 ece12cc29375a..3c50222363698 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi @@ -20,6 +20,9 @@ class Homebrew::DevCmd::Bump::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def formula?; end + sig { returns(T::Boolean) } + def eval_all?; end + sig { returns(T::Boolean) } def formulae?; end From 0bb64fd3121cece186ef50155f1fd61b3236d8ca Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Sun, 14 Jul 2024 16:35:10 -0400 Subject: [PATCH 2/2] Add --repology flag --- Library/Homebrew/dev-cmd/bump.rb | 81 ++----------------- .../sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi | 3 + 2 files changed, 11 insertions(+), 73 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 578b0ae17d303..fddd1bf8e67e5 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -36,6 +36,8 @@ class VersionBumpInfo < T::Struct description: "Check only casks." switch "--eval-all", description: "Evaluate all formulae and casks." + switch "--repology", + description: "Use Repology to check for outdated packages." flag "--tap=", description: "Check formulae and casks within the given tap, specified as `/`." switch "--installed", @@ -96,24 +98,18 @@ def run end end - if formulae_and_casks.present? - handle_formula_and_casks(formulae_and_casks) - else - handle_api_response - end + handle_formula_and_casks(formulae_and_casks) end end private - sig { params(_formula_or_cask: T.any(Formula, Cask::Cask)).returns(T::Boolean) } - def skip_repology?(_formula_or_cask) - # (ENV["CI"].present? && args.open_pr? && formula_or_cask.livecheckable?) || - # (formula_or_cask.is_a?(Formula) && formula_or_cask.versioned_formula?) + sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T::Boolean) } + def skip_repology?(formula_or_cask) + return true unless args.repology? - # Unconditionally skip Repology queries for now because we've been blocked. - # TODO: get unblocked and make this conditional on e.g. args.repology? - true + (ENV["CI"].present? && args.open_pr? && formula_or_cask.livecheckable?) || + (formula_or_cask.is_a?(Formula) && formula_or_cask.versioned_formula?) end sig { params(formulae_and_casks: T::Array[T.any(Formula, Cask::Cask)]).void } @@ -162,67 +158,6 @@ def handle_formula_and_casks(formulae_and_casks) end end - sig { void } - def handle_api_response - limit = args.limit.to_i if args.limit.present? - - api_response = {} - unless args.cask? - api_response[:formulae] = - Repology.parse_api_response(limit, args.start_with, repository: Repology::HOMEBREW_CORE) - end - unless args.formula? - api_response[:casks] = - Repology.parse_api_response(limit, args.start_with, repository: Repology::HOMEBREW_CASK) - end - - api_response.each_with_index do |(package_type, outdated_packages), idx| - repository = if package_type == :formulae - Repology::HOMEBREW_CORE - else - Repology::HOMEBREW_CASK - end - puts if idx.positive? - oh1 package_type.capitalize if api_response.size > 1 - - outdated_packages.each_with_index do |(_name, repositories), i| - break if limit && i >= limit - - homebrew_repo = repositories.find do |repo| - repo["repo"] == repository - end - - next if homebrew_repo.blank? - - formula_or_cask = begin - if repository == Repology::HOMEBREW_CORE - Formula[homebrew_repo["srcname"]] - else - Cask::CaskLoader.load(homebrew_repo["srcname"]) - end - rescue - next - end - name = Livecheck.package_or_resource_name(formula_or_cask) - ambiguous_cask = begin - formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name] - rescue FormulaUnavailableError - false - end - - puts if i.positive? - next if skip_ineligible_formulae(formula_or_cask) - - retrieve_and_display_info_and_open_pr( - formula_or_cask, - name, - repositories, - ambiguous_cask:, - ) - end - end - end - sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T::Boolean) } 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 3c50222363698..51897d096110e 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi @@ -23,6 +23,9 @@ class Homebrew::DevCmd::Bump::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def eval_all?; end + sig { returns(T::Boolean) } + def repology?; end + sig { returns(T::Boolean) } def formulae?; end