diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 07c2cec10d..e1ceafbb3c 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -526,6 +526,7 @@ module Homebrew puts "URL (strategy): #{strategy_data[:url]}" if strategy_data[:url] != url puts "URL (final): #{strategy_data[:final_url]}" if strategy_data[:final_url] puts "Regex (strategy): #{strategy_data[:regex].inspect}" if strategy_data[:regex] != livecheck_regex + puts "Cached?: Yes" if strategy_data[:cached] == true end match_version_map.delete_if do |_match, version| @@ -568,6 +569,7 @@ module Homebrew version_info[:meta][:url][:final] = strategy_data[:final_url] if strategy_data[:final_url] version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names[s] } if strategies.present? version_info[:meta][:regex] = regex.inspect if regex.present? + version_info[:meta][:cached] = true if strategy_data[:cached] == true end return version_info diff --git a/Library/Homebrew/livecheck/strategy/page_match.rb b/Library/Homebrew/livecheck/strategy/page_match.rb index 0d611936f7..6aaa470dab 100644 --- a/Library/Homebrew/livecheck/strategy/page_match.rb +++ b/Library/Homebrew/livecheck/strategy/page_match.rb @@ -88,11 +88,12 @@ module Homebrew def self.find_versions(url, regex, provided_content = nil, &block) match_data = { matches: {}, regex: regex, url: url } - content = if provided_content.present? + content = if provided_content.is_a?(String) + match_data[:cached] = true provided_content else match_data.merge!(Strategy.page_content(url)) - match_data.delete(:content) + match_data[:content] end return match_data if content.blank? diff --git a/Library/Homebrew/test/livecheck/strategy/page_match_spec.rb b/Library/Homebrew/test/livecheck/strategy/page_match_spec.rb index 4c364f1d8a..62142abe18 100644 --- a/Library/Homebrew/test/livecheck/strategy/page_match_spec.rb +++ b/Library/Homebrew/test/livecheck/strategy/page_match_spec.rb @@ -36,6 +36,7 @@ describe Homebrew::Livecheck::Strategy::PageMatch do } let(:page_content_matches) { ["2.6.0", "2.5.0", "2.4.0", "2.3.0", "2.2.0", "2.1.0", "2.0.0", "1.9.0"] } + let(:find_versions_return_hash) { { matches: { @@ -53,6 +54,12 @@ describe Homebrew::Livecheck::Strategy::PageMatch do } } + let(:find_versions_cached_return_hash) { + return_hash = find_versions_return_hash + return_hash[:cached] = true + return_hash + } + describe "::match?" do it "returns true for any URL" do expect(page_match.match?(url)).to be true @@ -72,7 +79,7 @@ describe Homebrew::Livecheck::Strategy::PageMatch do describe "::find_versions?" do it "finds versions in provided_content" do - expect(page_match.find_versions(url, regex, page_content)).to eq(find_versions_return_hash) + expect(page_match.find_versions(url, regex, page_content)).to eq(find_versions_cached_return_hash) end end end