Merge pull request #12563 from samford/livecheck/avoid-duplicate-urls
Livecheck: Avoid duplicate URLs
This commit is contained in:
commit
29329fe739
@ -484,7 +484,7 @@ module Homebrew
|
|||||||
T.absurd(formula_or_cask)
|
T.absurd(formula_or_cask)
|
||||||
end
|
end
|
||||||
|
|
||||||
urls.compact
|
urls.compact.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# Preprocesses and returns the URL used by livecheck.
|
# Preprocesses and returns the URL used by livecheck.
|
||||||
@ -609,24 +609,16 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
checked_urls = []
|
||||||
# rubocop:disable Metrics/BlockLength
|
# rubocop:disable Metrics/BlockLength
|
||||||
urls.each_with_index do |original_url, i|
|
urls.each_with_index do |original_url, i|
|
||||||
if debug
|
|
||||||
puts
|
|
||||||
if livecheck_url.is_a?(Symbol)
|
|
||||||
# This assumes the URL symbol will fit within the available space
|
|
||||||
puts "URL (#{livecheck_url}):".ljust(18, " ") + original_url
|
|
||||||
else
|
|
||||||
puts "URL: #{original_url}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Only preprocess the URL when it's appropriate
|
# Only preprocess the URL when it's appropriate
|
||||||
url = if STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL.include?(livecheck_strategy)
|
url = if STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL.include?(livecheck_strategy)
|
||||||
original_url
|
original_url
|
||||||
else
|
else
|
||||||
preprocess_url(original_url)
|
preprocess_url(original_url)
|
||||||
end
|
end
|
||||||
|
next if checked_urls.include?(url)
|
||||||
|
|
||||||
strategies = Strategy.from_url(
|
strategies = Strategy.from_url(
|
||||||
url,
|
url,
|
||||||
@ -639,6 +631,13 @@ module Homebrew
|
|||||||
strategy_name = livecheck_strategy_names[strategy]
|
strategy_name = livecheck_strategy_names[strategy]
|
||||||
|
|
||||||
if debug
|
if debug
|
||||||
|
puts
|
||||||
|
if livecheck_url.is_a?(Symbol)
|
||||||
|
# This assumes the URL symbol will fit within the available space
|
||||||
|
puts "URL (#{livecheck_url}):".ljust(18, " ") + original_url
|
||||||
|
else
|
||||||
|
puts "URL: #{original_url}"
|
||||||
|
end
|
||||||
puts "URL (processed): #{url}" if url != original_url
|
puts "URL (processed): #{url}" if url != original_url
|
||||||
if strategies.present? && verbose
|
if strategies.present? && verbose
|
||||||
puts "Strategies: #{strategies.map { |s| livecheck_strategy_names[s] }.join(", ")}"
|
puts "Strategies: #{strategies.map { |s| livecheck_strategy_names[s] }.join(", ")}"
|
||||||
@ -674,6 +673,7 @@ module Homebrew
|
|||||||
match_version_map = strategy_data[:matches]
|
match_version_map = strategy_data[:matches]
|
||||||
regex = strategy_data[:regex]
|
regex = strategy_data[:regex]
|
||||||
messages = strategy_data[:messages]
|
messages = strategy_data[:messages]
|
||||||
|
checked_urls << url
|
||||||
|
|
||||||
if messages.is_a?(Array) && match_version_map.blank?
|
if messages.is_a?(Array) && match_version_map.blank?
|
||||||
puts messages unless json
|
puts messages unless json
|
||||||
|
|||||||
@ -44,6 +44,15 @@ describe Homebrew::Livecheck do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:f_duplicate_urls) do
|
||||||
|
formula("test_duplicate_urls") do
|
||||||
|
desc "Test formula with a duplicate URL"
|
||||||
|
homepage "https://github.com/Homebrew/brew.git"
|
||||||
|
url "https://brew.sh/test-0.0.1.tgz"
|
||||||
|
head "https://github.com/Homebrew/brew.git"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "::resolve_livecheck_reference" do
|
describe "::resolve_livecheck_reference" do
|
||||||
context "when a formula/cask has a livecheck block without formula/cask methods" do
|
context "when a formula/cask has a livecheck block without formula/cask methods" do
|
||||||
it "returns [nil, []]" do
|
it "returns [nil, []]" do
|
||||||
@ -144,6 +153,7 @@ describe Homebrew::Livecheck do
|
|||||||
it "returns the list of URLs to check" do
|
it "returns the list of URLs to check" do
|
||||||
expect(livecheck.checkable_urls(f)).to eq([stable_url, head_url, homepage_url])
|
expect(livecheck.checkable_urls(f)).to eq([stable_url, head_url, homepage_url])
|
||||||
expect(livecheck.checkable_urls(c)).to eq([cask_url, homepage_url])
|
expect(livecheck.checkable_urls(c)).to eq([cask_url, homepage_url])
|
||||||
|
expect(livecheck.checkable_urls(f_duplicate_urls)).to eq([stable_url, head_url])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user