Crate: Rework conditions

Co-authored-by: Douglas Eichelberger <dduugg@gmail.com>
Co-authored-by: Markus Reiter <me@reitermark.us>
This commit is contained in:
Sam Ford 2024-02-08 17:30:11 -05:00
parent 98f3258ff4
commit 55ec4c483c
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D
2 changed files with 7 additions and 11 deletions

View File

@ -25,10 +25,8 @@ module Homebrew
# a `strategy` block isn't provided.
DEFAULT_BLOCK = proc do |json, regex|
json["versions"]&.map do |version|
next if version["yanked"] == true
match = version["num"]&.match(regex)
next if match.blank?
next if version["yanked"]
next unless (match = version["num"]&.match(regex))
match[1]
end
@ -58,9 +56,7 @@ module Homebrew
sig { params(url: String).returns(T::Hash[Symbol, T.untyped]) }
def self.generate_input_values(url)
values = {}
match = url.match(URL_MATCH_REGEX)
return values if match.blank?
return values unless (match = url.match(URL_MATCH_REGEX))
values[:url] = "https://crates.io/api/v1/crates/#{match[:package]}/versions"
@ -95,13 +91,13 @@ module Homebrew
match_data[:url] = generated[:url]
content = if provided_content.is_a?(String)
content = if provided_content
provided_content
else
match_data.merge!(Strategy.page_content(match_data[:url], homebrew_curl: homebrew_curl))
match_data[:content]
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|
match_data[:matches][match_text] = Version.new(match_text)

View File

@ -248,8 +248,8 @@ livecheck do
url :stable
strategy :crate do |json, regex|
json["versions"]&.map do |version|
next if version["yanked"] == true
next if (match = version["num"]&.match(regex)).blank?
next if version["yanked"]
next unless (match = version["num"]&.match(regex))
match[1]
end