Skip to content
Snippets Groups Projects
Unverified Commit 0fe3bf7c authored by Markus Reiter's avatar Markus Reiter Committed by Sam Ford
Browse files

Only use `Sparkle` strategy if URL is specified explicitly.

parent 90177783
No related branches found
No related tags found
No related merge requests found
......@@ -435,9 +435,9 @@ module Homebrew
has_livecheckable = formula_or_cask.livecheckable?
livecheck = formula_or_cask.livecheck
livecheck_url = livecheck.url
livecheck_regex = livecheck.regex
livecheck_strategy = livecheck.strategy
livecheck_url = livecheck.url
urls = [livecheck_url] if livecheck_url.present?
urls ||= checkable_urls(formula_or_cask)
......@@ -475,7 +475,9 @@ module Homebrew
strategies = Strategy.from_url(
url,
livecheck_strategy: livecheck_strategy,
url_provided: livecheck_url.present?,
regex_provided: livecheck_regex.present?,
block_provided: livecheck.strategy_block.present?,
)
strategy = Strategy.from_symbol(livecheck_strategy)
strategy ||= strategies.first
......@@ -490,8 +492,8 @@ module Homebrew
puts "Regex: #{livecheck_regex.inspect}" if livecheck_regex.present?
end
if livecheck_strategy == :page_match && livecheck_regex.blank?
odebug "#{strategy_name} strategy requires a regex"
if livecheck_strategy == :page_match && (livecheck_regex.blank? && livecheck.strategy_block.blank?)
odebug "#{strategy_name} strategy requires a regex or block"
next
end
......
......@@ -57,12 +57,16 @@ module Homebrew
# @param regex_provided [Boolean] whether a regex is provided in the
# `livecheck` block
# @return [Array]
def from_url(url, livecheck_strategy: nil, regex_provided: nil)
def from_url(url, livecheck_strategy: nil, url_provided: nil, regex_provided: nil, block_provided: nil)
usable_strategies = strategies.values.select do |strategy|
if strategy == PageMatch
# Only treat the `PageMatch` strategy as usable if a regex is
# present in the `livecheck` block
next unless regex_provided
next unless (regex_provided || block_provided)
elsif strategy == Sparkle && (livecheck_strategy || !url_provided)
# Skip the `Sparkle` strategy if a strategy is specified explicitly
# or if the URL is not specified explicitly.
next
elsif strategy.const_defined?(:PRIORITY) &&
!strategy::PRIORITY.positive? &&
from_symbol(livecheck_strategy) != strategy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment