Merge pull request #10143 from samford/pagematch-fix-caching

PageMatch: Return fetched content in match_data
This commit is contained in:
Mike McQuaid 2020-12-28 13:25:58 +00:00 committed by GitHub
commit 55054a122d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

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

View File

@ -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?

View File

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