Class: Homebrew::Livecheck::Strategy::GithubLatest
- Defined in:
- livecheck/strategy/github_latest.rb
Overview
The GithubLatest strategy identifies versions of software at github.com by checking a repository's "latest" release using the GitHub API.
GitHub URLs take a few different formats:
https://github.com/example/example/releases/download/1.2.3/example-1.2.3.tar.gz
https://github.com/example/example/archive/v1.2.3.tar.gz
https://github.com/downloads/example/example/example-1.2.3.tar.gz
GithubLatest should only be used when the upstream repository has a
"latest" release for a suitable version and the strategy is necessary
or appropriate (e.g. the formula/cask uses a release asset or the
Git strategy returns an unreleased version). The strategy can only
be applied by using strategy :github_latest
in a livecheck
block.
The default regex identifies versions like 1.2.3
/v1.2.3
in a
release's tag or title. This is a common tag format but a modified
regex can be provided in a livecheck
block to override the default
if a repository uses a different format (e.g. 1.2.3d
, 1.2.3-4
,
etc.).
Constant Summary collapse
- NICE_NAME =
"GitHub - Latest"
- PRIORITY =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
A priority of zero causes livecheck to skip the strategy. We do this for Homebrew::Livecheck::Strategy::GithubLatest so we can selectively apply the strategy using
strategy :github_latest
in alivecheck
block. 0
Class Method Summary collapse
-
.find_versions(url:, regex: GithubReleases::DEFAULT_REGEX, **_unused, &block) ⇒ Hash{Symbol => T.untyped}
private
Generates the GitHub API URL for the repository's "latest" release and identifies the version from the JSON response.
-
.generate_input_values(url) ⇒ Hash{Symbol => T.untyped}
private
Extracts information from a provided URL and uses it to generate various input values used by the strategy to check for new versions.
-
.match?(url) ⇒ Boolean
private
Whether the strategy can be applied to the provided URL.
Class Method Details
.find_versions(url:, regex: GithubReleases::DEFAULT_REGEX, **_unused, &block) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Generates the GitHub API URL for the repository's "latest" release and identifies the version from the JSON response.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'livecheck/strategy/github_latest.rb', line 82 def self.find_versions(url:, regex: GithubReleases::DEFAULT_REGEX, **_unused, &block) match_data = { matches: {}, regex:, url: } generated = generate_input_values(url) return match_data if generated.blank? match_data[:url] = generated[:url] release = GitHub.get_latest_release(generated[:username], generated[:repository]) GithubReleases.versions_from_content(release, regex, &block).each do |match_text| match_data[:matches][match_text] = Version.new(match_text) end match_data end |
.generate_input_values(url) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
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.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'livecheck/strategy/github_latest.rb', line 55 def self.generate_input_values(url) values = {} match = url.delete_suffix(".git").match(GithubReleases::URL_MATCH_REGEX) return values if match.blank? values[:url] = "https://api.github.com/repos/#{match[:username]}/#{match[:repository]}/releases/latest" values[:username] = match[:username] values[:repository] = match[:repository] values end |
.match?(url) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Whether the strategy can be applied to the provided URL.
43 44 45 |
# File 'livecheck/strategy/github_latest.rb', line 43 def self.match?(url) GithubReleases.match?(url) end |