formula/cask: add symbol support to no_autobump! method

Signed-off-by: botantony <antonsm21@gmail.com>
This commit is contained in:
botantony 2025-04-24 15:04:49 +02:00 committed by Anton Melnikov
parent 5c032d3616
commit 79cf39fc1d
3 changed files with 21 additions and 4 deletions

View File

@ -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])

View File

@ -1,6 +1,7 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true # frozen_string_literal: true
require "autobump_constants"
require "locale" require "locale"
require "lazy_object" require "lazy_object"
require "livecheck" require "livecheck"
@ -547,14 +548,18 @@ module Cask
end end
def no_autobump!(because:) 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 if !@cask.allow_reassignment && @no_autobump_defined
raise CaskInvalidError.new(cask, "'no_autobump_defined' stanza may only appear once.") raise CaskInvalidError.new(cask, "'no_autobump_defined' stanza may only appear once.")
end end
@no_autobump_defined = true @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 @autobump = false
end end

View File

@ -1,6 +1,7 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "autobump_constants"
require "cache_store" require "cache_store"
require "did_you_mean" require "did_you_mean"
require "formula_support" require "formula_support"
@ -4202,10 +4203,14 @@ class Formula
# Method that excludes the formula from the autobump list. # Method that excludes the formula from the autobump list.
# #
# @api public # @api public
sig { params(because: String).returns(T.untyped) } sig { params(because: T.any(String, Symbol)).returns(T.untyped) }
def no_autobump!(because:) 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_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)) @autobump = T.let(false, T.nilable(T::Boolean))
end end