Merge pull request #19293 from Homebrew/livecheck/options
livecheck: add Options class
This commit is contained in:
commit
6291c24004
@ -2,6 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "livecheck/constants"
|
require "livecheck/constants"
|
||||||
|
require "livecheck/options"
|
||||||
require "cask/cask"
|
require "cask/cask"
|
||||||
|
|
||||||
# The {Livecheck} class implements the DSL methods used in a formula's, cask's
|
# The {Livecheck} class implements the DSL methods used in a formula's, cask's
|
||||||
@ -15,6 +16,10 @@ require "cask/cask"
|
|||||||
class Livecheck
|
class Livecheck
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
|
# Options to modify livecheck's behavior.
|
||||||
|
sig { returns(Homebrew::Livecheck::Options) }
|
||||||
|
attr_reader :options
|
||||||
|
|
||||||
# A very brief description of why the formula/cask/resource is skipped (e.g.
|
# A very brief description of why the formula/cask/resource is skipped (e.g.
|
||||||
# `No longer developed or maintained`).
|
# `No longer developed or maintained`).
|
||||||
sig { returns(T.nilable(String)) }
|
sig { returns(T.nilable(String)) }
|
||||||
@ -24,13 +29,10 @@ class Livecheck
|
|||||||
sig { returns(T.nilable(Proc)) }
|
sig { returns(T.nilable(Proc)) }
|
||||||
attr_reader :strategy_block
|
attr_reader :strategy_block
|
||||||
|
|
||||||
# Options used by `Strategy` methods to modify `curl` behavior.
|
|
||||||
sig { returns(T.nilable(T::Hash[Symbol, T.untyped])) }
|
|
||||||
attr_reader :url_options
|
|
||||||
|
|
||||||
sig { params(package_or_resource: T.any(Cask::Cask, T.class_of(Formula), Resource)).void }
|
sig { params(package_or_resource: T.any(Cask::Cask, T.class_of(Formula), Resource)).void }
|
||||||
def initialize(package_or_resource)
|
def initialize(package_or_resource)
|
||||||
@package_or_resource = package_or_resource
|
@package_or_resource = package_or_resource
|
||||||
|
@options = T.let(Homebrew::Livecheck::Options.new, Homebrew::Livecheck::Options)
|
||||||
@referenced_cask_name = T.let(nil, T.nilable(String))
|
@referenced_cask_name = T.let(nil, T.nilable(String))
|
||||||
@referenced_formula_name = T.let(nil, T.nilable(String))
|
@referenced_formula_name = T.let(nil, T.nilable(String))
|
||||||
@regex = T.let(nil, T.nilable(Regexp))
|
@regex = T.let(nil, T.nilable(Regexp))
|
||||||
@ -40,7 +42,6 @@ class Livecheck
|
|||||||
@strategy_block = T.let(nil, T.nilable(Proc))
|
@strategy_block = T.let(nil, T.nilable(Proc))
|
||||||
@throttle = T.let(nil, T.nilable(Integer))
|
@throttle = T.let(nil, T.nilable(Integer))
|
||||||
@url = T.let(nil, T.any(NilClass, String, Symbol))
|
@url = T.let(nil, T.any(NilClass, String, Symbol))
|
||||||
@url_options = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the `@referenced_cask_name` instance variable to the provided `String`
|
# Sets the `@referenced_cask_name` instance variable to the provided `String`
|
||||||
@ -170,15 +171,17 @@ class Livecheck
|
|||||||
params(
|
params(
|
||||||
# URL to check for version information.
|
# URL to check for version information.
|
||||||
url: T.any(String, Symbol),
|
url: T.any(String, Symbol),
|
||||||
|
homebrew_curl: T.nilable(T::Boolean),
|
||||||
post_form: T.nilable(T::Hash[Symbol, String]),
|
post_form: T.nilable(T::Hash[Symbol, String]),
|
||||||
post_json: T.nilable(T::Hash[Symbol, String]),
|
post_json: T.nilable(T::Hash[Symbol, String]),
|
||||||
).returns(T.nilable(T.any(String, Symbol)))
|
).returns(T.nilable(T.any(String, Symbol)))
|
||||||
}
|
}
|
||||||
def url(url = T.unsafe(nil), post_form: nil, post_json: nil)
|
def url(url = T.unsafe(nil), homebrew_curl: nil, post_form: nil, post_json: nil)
|
||||||
raise ArgumentError, "Only use `post_form` or `post_json`, not both" if post_form && post_json
|
raise ArgumentError, "Only use `post_form` or `post_json`, not both" if post_form && post_json
|
||||||
|
|
||||||
options = { post_form:, post_json: }.compact
|
@options.homebrew_curl = homebrew_curl unless homebrew_curl.nil?
|
||||||
@url_options = options if options.present?
|
@options.post_form = post_form unless post_form.nil?
|
||||||
|
@options.post_json = post_json unless post_json.nil?
|
||||||
|
|
||||||
case url
|
case url
|
||||||
when nil
|
when nil
|
||||||
@ -190,6 +193,7 @@ class Livecheck
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
delegate url_options: :@options
|
||||||
delegate version: :@package_or_resource
|
delegate version: :@package_or_resource
|
||||||
delegate arch: :@package_or_resource
|
delegate arch: :@package_or_resource
|
||||||
private :version, :arch
|
private :version, :arch
|
||||||
@ -198,6 +202,7 @@ class Livecheck
|
|||||||
sig { returns(T::Hash[String, T.untyped]) }
|
sig { returns(T::Hash[String, T.untyped]) }
|
||||||
def to_hash
|
def to_hash
|
||||||
{
|
{
|
||||||
|
"options" => @options.to_hash,
|
||||||
"cask" => @referenced_cask_name,
|
"cask" => @referenced_cask_name,
|
||||||
"formula" => @referenced_formula_name,
|
"formula" => @referenced_formula_name,
|
||||||
"regex" => @regex,
|
"regex" => @regex,
|
||||||
@ -206,7 +211,6 @@ class Livecheck
|
|||||||
"strategy" => @strategy,
|
"strategy" => @strategy,
|
||||||
"throttle" => @throttle,
|
"throttle" => @throttle,
|
||||||
"url" => @url,
|
"url" => @url,
|
||||||
"url_options" => @url_options,
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,6 +34,13 @@ module Homebrew
|
|||||||
@livecheck_strategy_names[strategy_class] ||= Utils.demodulize(strategy_class.name)
|
@livecheck_strategy_names[strategy_class] ||= Utils.demodulize(strategy_class.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(strategy_class: T::Class[T.anything]).returns(T::Array[Symbol]) }
|
||||||
|
private_class_method def self.livecheck_find_versions_parameters(strategy_class)
|
||||||
|
@livecheck_find_versions_parameters ||= T.let({}, T.nilable(T::Hash[T::Class[T.anything], T::Array[Symbol]]))
|
||||||
|
@livecheck_find_versions_parameters[strategy_class] ||=
|
||||||
|
T::Utils.signature_for_method(strategy_class.method(:find_versions)).parameters.map(&:second)
|
||||||
|
end
|
||||||
|
|
||||||
# Uses `formulae_and_casks_to_check` to identify taps in use other than
|
# Uses `formulae_and_casks_to_check` to identify taps in use other than
|
||||||
# homebrew/core and homebrew/cask and loads strategies from them.
|
# homebrew/core and homebrew/cask and loads strategies from them.
|
||||||
sig { params(formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)]).void }
|
sig { params(formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)]).void }
|
||||||
@ -613,8 +620,9 @@ module Homebrew
|
|||||||
livecheck = formula_or_cask.livecheck
|
livecheck = formula_or_cask.livecheck
|
||||||
referenced_livecheck = referenced_formula_or_cask&.livecheck
|
referenced_livecheck = referenced_formula_or_cask&.livecheck
|
||||||
|
|
||||||
|
livecheck_options = livecheck.options || referenced_livecheck&.options
|
||||||
|
livecheck_url_options = livecheck_options.url_options.compact
|
||||||
livecheck_url = livecheck.url || referenced_livecheck&.url
|
livecheck_url = livecheck.url || referenced_livecheck&.url
|
||||||
livecheck_url_options = livecheck.url_options || referenced_livecheck&.url_options
|
|
||||||
livecheck_regex = livecheck.regex || referenced_livecheck&.regex
|
livecheck_regex = livecheck.regex || referenced_livecheck&.regex
|
||||||
livecheck_strategy = livecheck.strategy || referenced_livecheck&.strategy
|
livecheck_strategy = livecheck.strategy || referenced_livecheck&.strategy
|
||||||
livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block
|
livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block
|
||||||
@ -676,8 +684,8 @@ module Homebrew
|
|||||||
elsif original_url.present? && original_url != "None"
|
elsif original_url.present? && original_url != "None"
|
||||||
puts "URL: #{original_url}"
|
puts "URL: #{original_url}"
|
||||||
end
|
end
|
||||||
puts "URL Options: #{livecheck_url_options}" if livecheck_url_options.present?
|
|
||||||
puts "URL (processed): #{url}" if url != original_url
|
puts "URL (processed): #{url}" if url != original_url
|
||||||
|
puts "URL Options: #{livecheck_url_options}" if livecheck_url_options.present?
|
||||||
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(", ")}"
|
||||||
end
|
end
|
||||||
@ -697,23 +705,25 @@ module Homebrew
|
|||||||
|
|
||||||
next if strategy.blank?
|
next if strategy.blank?
|
||||||
|
|
||||||
homebrew_curl = case strategy_name
|
if (livecheck_homebrew_curl = livecheck_options.homebrew_curl).nil?
|
||||||
|
case strategy_name
|
||||||
when "PageMatch", "HeaderMatch"
|
when "PageMatch", "HeaderMatch"
|
||||||
use_homebrew_curl?(referenced_package, url)
|
if (homebrew_curl = use_homebrew_curl?(referenced_package, url))
|
||||||
|
livecheck_options = livecheck_options.merge({ homebrew_curl: })
|
||||||
|
livecheck_homebrew_curl = homebrew_curl
|
||||||
end
|
end
|
||||||
puts "Homebrew curl?: Yes" if debug && homebrew_curl.present?
|
end
|
||||||
|
end
|
||||||
|
puts "Homebrew curl?: #{livecheck_homebrew_curl ? "Yes" : "No"}" if debug && !livecheck_homebrew_curl.nil?
|
||||||
|
|
||||||
strategy_args = {
|
# Only use arguments that the strategy's `#find_versions` method
|
||||||
regex: livecheck_regex,
|
# supports
|
||||||
url_options: livecheck_url_options,
|
find_versions_parameters = livecheck_find_versions_parameters(strategy)
|
||||||
homebrew_curl:,
|
strategy_args = {}
|
||||||
}
|
strategy_args[:cask] = cask if find_versions_parameters.include?(:cask)
|
||||||
# TODO: Set `cask`/`url` args based on the presence of the keyword arg
|
strategy_args[:url] = url if find_versions_parameters.include?(:url)
|
||||||
# in the strategy's `#find_versions` method once we figure out why
|
strategy_args[:regex] = livecheck_regex if find_versions_parameters.include?(:regex)
|
||||||
# `strategy.method(:find_versions).parameters` isn't working as
|
strategy_args[:options] = livecheck_options if find_versions_parameters.include?(:options)
|
||||||
# expected.
|
|
||||||
strategy_args[:cask] = cask if strategy_name == "ExtractPlist" && cask.present?
|
|
||||||
strategy_args[:url] = url
|
|
||||||
strategy_args.compact!
|
strategy_args.compact!
|
||||||
|
|
||||||
strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block)
|
strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block)
|
||||||
@ -813,7 +823,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
version_info[:meta][:url][:final] = strategy_data[:final_url] if strategy_data[:final_url]
|
version_info[:meta][:url][:final] = strategy_data[:final_url] if strategy_data[:final_url]
|
||||||
version_info[:meta][:url][:options] = livecheck_url_options if livecheck_url_options.present?
|
version_info[:meta][:url][:options] = livecheck_url_options if livecheck_url_options.present?
|
||||||
version_info[:meta][:url][:homebrew_curl] = homebrew_curl if homebrew_curl.present?
|
|
||||||
end
|
end
|
||||||
version_info[:meta][:strategy] = strategy_name if strategy.present?
|
version_info[:meta][:strategy] = strategy_name if strategy.present?
|
||||||
version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names(s) } if strategies.present?
|
version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names(s) } if strategies.present?
|
||||||
@ -860,9 +869,10 @@ module Homebrew
|
|||||||
resource_version_info = {}
|
resource_version_info = {}
|
||||||
|
|
||||||
livecheck = resource.livecheck
|
livecheck = resource.livecheck
|
||||||
|
livecheck_options = livecheck.options
|
||||||
|
livecheck_url_options = livecheck_options.url_options.compact
|
||||||
livecheck_reference = livecheck.formula
|
livecheck_reference = livecheck.formula
|
||||||
livecheck_url = livecheck.url
|
livecheck_url = livecheck.url
|
||||||
livecheck_url_options = livecheck.url_options
|
|
||||||
livecheck_regex = livecheck.regex
|
livecheck_regex = livecheck.regex
|
||||||
livecheck_strategy = livecheck.strategy
|
livecheck_strategy = livecheck.strategy
|
||||||
livecheck_strategy_block = livecheck.strategy_block
|
livecheck_strategy_block = livecheck.strategy_block
|
||||||
@ -902,8 +912,8 @@ module Homebrew
|
|||||||
elsif original_url.present? && original_url != "None"
|
elsif original_url.present? && original_url != "None"
|
||||||
puts "URL: #{original_url}"
|
puts "URL: #{original_url}"
|
||||||
end
|
end
|
||||||
puts "URL Options: #{livecheck_url_options}" if livecheck_url_options.present?
|
|
||||||
puts "URL (processed): #{url}" if url != original_url
|
puts "URL (processed): #{url}" if url != original_url
|
||||||
|
puts "URL Options: #{livecheck_url_options}" if livecheck_url_options.present?
|
||||||
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(", ")}"
|
||||||
end
|
end
|
||||||
@ -926,16 +936,22 @@ module Homebrew
|
|||||||
puts if debug && strategy.blank? && livecheck_reference != :parent
|
puts if debug && strategy.blank? && livecheck_reference != :parent
|
||||||
next if strategy.blank? && livecheck_reference != :parent
|
next if strategy.blank? && livecheck_reference != :parent
|
||||||
|
|
||||||
|
if debug && !(livecheck_homebrew_curl = livecheck_options.homebrew_curl).nil?
|
||||||
|
puts "Homebrew curl?: #{livecheck_homebrew_curl ? "Yes" : "No"}"
|
||||||
|
end
|
||||||
|
|
||||||
if livecheck_reference == :parent
|
if livecheck_reference == :parent
|
||||||
match_version_map = { formula_latest => Version.new(formula_latest) }
|
match_version_map = { formula_latest => Version.new(formula_latest) }
|
||||||
cached = true
|
cached = true
|
||||||
else
|
else
|
||||||
strategy_args = {
|
# Only use arguments that the strategy's `#find_versions` method
|
||||||
url:,
|
# supports
|
||||||
regex: livecheck_regex,
|
find_versions_parameters = livecheck_find_versions_parameters(strategy)
|
||||||
url_options: livecheck_url_options,
|
strategy_args = {}
|
||||||
homebrew_curl: false,
|
strategy_args[:url] = url if find_versions_parameters.include?(:url)
|
||||||
}.compact
|
strategy_args[:regex] = livecheck_regex if find_versions_parameters.include?(:regex)
|
||||||
|
strategy_args[:options] = livecheck_options if find_versions_parameters.include?(:options)
|
||||||
|
strategy_args.compact!
|
||||||
|
|
||||||
strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block)
|
strategy_data = strategy.find_versions(**strategy_args, &livecheck_strategy_block)
|
||||||
match_version_map = strategy_data[:matches]
|
match_version_map = strategy_data[:matches]
|
||||||
|
|||||||
105
Library/Homebrew/livecheck/options.rb
Normal file
105
Library/Homebrew/livecheck/options.rb
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
# typed: strong
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Homebrew
|
||||||
|
module Livecheck
|
||||||
|
# Options to modify livecheck's behavior. These primarily come from
|
||||||
|
# `livecheck` blocks but they can also be set by livecheck at runtime.
|
||||||
|
#
|
||||||
|
# Option values use a `nil` default to indicate that the value has not been
|
||||||
|
# set.
|
||||||
|
class Options < T::Struct
|
||||||
|
# Whether to use brewed curl.
|
||||||
|
prop :homebrew_curl, T.nilable(T::Boolean)
|
||||||
|
|
||||||
|
# Form data to use when making a `POST` request.
|
||||||
|
prop :post_form, T.nilable(T::Hash[Symbol, String])
|
||||||
|
|
||||||
|
# JSON data to use when making a `POST` request.
|
||||||
|
prop :post_json, T.nilable(T::Hash[Symbol, String])
|
||||||
|
|
||||||
|
# Returns a `Hash` of options that are provided as arguments to `url`.
|
||||||
|
sig { returns(T::Hash[Symbol, T.untyped]) }
|
||||||
|
def url_options
|
||||||
|
{
|
||||||
|
homebrew_curl:,
|
||||||
|
post_form:,
|
||||||
|
post_json:,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a `Hash` of all instance variables, using `String` keys.
|
||||||
|
sig { returns(T::Hash[String, T.untyped]) }
|
||||||
|
def to_hash
|
||||||
|
T.let(serialize, T::Hash[String, T.untyped])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a `Hash` of all instance variables, using `Symbol` keys.
|
||||||
|
sig { returns(T::Hash[Symbol, T.untyped]) }
|
||||||
|
def to_h = to_hash.transform_keys(&:to_sym)
|
||||||
|
|
||||||
|
# Returns a new object formed by merging `other` values with a copy of
|
||||||
|
# `self`.
|
||||||
|
#
|
||||||
|
# `nil` values are removed from `other` before merging if it is an
|
||||||
|
# `Options` object, as these are unitiailized values. This ensures that
|
||||||
|
# existing values in `self` aren't unexpectedly overwritten with defaults.
|
||||||
|
sig { params(other: T.any(Options, T::Hash[Symbol, T.untyped])).returns(Options) }
|
||||||
|
def merge(other)
|
||||||
|
return dup if other.empty?
|
||||||
|
|
||||||
|
this_hash = to_h
|
||||||
|
other_hash = other.is_a?(Options) ? other.to_h : other
|
||||||
|
return dup if this_hash == other_hash
|
||||||
|
|
||||||
|
new_options = this_hash.merge(other_hash)
|
||||||
|
Options.new(**new_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Merges values from `other` into `self` and returns `self`.
|
||||||
|
#
|
||||||
|
# `nil` values are removed from `other` before merging if it is an
|
||||||
|
# `Options` object, as these are unitiailized values. This ensures that
|
||||||
|
# existing values in `self` aren't unexpectedly overwritten with defaults.
|
||||||
|
sig { params(other: T.any(Options, T::Hash[Symbol, T.untyped])).returns(Options) }
|
||||||
|
def merge!(other)
|
||||||
|
return self if other.empty?
|
||||||
|
|
||||||
|
if other.is_a?(Options)
|
||||||
|
return self if self == other
|
||||||
|
|
||||||
|
other.instance_variables.each do |ivar|
|
||||||
|
next if (v = T.let(other.instance_variable_get(ivar), Object)).nil?
|
||||||
|
|
||||||
|
instance_variable_set(ivar, v)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
other.each do |k, v|
|
||||||
|
cmd = :"#{k}="
|
||||||
|
send(cmd, v) if respond_to?(cmd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(other: Object).returns(T::Boolean) }
|
||||||
|
def ==(other)
|
||||||
|
return false unless other.is_a?(Options)
|
||||||
|
|
||||||
|
@homebrew_curl == other.homebrew_curl &&
|
||||||
|
@post_form == other.post_form &&
|
||||||
|
@post_json == other.post_json
|
||||||
|
end
|
||||||
|
alias eql? ==
|
||||||
|
|
||||||
|
# Whether the object has only default values.
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def empty? = to_hash.empty?
|
||||||
|
|
||||||
|
# Whether the object has any non-default values.
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def present? = !empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -2,6 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
|
require "livecheck/options"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module Livecheck
|
module Livecheck
|
||||||
@ -193,23 +194,16 @@ module Homebrew
|
|||||||
# collected into an array of hashes.
|
# collected into an array of hashes.
|
||||||
#
|
#
|
||||||
# @param url [String] the URL to fetch
|
# @param url [String] the URL to fetch
|
||||||
# @param url_options [Hash] options to modify curl behavior
|
# @param options [Options] options to modify behavior
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
sig {
|
sig { params(url: String, options: Options).returns(T::Array[T::Hash[String, String]]) }
|
||||||
params(
|
def self.page_headers(url, options: Options.new)
|
||||||
url: String,
|
|
||||||
url_options: T::Hash[Symbol, T.untyped],
|
|
||||||
homebrew_curl: T::Boolean,
|
|
||||||
).returns(T::Array[T::Hash[String, String]])
|
|
||||||
}
|
|
||||||
def self.page_headers(url, url_options: {}, homebrew_curl: false)
|
|
||||||
headers = []
|
headers = []
|
||||||
|
|
||||||
if url_options[:post_form].present? || url_options[:post_json].present?
|
if options.post_form || options.post_json
|
||||||
curl_post_args = ["--request", "POST", *post_args(
|
curl_post_args = ["--request", "POST", *post_args(
|
||||||
post_form: url_options[:post_form],
|
post_form: options.post_form,
|
||||||
post_json: url_options[:post_json],
|
post_json: options.post_json,
|
||||||
)]
|
)]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -221,7 +215,7 @@ module Homebrew
|
|||||||
MAX_REDIRECTIONS.to_s,
|
MAX_REDIRECTIONS.to_s,
|
||||||
url,
|
url,
|
||||||
wanted_headers: ["location", "content-disposition"],
|
wanted_headers: ["location", "content-disposition"],
|
||||||
use_homebrew_curl: homebrew_curl,
|
use_homebrew_curl: options.homebrew_curl || false,
|
||||||
user_agent:,
|
user_agent:,
|
||||||
**DEFAULT_CURL_OPTIONS,
|
**DEFAULT_CURL_OPTIONS,
|
||||||
)
|
)
|
||||||
@ -242,21 +236,14 @@ module Homebrew
|
|||||||
# array with the error message instead.
|
# array with the error message instead.
|
||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param url_options [Hash] options to modify curl behavior
|
# @param options [Options] options to modify behavior
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig { params(url: String, options: Options).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
params(
|
def self.page_content(url, options: Options.new)
|
||||||
url: String,
|
if options.post_form || options.post_json
|
||||||
url_options: T::Hash[Symbol, T.untyped],
|
|
||||||
homebrew_curl: T::Boolean,
|
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
|
||||||
}
|
|
||||||
def self.page_content(url, url_options: {}, homebrew_curl: false)
|
|
||||||
if url_options[:post_form].present? || url_options[:post_json].present?
|
|
||||||
curl_post_args = ["--request", "POST", *post_args(
|
curl_post_args = ["--request", "POST", *post_args(
|
||||||
post_form: url_options[:post_form],
|
post_form: options.post_form,
|
||||||
post_json: url_options[:post_json],
|
post_json: options.post_json,
|
||||||
)]
|
)]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -266,7 +253,9 @@ module Homebrew
|
|||||||
*curl_post_args,
|
*curl_post_args,
|
||||||
*PAGE_CONTENT_CURL_ARGS, url,
|
*PAGE_CONTENT_CURL_ARGS, url,
|
||||||
**DEFAULT_CURL_OPTIONS,
|
**DEFAULT_CURL_OPTIONS,
|
||||||
use_homebrew_curl: homebrew_curl || !curl_supports_fail_with_body?,
|
use_homebrew_curl: options.homebrew_curl ||
|
||||||
|
!curl_supports_fail_with_body? ||
|
||||||
|
false,
|
||||||
user_agent:
|
user_agent:
|
||||||
)
|
)
|
||||||
next unless status.success?
|
next unless status.success?
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Livecheck
|
|
||||||
module Strategy
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -85,19 +85,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -93,19 +93,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -72,19 +72,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -73,19 +73,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex for matching versions in content
|
# @param regex [Regexp, nil] a regex for matching versions in content
|
||||||
# @param provided_content [String, nil] content to check instead of
|
# @param provided_content [String, nil] content to check instead of
|
||||||
# fetching
|
# fetching
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
match_data[:cached] = true if provided_content.is_a?(String)
|
match_data[:cached] = true if provided_content.is_a?(String)
|
||||||
|
|
||||||
@ -97,13 +96,7 @@ module Homebrew
|
|||||||
content = if provided_content
|
content = if provided_content
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(match_data[:url], options:))
|
||||||
Strategy.page_content(
|
|
||||||
match_data[:url],
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data unless content
|
return match_data unless content
|
||||||
|
|||||||
@ -34,17 +34,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param provided_content [String, nil] content to use in place of
|
# @param provided_content [String, nil] content to use in place of
|
||||||
# fetching via `Strategy#page_content`
|
# fetching via `Strategy#page_content`
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
if regex.present? && block.blank?
|
if regex.present? && block.blank?
|
||||||
raise ArgumentError,
|
raise ArgumentError,
|
||||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||||
@ -54,7 +55,7 @@ module Homebrew
|
|||||||
url:,
|
url:,
|
||||||
regex:,
|
regex:,
|
||||||
provided_content:,
|
provided_content:,
|
||||||
**unused,
|
options:,
|
||||||
&block || proc { |yaml| yaml["version"] }
|
&block || proc { |yaml| yaml["version"] }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -79,17 +79,18 @@ module Homebrew
|
|||||||
# @param url [String, nil] an alternative URL to check for version
|
# @param url [String, nil] an alternative URL to check for version
|
||||||
# information
|
# information
|
||||||
# @param regex [Regexp, nil] a regex for use in a strategy block
|
# @param regex [Regexp, nil] a regex for use in a strategy block
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
cask: Cask::Cask,
|
cask: Cask::Cask,
|
||||||
url: T.nilable(String),
|
url: T.nilable(String),
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
_unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(cask:, url: nil, regex: nil, **_unused, &block)
|
def self.find_versions(cask:, url: nil, regex: nil, options: Options.new, &block)
|
||||||
if regex.present? && block.blank?
|
if regex.present? && block.blank?
|
||||||
raise ArgumentError,
|
raise ArgumentError,
|
||||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||||
|
|||||||
@ -186,16 +186,17 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the Git repository to check
|
# @param url [String] the URL of the Git repository to check
|
||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
_unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **_unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
tags_data = tag_info(url, regex)
|
tags_data = tag_info(url, regex)
|
||||||
|
|||||||
@ -70,16 +70,17 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: Regexp,
|
regex: Regexp,
|
||||||
_unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: GithubReleases::DEFAULT_REGEX, **_unused, &block)
|
def self.find_versions(url:, regex: GithubReleases::DEFAULT_REGEX, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|||||||
@ -124,16 +124,17 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: Regexp,
|
regex: Regexp,
|
||||||
_unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: DEFAULT_REGEX, **_unused, &block)
|
def self.find_versions(url:, regex: DEFAULT_REGEX, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|||||||
@ -74,22 +74,23 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
version_data = PageMatch.find_versions(
|
version_data = PageMatch.find_versions(
|
||||||
url: generated[:url],
|
url: generated[:url],
|
||||||
regex: regex || generated[:regex],
|
regex: regex || generated[:regex],
|
||||||
**unused,
|
options:,
|
||||||
&block
|
&block
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -84,19 +84,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -70,19 +70,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -67,25 +67,20 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL to fetch
|
# @param url [String] the URL to fetch
|
||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
headers = Strategy.page_headers(
|
headers = Strategy.page_headers(url, options:)
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Merge the headers from all responses into one hash
|
# Merge the headers from all responses into one hash
|
||||||
merged_headers = headers.reduce(&:merge)
|
merged_headers = headers.reduce(&:merge)
|
||||||
|
|||||||
@ -94,19 +94,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param provided_content [String, nil] page content to use in place of
|
# @param provided_content [String, nil] page content to use in place of
|
||||||
# fetching via `Strategy#page_content`
|
# fetching via `Strategy#page_content`
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||||
|
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
@ -116,13 +115,7 @@ module Homebrew
|
|||||||
match_data[:cached] = true
|
match_data[:cached] = true
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(url, options:))
|
||||||
Strategy.page_content(
|
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data if content.blank?
|
return match_data if content.blank?
|
||||||
|
|||||||
@ -67,19 +67,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: Regexp,
|
regex: Regexp,
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: DEFAULT_REGEX, **unused, &block)
|
def self.find_versions(url:, regex: DEFAULT_REGEX, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex:, **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex:,
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -65,19 +65,25 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(url: generated[:url], regex: regex || generated[:regex], **unused, &block)
|
PageMatch.find_versions(
|
||||||
|
url: generated[:url],
|
||||||
|
regex: regex || generated[:regex],
|
||||||
|
options:,
|
||||||
|
&block
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -77,19 +77,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param provided_content [String, nil] page content to use in place of
|
# @param provided_content [String, nil] page content to use in place of
|
||||||
# fetching via `Strategy#page_content`
|
# fetching via `Strategy#page_content`
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
if regex.blank? && block.blank?
|
if regex.blank? && block.blank?
|
||||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a regex or `strategy` block"
|
raise ArgumentError, "#{Utils.demodulize(name)} requires a regex or `strategy` block"
|
||||||
end
|
end
|
||||||
@ -101,13 +100,7 @@ module Homebrew
|
|||||||
match_data[:cached] = true
|
match_data[:cached] = true
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(url, options:))
|
||||||
Strategy.page_content(
|
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data if content.blank?
|
return match_data if content.blank?
|
||||||
|
|||||||
@ -79,17 +79,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
# @param provided_content [String, nil] content to check instead of
|
# @param provided_content [String, nil] content to check instead of
|
||||||
# fetching
|
# fetching
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
@ -99,7 +100,7 @@ module Homebrew
|
|||||||
url: generated[:url],
|
url: generated[:url],
|
||||||
regex:,
|
regex:,
|
||||||
provided_content:,
|
provided_content:,
|
||||||
**unused,
|
options:,
|
||||||
&block || DEFAULT_BLOCK
|
&block || DEFAULT_BLOCK
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -84,22 +84,23 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
|
|
||||||
PageMatch.find_versions(
|
PageMatch.find_versions(
|
||||||
url: generated[:url] || url,
|
url: generated[:url] || url,
|
||||||
regex: regex || generated[:regex],
|
regex: regex || generated[:regex],
|
||||||
**unused,
|
options:,
|
||||||
&block
|
&block
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -214,18 +214,17 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp, nil] a regex for use in a strategy block
|
# @param regex [Regexp, nil] a regex for use in a strategy block
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
if regex.present? && block.blank?
|
if regex.present? && block.blank?
|
||||||
raise ArgumentError,
|
raise ArgumentError,
|
||||||
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
||||||
@ -233,13 +232,7 @@ module Homebrew
|
|||||||
|
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
|
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(url, options:))
|
||||||
Strategy.page_content(
|
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
content = match_data.delete(:content)
|
content = match_data.delete(:content)
|
||||||
return match_data if content.blank?
|
return match_data if content.blank?
|
||||||
|
|
||||||
|
|||||||
@ -134,19 +134,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param provided_content [String, nil] page content to use in place of
|
# @param provided_content [String, nil] page content to use in place of
|
||||||
# fetching via `Strategy#page_content`
|
# fetching via `Strategy#page_content`
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||||
|
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
@ -156,13 +155,7 @@ module Homebrew
|
|||||||
match_data[:cached] = true
|
match_data[:cached] = true
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(url, options:))
|
||||||
Strategy.page_content(
|
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data if content.blank?
|
return match_data if content.blank?
|
||||||
|
|||||||
@ -109,16 +109,17 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @param url [String] the URL of the content to check
|
# @param url [String] the URL of the content to check
|
||||||
# @param regex [Regexp] a regex used for matching versions in content
|
# @param regex [Regexp] a regex used for matching versions in content
|
||||||
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
unused: T.untyped,
|
options: Options,
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, **unused, &block)
|
def self.find_versions(url:, regex: nil, options: Options.new, &block)
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
generated_url = generated[:url]
|
generated_url = generated[:url]
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ module Homebrew
|
|||||||
url: generated_url,
|
url: generated_url,
|
||||||
regex: regex || generated[:regex],
|
regex: regex || generated[:regex],
|
||||||
provided_content: cached_content,
|
provided_content: cached_content,
|
||||||
**unused,
|
options:,
|
||||||
&block
|
&block
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -94,19 +94,18 @@ module Homebrew
|
|||||||
# @param regex [Regexp, nil] a regex used for matching versions
|
# @param regex [Regexp, nil] a regex used for matching versions
|
||||||
# @param provided_content [String, nil] page content to use in place of
|
# @param provided_content [String, nil] page content to use in place of
|
||||||
# fetching via `Strategy#page_content`
|
# fetching via `Strategy#page_content`
|
||||||
# @param homebrew_curl [Boolean] whether to use brewed curl with the URL
|
# @param options [Options] options to modify behavior
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
url: String,
|
url: String,
|
||||||
regex: T.nilable(Regexp),
|
regex: T.nilable(Regexp),
|
||||||
provided_content: T.nilable(String),
|
provided_content: T.nilable(String),
|
||||||
homebrew_curl: T::Boolean,
|
options: Options,
|
||||||
unused: T.untyped,
|
|
||||||
block: T.nilable(Proc),
|
block: T.nilable(Proc),
|
||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **unused, &block)
|
def self.find_versions(url:, regex: nil, provided_content: nil, options: Options.new, &block)
|
||||||
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
raise ArgumentError, "#{Utils.demodulize(name)} requires a `strategy` block" if block.blank?
|
||||||
|
|
||||||
match_data = { matches: {}, regex:, url: }
|
match_data = { matches: {}, regex:, url: }
|
||||||
@ -116,13 +115,7 @@ module Homebrew
|
|||||||
match_data[:cached] = true
|
match_data[:cached] = true
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(
|
match_data.merge!(Strategy.page_content(url, options:))
|
||||||
Strategy.page_content(
|
|
||||||
url,
|
|
||||||
url_options: unused.fetch(:url_options, {}),
|
|
||||||
homebrew_curl:,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data if content.blank?
|
return match_data if content.blank?
|
||||||
|
|||||||
@ -86,6 +86,22 @@ RSpec.describe Homebrew::Livecheck do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "::livecheck_find_versions_parameters" do
|
||||||
|
context "when provided with a strategy class" do
|
||||||
|
it "returns demodulized class name" do
|
||||||
|
page_match_parameters = T::Utils.signature_for_method(
|
||||||
|
Homebrew::Livecheck::Strategy::PageMatch.method(:find_versions),
|
||||||
|
).parameters.map(&:second)
|
||||||
|
|
||||||
|
# We run this twice with the same argument to exercise the caching logic
|
||||||
|
expect(livecheck.send(:livecheck_find_versions_parameters, Homebrew::Livecheck::Strategy::PageMatch))
|
||||||
|
.to eq(page_match_parameters)
|
||||||
|
expect(livecheck.send(:livecheck_find_versions_parameters, Homebrew::Livecheck::Strategy::PageMatch))
|
||||||
|
.to eq(page_match_parameters)
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|||||||
148
Library/Homebrew/test/livecheck/options_spec.rb
Normal file
148
Library/Homebrew/test/livecheck/options_spec.rb
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "livecheck/options"
|
||||||
|
|
||||||
|
RSpec.describe Homebrew::Livecheck::Options do
|
||||||
|
subject(:options) { described_class }
|
||||||
|
|
||||||
|
let(:post_hash) do
|
||||||
|
{
|
||||||
|
empty: "",
|
||||||
|
boolean: "true",
|
||||||
|
number: "1",
|
||||||
|
string: "a + b = c",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:args) do
|
||||||
|
{
|
||||||
|
homebrew_curl: true,
|
||||||
|
post_form: post_hash,
|
||||||
|
post_json: post_hash,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:other_args) do
|
||||||
|
{
|
||||||
|
post_form: { something: "else" },
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:merged_hash) { args.merge(other_args) }
|
||||||
|
|
||||||
|
let(:base_options) { options.new(**args) }
|
||||||
|
let(:other_options) { options.new(**other_args) }
|
||||||
|
let(:merged_options) { options.new(**merged_hash) }
|
||||||
|
|
||||||
|
describe "#url_options" do
|
||||||
|
it "returns a Hash of the options that are provided as arguments to the `url` DSL method" do
|
||||||
|
expect(options.new.url_options).to eq({
|
||||||
|
homebrew_curl: nil,
|
||||||
|
post_form: nil,
|
||||||
|
post_json: nil,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#to_h" do
|
||||||
|
it "returns a Hash of all instance variables" do
|
||||||
|
# `T::Struct.serialize` omits `nil` values
|
||||||
|
expect(options.new.to_h).to eq({})
|
||||||
|
|
||||||
|
expect(options.new(**args).to_h).to eq(args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#to_hash" do
|
||||||
|
it "returns a Hash of all instance variables, using String keys" do
|
||||||
|
# `T::Struct.serialize` omits `nil` values
|
||||||
|
expect(options.new.to_hash).to eq({})
|
||||||
|
|
||||||
|
expect(options.new(**args).to_hash).to eq(args.transform_keys(&:to_s))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#merge" do
|
||||||
|
it "returns an Options object with merged values" do
|
||||||
|
expect(options.new(**args).merge(other_args))
|
||||||
|
.to eq(options.new(**merged_hash))
|
||||||
|
expect(options.new(**args).merge(options.new(**other_args)))
|
||||||
|
.to eq(options.new(**merged_hash))
|
||||||
|
expect(options.new(**args).merge(args))
|
||||||
|
.to eq(options.new(**args))
|
||||||
|
expect(options.new(**args).merge({}))
|
||||||
|
.to eq(options.new(**args))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#merge!" do
|
||||||
|
it "merges values from `other` into `self` and returns `self`" do
|
||||||
|
o1 = options.new(**args)
|
||||||
|
expect(o1.merge!(other_options)).to eq(merged_options)
|
||||||
|
expect(o1).to eq(merged_options)
|
||||||
|
|
||||||
|
o2 = options.new(**args)
|
||||||
|
expect(o2.merge!(other_args)).to eq(merged_options)
|
||||||
|
expect(o2).to eq(merged_options)
|
||||||
|
|
||||||
|
o3 = options.new(**args)
|
||||||
|
expect(o3.merge!(base_options)).to eq(base_options)
|
||||||
|
expect(o3).to eq(base_options)
|
||||||
|
|
||||||
|
o4 = options.new(**args)
|
||||||
|
expect(o4.merge!(args)).to eq(base_options)
|
||||||
|
expect(o4).to eq(base_options)
|
||||||
|
|
||||||
|
o5 = options.new(**args)
|
||||||
|
expect(o5.merge!(options.new)).to eq(base_options)
|
||||||
|
expect(o5).to eq(base_options)
|
||||||
|
|
||||||
|
o6 = options.new(**args)
|
||||||
|
expect(o6.merge!({})).to eq(base_options)
|
||||||
|
expect(o6).to eq(base_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "skips over hash values without a corresponding Options value" do
|
||||||
|
o1 = options.new(**args)
|
||||||
|
expect(o1.merge!({ nonexistent: true })).to eq(base_options)
|
||||||
|
expect(o1).to eq(base_options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#==" do
|
||||||
|
it "returns true if all instance variables are the same" do
|
||||||
|
obj_with_args1 = options.new(**args)
|
||||||
|
obj_with_args2 = options.new(**args)
|
||||||
|
expect(obj_with_args1 == obj_with_args2).to be true
|
||||||
|
|
||||||
|
default_obj1 = options.new
|
||||||
|
default_obj2 = options.new
|
||||||
|
expect(default_obj1 == default_obj2).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if any instance variables differ" do
|
||||||
|
expect(options.new == options.new(**args)).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if other object is not the same class" do
|
||||||
|
expect(options.new == :other).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#empty?" do
|
||||||
|
it "returns true if object has only default values" do
|
||||||
|
expect(options.new.empty?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false if object has any non-default values" do
|
||||||
|
expect(options.new(**args).empty?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#present?" do
|
||||||
|
it "returns false if object has only default values" do
|
||||||
|
expect(options.new.present?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns true if object has any non-default values" do
|
||||||
|
expect(options.new(**args).present?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -181,8 +181,12 @@ RSpec.describe Homebrew::Livecheck::Strategy do
|
|||||||
it "handles `post_form` `url` options" do
|
it "handles `post_form` `url` options" do
|
||||||
allow(strategy).to receive(:curl_headers).and_return({ responses:, body: })
|
allow(strategy).to receive(:curl_headers).and_return({ responses:, body: })
|
||||||
|
|
||||||
expect(strategy.page_headers(url, url_options: { post_form: post_hash }))
|
expect(
|
||||||
.to eq([responses.first[:headers]])
|
strategy.page_headers(
|
||||||
|
url,
|
||||||
|
options: Homebrew::Livecheck::Options.new(post_form: post_hash),
|
||||||
|
),
|
||||||
|
).to eq([responses.first[:headers]])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an empty array if `curl_headers` only raises an `ErrorDuringExecution` error" do
|
it "returns an empty array if `curl_headers` only raises an `ErrorDuringExecution` error" do
|
||||||
@ -207,14 +211,24 @@ RSpec.describe Homebrew::Livecheck::Strategy do
|
|||||||
allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version)
|
allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version)
|
||||||
allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status])
|
allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status])
|
||||||
|
|
||||||
expect(strategy.page_content(url, url_options: { post_form: post_hash })).to eq({ content: body })
|
expect(
|
||||||
|
strategy.page_content(
|
||||||
|
url,
|
||||||
|
options: Homebrew::Livecheck::Options.new(post_form: post_hash),
|
||||||
|
),
|
||||||
|
).to eq({ content: body })
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles `post_json` `url` option" do
|
it "handles `post_json` `url` option" do
|
||||||
allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version)
|
allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version)
|
||||||
allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status])
|
allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status])
|
||||||
|
|
||||||
expect(strategy.page_content(url, url_options: { post_json: post_hash })).to eq({ content: body })
|
expect(
|
||||||
|
strategy.page_content(
|
||||||
|
url,
|
||||||
|
options: Homebrew::Livecheck::Options.new(post_json: post_hash),
|
||||||
|
),
|
||||||
|
).to eq({ content: body })
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns error `messages` from `stderr` in the return hash on failure when `stderr` is not `nil`" do
|
it "returns error `messages` from `stderr` in the return hash on failure when `stderr` is not `nil`" do
|
||||||
|
|||||||
@ -156,10 +156,17 @@ RSpec.describe Livecheck do
|
|||||||
expect(livecheck_c.url).to eq(:url)
|
expect(livecheck_c.url).to eq(:url)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets `url_options` when provided" do
|
it "sets `url` options when provided" do
|
||||||
post_args = { post_form: post_hash }
|
# This test makes sure that we can set multiple options at once and
|
||||||
livecheck_f.url(url_string, **post_args)
|
# options from subsequent `url` calls are merged with existing values
|
||||||
expect(livecheck_f.url_options).to eq(post_args)
|
# (i.e. existing values aren't reset to `nil`). [We only call `url` once
|
||||||
|
# in a `livecheck` block but this should technically work due to how it's
|
||||||
|
# implemented.]
|
||||||
|
livecheck_f.url(url_string, homebrew_curl: true, post_form: post_hash)
|
||||||
|
livecheck_f.url(url_string, post_json: post_hash)
|
||||||
|
expect(livecheck_f.options.homebrew_curl).to be(true)
|
||||||
|
expect(livecheck_f.options.post_form).to eq(post_hash)
|
||||||
|
expect(livecheck_f.options.post_json).to eq(post_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an ArgumentError if the argument isn't a valid Symbol" do
|
it "raises an ArgumentError if the argument isn't a valid Symbol" do
|
||||||
@ -179,6 +186,7 @@ RSpec.describe Livecheck do
|
|||||||
it "returns a Hash of all instance variables" do
|
it "returns a Hash of all instance variables" do
|
||||||
expect(livecheck_f.to_hash).to eq(
|
expect(livecheck_f.to_hash).to eq(
|
||||||
{
|
{
|
||||||
|
"options" => Homebrew::Livecheck::Options.new.to_hash,
|
||||||
"cask" => nil,
|
"cask" => nil,
|
||||||
"formula" => nil,
|
"formula" => nil,
|
||||||
"regex" => nil,
|
"regex" => nil,
|
||||||
@ -187,7 +195,6 @@ RSpec.describe Livecheck do
|
|||||||
"strategy" => nil,
|
"strategy" => nil,
|
||||||
"throttle" => nil,
|
"throttle" => nil,
|
||||||
"url" => nil,
|
"url" => nil,
|
||||||
"url_options" => nil,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user