From 79cf39fc1d5f19f8724b708722602df5cc4717a2 Mon Sep 17 00:00:00 2001 From: botantony Date: Thu, 24 Apr 2025 15:04:49 +0200 Subject: [PATCH] formula/cask: add symbol support to `no_autobump!` method Signed-off-by: botantony --- Library/Homebrew/autobump_constants.rb | 7 +++++++ Library/Homebrew/cask/dsl.rb | 9 +++++++-- Library/Homebrew/formula.rb | 9 +++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 Library/Homebrew/autobump_constants.rb diff --git a/Library/Homebrew/autobump_constants.rb b/Library/Homebrew/autobump_constants.rb new file mode 100644 index 0000000000..a88ccaa71e --- /dev/null +++ b/Library/Homebrew/autobump_constants.rb @@ -0,0 +1,7 @@ +# typed: strict +# frozen_string_literal: true + +# TODO: add more reasons here +NO_AUTOBUMP_REASONS_LIST = T.let({ + incompatible_version_format: "incompatible version format", +}.freeze, T::Hash[Symbol, String]) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 14fc10b91f..a1b09c9678 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -1,6 +1,7 @@ # typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true +require "autobump_constants" require "locale" require "lazy_object" require "livecheck" @@ -547,14 +548,18 @@ module Cask end def no_autobump!(because:) - raise ArgumentError, "`because` argument must be a string!" unless because.is_a?(String) + if !because.is_a?(String) && (!because.is_a?(Symbol) || !NO_AUTOBUMP_REASONS_LIST.key?(because)) + raise ArgumentError, "'because' argument should use valid symbol or a string!" + end if !@cask.allow_reassignment && @no_autobump_defined raise CaskInvalidError.new(cask, "'no_autobump_defined' stanza may only appear once.") end @no_autobump_defined = true - @no_autobump_message = because + # TODO: add symbol support when a list of common reasons is ready. + # At this moment just convert symbols to a string + @no_autobump_message = because.to_s @autobump = false end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4344adfa92..150489f0b4 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1,6 +1,7 @@ # typed: strict # frozen_string_literal: true +require "autobump_constants" require "cache_store" require "did_you_mean" require "formula_support" @@ -4202,10 +4203,14 @@ class Formula # Method that excludes the formula from the autobump list. # # @api public - sig { params(because: String).returns(T.untyped) } + sig { params(because: T.any(String, Symbol)).returns(T.untyped) } def no_autobump!(because:) + if because.is_a?(Symbol) && !NO_AUTOBUMP_REASONS_LIST.key?(because) + raise ArgumentError, "'because' argument should use valid symbol or a string!" + end + @no_autobump_defined = T.let(true, T.nilable(T::Boolean)) - @no_autobump_message = T.let(because, T.nilable(String)) + @no_autobump_message = T.let(because.to_s, T.nilable(String)) @autobump = T.let(false, T.nilable(T::Boolean)) end