GithubRelease: Add #generate_input_values method
Keeping the logic for generating the API URL in a method makes it testable, aligns with other strategies, and will help to enable some future work.
This commit is contained in:
parent
701f7c5051
commit
263f486806
@ -81,6 +81,7 @@ module Homebrew
|
|||||||
}
|
}
|
||||||
def self.find_versions(url:, regex: GitHubRelease::DEFAULT_REGEX, **_unused, &block)
|
def self.find_versions(url:, regex: GitHubRelease::DEFAULT_REGEX, **_unused, &block)
|
||||||
match_data = { matches: {}, regex: regex, url: url }
|
match_data = { matches: {}, regex: regex, url: url }
|
||||||
|
|
||||||
generated = generate_input_values(url)
|
generated = generate_input_values(url)
|
||||||
return match_data if generated.blank?
|
return match_data if generated.blank?
|
||||||
|
|
||||||
|
@ -61,6 +61,27 @@ module Homebrew
|
|||||||
URL_MATCH_REGEX.match?(url)
|
URL_MATCH_REGEX.match?(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Extracts information from a provided URL and uses it to generate
|
||||||
|
# various input values used by the strategy to check for new versions.
|
||||||
|
# Some of these values act as defaults and can be overridden in a
|
||||||
|
# `livecheck` block.
|
||||||
|
#
|
||||||
|
# @param url [String] the URL used to generate values
|
||||||
|
# @return [Hash]
|
||||||
|
sig { params(url: String).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
|
def self.generate_input_values(url)
|
||||||
|
values = {}
|
||||||
|
|
||||||
|
match = url.delete_suffix(".git").match(URL_MATCH_REGEX)
|
||||||
|
return values if match.blank?
|
||||||
|
|
||||||
|
values[:url] = "#{GitHub::API_URL}/repos/#{match[:username]}/#{match[:repository]}/releases"
|
||||||
|
values[:username] = match[:username]
|
||||||
|
values[:repository] = match[:repository]
|
||||||
|
|
||||||
|
values
|
||||||
|
end
|
||||||
|
|
||||||
# Uses a regex to match versions from release JSON or, if a block is
|
# Uses a regex to match versions from release JSON or, if a block is
|
||||||
# provided, passes the JSON to the block to handle matching. With
|
# provided, passes the JSON to the block to handle matching. With
|
||||||
# either approach, an array of unique matches is returned.
|
# either approach, an array of unique matches is returned.
|
||||||
@ -117,12 +138,14 @@ module Homebrew
|
|||||||
).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, **_unused, &block)
|
||||||
match_data = { matches: {}, regex: regex }
|
match_data = { matches: {}, regex: regex, url: url }
|
||||||
match = url.delete_suffix(".git")
|
|
||||||
.match(URL_MATCH_REGEX)
|
|
||||||
return match_data if match.blank?
|
|
||||||
|
|
||||||
releases = GitHub::API.open_rest("https://api.github.com/repos/#{match[:username]}/#{match[:repository]}/releases")
|
generated = generate_input_values(url)
|
||||||
|
return match_data if generated.blank?
|
||||||
|
|
||||||
|
match_data[:url] = generated[:url]
|
||||||
|
|
||||||
|
releases = GitHub::API.open_rest(generated[:url])
|
||||||
versions_from_content(releases, regex, &block).each do |match_text|
|
versions_from_content(releases, regex, &block).each do |match_text|
|
||||||
match_data[:matches][match_text] = Version.new(match_text)
|
match_data[:matches][match_text] = Version.new(match_text)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user