Merge pull request #11839 from Rylan12/fix-api-paths
api: fix generic api path functions
This commit is contained in:
commit
764959b73a
@ -7,19 +7,19 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Analytics
|
module Analytics
|
||||||
extend T::Sig
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
sig { returns(String) }
|
||||||
|
def analytics_api_path
|
||||||
|
"analytics"
|
||||||
|
end
|
||||||
|
alias generic_analytics_api_path analytics_api_path
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { params(category: String, days: T.any(Integer, String)).returns(Hash) }
|
||||||
def analytics_api_path
|
def fetch(category, days)
|
||||||
"analytics"
|
Homebrew::API.fetch "#{analytics_api_path}/#{category}/#{days}d.json"
|
||||||
end
|
end
|
||||||
alias generic_analytics_api_path analytics_api_path
|
|
||||||
|
|
||||||
sig { params(category: String, days: T.any(Integer, String)).returns(Hash) }
|
|
||||||
def fetch(category, days)
|
|
||||||
Homebrew::API.fetch "#{analytics_api_path}/#{category}/#{days}d.json"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,84 +9,84 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Bottle
|
module Bottle
|
||||||
extend T::Sig
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
sig { returns(String) }
|
||||||
|
def bottle_api_path
|
||||||
|
"bottle"
|
||||||
|
end
|
||||||
|
alias generic_bottle_api_path bottle_api_path
|
||||||
|
|
||||||
sig { returns(String) }
|
GITHUB_PACKAGES_SHA256_REGEX = %r{#{GitHubPackages::URL_REGEX}.*/blobs/sha256:(?<sha256>\h{64})$}.freeze
|
||||||
def bottle_api_path
|
|
||||||
"bottle"
|
|
||||||
end
|
|
||||||
alias generic_bottle_api_path bottle_api_path
|
|
||||||
|
|
||||||
GITHUB_PACKAGES_SHA256_REGEX = %r{#{GitHubPackages::URL_REGEX}.*/blobs/sha256:(?<sha256>\h{64})$}.freeze
|
sig { params(name: String).returns(Hash) }
|
||||||
|
def fetch(name)
|
||||||
sig { params(name: String).returns(Hash) }
|
Homebrew::API.fetch "#{bottle_api_path}/#{name}.json"
|
||||||
def fetch(name)
|
|
||||||
Homebrew::API.fetch "#{bottle_api_path}/#{name}.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(name: String).returns(T::Boolean) }
|
|
||||||
def available?(name)
|
|
||||||
fetch name
|
|
||||||
true
|
|
||||||
rescue ArgumentError
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(name: String).void }
|
|
||||||
def fetch_bottles(name)
|
|
||||||
hash = fetch(name)
|
|
||||||
bottle_tag = Utils::Bottles.tag.to_s
|
|
||||||
|
|
||||||
if !hash["bottles"].key?(bottle_tag) && !hash["bottles"].key?("all")
|
|
||||||
odie "No bottle available for #{name} on the current OS"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
download_bottle(hash, bottle_tag)
|
sig { params(name: String).returns(T::Boolean) }
|
||||||
|
def available?(name)
|
||||||
|
fetch name
|
||||||
|
true
|
||||||
|
rescue ArgumentError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
hash["dependencies"].each do |dep_hash|
|
sig { params(name: String).void }
|
||||||
existing_formula = begin
|
def fetch_bottles(name)
|
||||||
Formulary.factory dep_hash["name"]
|
hash = fetch(name)
|
||||||
rescue FormulaUnavailableError
|
bottle_tag = Utils::Bottles.tag.to_s
|
||||||
# The formula might not exist if it's not installed and homebrew/core isn't tapped
|
|
||||||
nil
|
if !hash["bottles"].key?(bottle_tag) && !hash["bottles"].key?("all")
|
||||||
|
odie "No bottle available for #{name} on the current OS"
|
||||||
end
|
end
|
||||||
|
|
||||||
next if existing_formula.present? && existing_formula.latest_version_installed?
|
download_bottle(hash, bottle_tag)
|
||||||
|
|
||||||
download_bottle(dep_hash, bottle_tag)
|
hash["dependencies"].each do |dep_hash|
|
||||||
|
existing_formula = begin
|
||||||
|
Formulary.factory dep_hash["name"]
|
||||||
|
rescue FormulaUnavailableError
|
||||||
|
# The formula might not exist if it's not installed and homebrew/core isn't tapped
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
next if existing_formula.present? && existing_formula.latest_version_installed?
|
||||||
|
|
||||||
|
download_bottle(dep_hash, bottle_tag)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(url: String).returns(T.nilable(String)) }
|
sig { params(url: String).returns(T.nilable(String)) }
|
||||||
def checksum_from_url(url)
|
def checksum_from_url(url)
|
||||||
match = url.match GITHUB_PACKAGES_SHA256_REGEX
|
match = url.match GITHUB_PACKAGES_SHA256_REGEX
|
||||||
return if match.blank?
|
return if match.blank?
|
||||||
|
|
||||||
match[:sha256]
|
match[:sha256]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(hash: Hash, tag: Symbol).void }
|
sig { params(hash: Hash, tag: String).void }
|
||||||
def download_bottle(hash, tag)
|
def download_bottle(hash, tag)
|
||||||
bottle = hash["bottles"][tag]
|
bottle = hash["bottles"][tag]
|
||||||
bottle ||= hash["bottles"]["all"]
|
bottle ||= hash["bottles"]["all"]
|
||||||
return if bottle.blank?
|
return if bottle.blank?
|
||||||
|
|
||||||
sha256 = bottle["sha256"] || checksum_from_url(bottle["url"])
|
sha256 = bottle["sha256"] || checksum_from_url(bottle["url"])
|
||||||
bottle_filename = ::Bottle::Filename.new(hash["name"], hash["pkg_version"], tag, hash["rebuild"])
|
bottle_filename = ::Bottle::Filename.new(hash["name"], hash["pkg_version"], tag, hash["rebuild"])
|
||||||
|
|
||||||
resource = Resource.new hash["name"]
|
resource = Resource.new hash["name"]
|
||||||
resource.url bottle["url"]
|
resource.url bottle["url"]
|
||||||
resource.sha256 sha256
|
resource.sha256 sha256
|
||||||
resource.version hash["pkg_version"]
|
resource.version hash["pkg_version"]
|
||||||
resource.downloader.resolved_basename = bottle_filename
|
resource.downloader.resolved_basename = bottle_filename
|
||||||
|
|
||||||
resource.fetch
|
resource.fetch
|
||||||
|
|
||||||
# Map the name of this formula to the local bottle path to allow the
|
# Map the name of this formula to the local bottle path to allow the
|
||||||
# formula to be loaded by passing just the name to `Formulary::factory`.
|
# formula to be loaded by passing just the name to `Formulary::factory`.
|
||||||
Formulary.map_formula_name_to_local_bottle_path hash["name"], resource.downloader.cached_location
|
Formulary.map_formula_name_to_local_bottle_path hash["name"], resource.downloader.cached_location
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,13 +7,13 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Cask
|
module Cask
|
||||||
extend T::Sig
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
sig { params(name: String).returns(Hash) }
|
||||||
|
def fetch(name)
|
||||||
sig { params(name: String).returns(Hash) }
|
Homebrew::API.fetch "cask/#{name}.json"
|
||||||
def fetch(name)
|
end
|
||||||
Homebrew::API.fetch "cask/#{name}.json"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,19 +7,19 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Formula
|
module Formula
|
||||||
extend T::Sig
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
sig { returns(String) }
|
||||||
|
def formula_api_path
|
||||||
|
"formula"
|
||||||
|
end
|
||||||
|
alias generic_formula_api_path formula_api_path
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { params(name: String).returns(Hash) }
|
||||||
def formula_api_path
|
def fetch(name)
|
||||||
"formula"
|
Homebrew::API.fetch "#{formula_api_path}/#{name}.json"
|
||||||
end
|
end
|
||||||
alias generic_formula_api_path formula_api_path
|
|
||||||
|
|
||||||
sig { params(name: String).returns(Hash) }
|
|
||||||
def fetch(name)
|
|
||||||
Homebrew::API.fetch "#{formula_api_path}/#{name}.json"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,45 +7,45 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Versions
|
module Versions
|
||||||
extend T::Sig
|
class << self
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
def formulae
|
||||||
|
# The result is cached by Homebrew::API.fetch
|
||||||
def formulae
|
Homebrew::API.fetch "versions-formulae.json"
|
||||||
# The result is cached by Homebrew::API.fetch
|
|
||||||
Homebrew::API.fetch "versions-formulae.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
def linux
|
|
||||||
# The result is cached by Homebrew::API.fetch
|
|
||||||
Homebrew::API.fetch "versions-linux.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
def casks
|
|
||||||
# The result is cached by Homebrew::API.fetch
|
|
||||||
Homebrew::API.fetch "versions-casks.json"
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { params(name: String).returns(T.nilable(PkgVersion)) }
|
|
||||||
def latest_formula_version(name)
|
|
||||||
versions = if OS.mac? || Homebrew::EnvConfig.force_homebrew_on_linux?
|
|
||||||
formulae
|
|
||||||
else
|
|
||||||
linux
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless versions.key? name
|
def linux
|
||||||
|
# The result is cached by Homebrew::API.fetch
|
||||||
|
Homebrew::API.fetch "versions-linux.json"
|
||||||
|
end
|
||||||
|
|
||||||
version = Version.new(versions[name]["version"])
|
def casks
|
||||||
revision = versions[name]["revision"]
|
# The result is cached by Homebrew::API.fetch
|
||||||
PkgVersion.new(version, revision)
|
Homebrew::API.fetch "versions-casks.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(token: String).returns(T.nilable(Version)) }
|
sig { params(name: String).returns(T.nilable(PkgVersion)) }
|
||||||
def latest_cask_version(token)
|
def latest_formula_version(name)
|
||||||
return unless casks.key? token
|
versions = if OS.mac? || Homebrew::EnvConfig.force_homebrew_on_linux?
|
||||||
|
formulae
|
||||||
|
else
|
||||||
|
linux
|
||||||
|
end
|
||||||
|
|
||||||
Version.new(casks[token]["version"])
|
return unless versions.key? name
|
||||||
|
|
||||||
|
version = Version.new(versions[name]["version"])
|
||||||
|
revision = versions[name]["revision"]
|
||||||
|
PkgVersion.new(version, revision)
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { params(token: String).returns(T.nilable(Version)) }
|
||||||
|
def latest_cask_version(token)
|
||||||
|
return unless casks.key? token
|
||||||
|
|
||||||
|
Version.new(casks[token]["version"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -190,7 +190,7 @@ module Utils
|
|||||||
def formula_output(f, args:)
|
def formula_output(f, args:)
|
||||||
return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
|
return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
|
||||||
|
|
||||||
json = Homebrew::API::Formula.fetch f
|
json = Homebrew::API::Formula.fetch f.name
|
||||||
return if json.blank? || json["analytics"].blank?
|
return if json.blank? || json["analytics"].blank?
|
||||||
|
|
||||||
get_analytics(json, args: args)
|
get_analytics(json, args: args)
|
||||||
@ -202,7 +202,7 @@ module Utils
|
|||||||
def cask_output(cask, args:)
|
def cask_output(cask, args:)
|
||||||
return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
|
return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
|
||||||
|
|
||||||
json = Homebrew::API::Cask.fetch cask
|
json = Homebrew::API::Cask.fetch cask.token
|
||||||
return if json.blank? || json["analytics"].blank?
|
return if json.blank? || json["analytics"].blank?
|
||||||
|
|
||||||
get_analytics(json, args: args)
|
get_analytics(json, args: args)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user