2024-06-02 15:14:25 +01:00
|
|
|
# typed: strict
|
2021-03-17 01:58:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module Livecheck
|
|
|
|
module Strategy
|
2022-06-09 15:38:02 -04:00
|
|
|
# The {ElectronBuilder} strategy fetches content at a URL and parses it
|
|
|
|
# as an electron-builder appcast in YAML format.
|
2021-03-17 01:58:31 +05:30
|
|
|
#
|
2021-08-10 18:38:21 -04:00
|
|
|
# This strategy is not applied automatically and it's necessary to use
|
|
|
|
# `strategy :electron_builder` in a `livecheck` block to apply it.
|
2021-03-17 01:58:31 +05:30
|
|
|
class ElectronBuilder
|
|
|
|
NICE_NAME = "electron-builder"
|
|
|
|
|
|
|
|
# A priority of zero causes livecheck to skip the strategy. We do this
|
2021-08-10 18:38:21 -04:00
|
|
|
# for {ElectronBuilder} so we can selectively apply it when appropriate.
|
2021-03-17 01:58:31 +05:30
|
|
|
PRIORITY = 0
|
|
|
|
|
|
|
|
# The `Regexp` used to determine if the strategy applies to the URL.
|
2024-01-18 22:18:42 +00:00
|
|
|
URL_MATCH_REGEX = %r{^https?://.+/[^/]+\.ya?ml(?:\?[^/?]+)?$}i
|
2021-03-17 01:58:31 +05:30
|
|
|
|
|
|
|
# Whether the strategy can be applied to the provided URL.
|
|
|
|
#
|
|
|
|
# @param url [String] the URL to match against
|
|
|
|
# @return [Boolean]
|
|
|
|
sig { params(url: String).returns(T::Boolean) }
|
|
|
|
def self.match?(url)
|
|
|
|
URL_MATCH_REGEX.match?(url)
|
|
|
|
end
|
|
|
|
|
2021-08-10 18:38:21 -04:00
|
|
|
# Checks the YAML content at the URL for new versions.
|
2021-03-17 01:58:31 +05:30
|
|
|
#
|
|
|
|
# @param url [String] the URL of the content to check
|
2023-03-02 15:20:33 -05:00
|
|
|
# @param regex [Regexp, nil] a regex used for matching versions
|
|
|
|
# @param provided_content [String, nil] content to use in place of
|
|
|
|
# fetching via `Strategy#page_content`
|
2021-03-17 01:58:31 +05:30
|
|
|
# @return [Hash]
|
2021-03-17 02:29:53 +05:30
|
|
|
sig {
|
|
|
|
params(
|
2023-03-02 15:20:33 -05:00
|
|
|
url: String,
|
|
|
|
regex: T.nilable(Regexp),
|
|
|
|
provided_content: T.nilable(String),
|
2024-02-28 12:32:21 -05:00
|
|
|
unused: T.untyped,
|
2023-04-04 22:40:31 -07:00
|
|
|
block: T.nilable(Proc),
|
2021-03-17 02:29:53 +05:30
|
|
|
).returns(T::Hash[Symbol, T.untyped])
|
|
|
|
}
|
2023-03-02 15:20:33 -05:00
|
|
|
def self.find_versions(url:, regex: nil, provided_content: nil, **unused, &block)
|
2021-11-16 12:31:54 -05:00
|
|
|
if regex.present? && block.blank?
|
2023-02-23 12:23:44 -08:00
|
|
|
raise ArgumentError,
|
2025-02-23 11:08:00 -08:00
|
|
|
"#{Utils.demodulize(name)} only supports a regex when using a `strategy` block"
|
2021-11-16 12:31:54 -05:00
|
|
|
end
|
2021-03-17 01:58:31 +05:30
|
|
|
|
2023-04-03 17:34:39 -07:00
|
|
|
Yaml.find_versions(
|
2024-03-07 16:20:20 +00:00
|
|
|
url:,
|
|
|
|
regex:,
|
|
|
|
provided_content:,
|
2023-03-02 15:20:33 -05:00
|
|
|
**unused,
|
|
|
|
&block || proc { |yaml| yaml["version"] }
|
|
|
|
)
|
2021-03-17 01:58:31 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|