mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Handle deprecate/disable symbols when loading from the API
This commit is contained in:
parent
d23dba67ca
commit
3cf86dad30
@ -167,11 +167,13 @@ module Formulary
|
||||
end
|
||||
|
||||
if (deprecation_date = json_formula["deprecation_date"]).present?
|
||||
deprecate! date: deprecation_date, because: json_formula["deprecation_reason"]
|
||||
reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["deprecation_reason"]
|
||||
deprecate! date: deprecation_date, because: reason
|
||||
end
|
||||
|
||||
if (disable_date = json_formula["disable_date"]).present?
|
||||
disable! date: disable_date, because: json_formula["disable_reason"]
|
||||
reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["disable_reason"]
|
||||
disable! date: disable_date, because: reason
|
||||
end
|
||||
|
||||
json_formula["build_dependencies"].each do |dep|
|
||||
@ -261,6 +263,12 @@ module Formulary
|
||||
string
|
||||
end
|
||||
|
||||
def self.convert_to_deprecate_disable_reason_string_or_symbol(string)
|
||||
return string unless DeprecateDisable::DEPRECATE_DISABLE_REASONS.keys.map(&:to_s).include?(string)
|
||||
|
||||
string.to_sym
|
||||
end
|
||||
|
||||
# A {FormulaLoader} returns instances of formulae.
|
||||
# Subclasses implement loaders for particular sources of formulae.
|
||||
class FormulaLoader
|
||||
|
@ -256,7 +256,7 @@ describe Formulary do
|
||||
let(:disable_json) do
|
||||
{
|
||||
"disable_date" => "2022-06-15",
|
||||
"disable_reason" => "repo_archived",
|
||||
"disable_reason" => "requires something else",
|
||||
}
|
||||
end
|
||||
|
||||
@ -344,4 +344,15 @@ describe Formulary do
|
||||
.to eq(Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"))
|
||||
end
|
||||
end
|
||||
|
||||
describe "::convert_to_deprecate_disable_reason_string_or_symbol" do
|
||||
it "returns the original string if it isn't a preset reason" do
|
||||
expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("foo")).to eq "foo"
|
||||
end
|
||||
|
||||
it "returns a symbol if the original string is a preset reason" do
|
||||
expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("does_not_build"))
|
||||
.to eq :does_not_build
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user