From 3cf86dad30d60452e14f360d7c16c3bb78c70fe4 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 16 Jun 2022 16:14:39 -0400 Subject: [PATCH] Handle deprecate/disable symbols when loading from the API --- Library/Homebrew/formulary.rb | 12 ++++++++++-- Library/Homebrew/test/formulary_spec.rb | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 4bc7f65c8b..86ce3d1451 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -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 diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index b371c84c26..4fdd65e4c3 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -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