Crate: Rework conditions
Co-authored-by: Douglas Eichelberger <dduugg@gmail.com> Co-authored-by: Markus Reiter <me@reitermark.us>
This commit is contained in:
parent
98f3258ff4
commit
55ec4c483c
@ -25,10 +25,8 @@ module Homebrew
|
|||||||
# a `strategy` block isn't provided.
|
# a `strategy` block isn't provided.
|
||||||
DEFAULT_BLOCK = proc do |json, regex|
|
DEFAULT_BLOCK = proc do |json, regex|
|
||||||
json["versions"]&.map do |version|
|
json["versions"]&.map do |version|
|
||||||
next if version["yanked"] == true
|
next if version["yanked"]
|
||||||
|
next unless (match = version["num"]&.match(regex))
|
||||||
match = version["num"]&.match(regex)
|
|
||||||
next if match.blank?
|
|
||||||
|
|
||||||
match[1]
|
match[1]
|
||||||
end
|
end
|
||||||
@ -58,9 +56,7 @@ module Homebrew
|
|||||||
sig { params(url: String).returns(T::Hash[Symbol, T.untyped]) }
|
sig { params(url: String).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
def self.generate_input_values(url)
|
def self.generate_input_values(url)
|
||||||
values = {}
|
values = {}
|
||||||
|
return values unless (match = url.match(URL_MATCH_REGEX))
|
||||||
match = url.match(URL_MATCH_REGEX)
|
|
||||||
return values if match.blank?
|
|
||||||
|
|
||||||
values[:url] = "https://crates.io/api/v1/crates/#{match[:package]}/versions"
|
values[:url] = "https://crates.io/api/v1/crates/#{match[:package]}/versions"
|
||||||
|
|
||||||
@ -95,13 +91,13 @@ module Homebrew
|
|||||||
|
|
||||||
match_data[:url] = generated[:url]
|
match_data[:url] = generated[:url]
|
||||||
|
|
||||||
content = if provided_content.is_a?(String)
|
content = if provided_content
|
||||||
provided_content
|
provided_content
|
||||||
else
|
else
|
||||||
match_data.merge!(Strategy.page_content(match_data[:url], homebrew_curl: homebrew_curl))
|
match_data.merge!(Strategy.page_content(match_data[:url], homebrew_curl: homebrew_curl))
|
||||||
match_data[:content]
|
match_data[:content]
|
||||||
end
|
end
|
||||||
return match_data if content.blank?
|
return match_data unless content
|
||||||
|
|
||||||
Json.versions_from_content(content, regex || DEFAULT_REGEX, &block || DEFAULT_BLOCK).each do |match_text|
|
Json.versions_from_content(content, regex || DEFAULT_REGEX, &block || DEFAULT_BLOCK).each do |match_text|
|
||||||
match_data[:matches][match_text] = Version.new(match_text)
|
match_data[:matches][match_text] = Version.new(match_text)
|
||||||
|
@ -248,8 +248,8 @@ livecheck do
|
|||||||
url :stable
|
url :stable
|
||||||
strategy :crate do |json, regex|
|
strategy :crate do |json, regex|
|
||||||
json["versions"]&.map do |version|
|
json["versions"]&.map do |version|
|
||||||
next if version["yanked"] == true
|
next if version["yanked"]
|
||||||
next if (match = version["num"]&.match(regex)).blank?
|
next unless (match = version["num"]&.match(regex))
|
||||||
|
|
||||||
match[1]
|
match[1]
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user