From 34e2779150a065ea4db5269f64cc78b508e94314 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Thu, 4 May 2023 11:12:31 -0400 Subject: [PATCH] GithubLatest: Move #generate_input_values `#generate_input_values` is called before `#versions_from_content` (in `#find_versions`), so it makes sense to move it above the latter. --- .../livecheck/strategy/github_latest.rb | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/github_latest.rb b/Library/Homebrew/livecheck/strategy/github_latest.rb index f5a6e21f43..c5f4a21b85 100644 --- a/Library/Homebrew/livecheck/strategy/github_latest.rb +++ b/Library/Homebrew/livecheck/strategy/github_latest.rb @@ -62,6 +62,28 @@ module Homebrew URL_MATCH_REGEX.match?(url) 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.sub(/\.git$/i, "").match(URL_MATCH_REGEX) + return values if match.blank? + + # Example URL: `https://github.com/example/example/releases/latest` + values[:url] = "https://github.com/#{match[:username]}/#{match[:repository]}/releases/latest" + values[:username] = match[:username] + values[:repository] = match[:repository] + + values + end + # Uses the regex to match release information in content or, if a block is # provided, passes the page content to the block to handle matching. # With either approach, an array of unique matches is returned. @@ -98,28 +120,6 @@ module Homebrew end.compact.uniq 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.sub(/\.git$/i, "").match(URL_MATCH_REGEX) - return values if match.blank? - - # Example URL: `https://github.com/example/example/releases/latest` - values[:url] = "https://github.com/#{match[:username]}/#{match[:repository]}/releases/latest" - values[:username] = match[:username] - values[:repository] = match[:repository] - - values - end - # Generates a URL and regex (if one isn't provided) and passes them # to {PageMatch.find_versions} to identify versions in the content. #