From d7fa4009306cb3a22dc54c39828a8ad269b1a200 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 24 Dec 2020 22:19:14 -0500 Subject: [PATCH] Livecheck: Surface cached status in debug output --- Library/Homebrew/livecheck/livecheck.rb | 2 ++ Library/Homebrew/livecheck/strategy/page_match.rb | 1 + .../Homebrew/test/livecheck/strategy/page_match_spec.rb | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) 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 344abae816..6aaa470dab 100644 --- a/Library/Homebrew/livecheck/strategy/page_match.rb +++ b/Library/Homebrew/livecheck/strategy/page_match.rb @@ -89,6 +89,7 @@ module Homebrew match_data = { matches: {}, regex: regex, url: url } content = if provided_content.is_a?(String) + match_data[:cached] = true provided_content else match_data.merge!(Strategy.page_content(url)) 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