Remove CaskSource API

This commit is contained in:
Rylan Polster 2023-01-28 02:15:00 -06:00
parent fd18c7b0ac
commit 32a0877cad
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
4 changed files with 15 additions and 39 deletions

View File

@ -3,7 +3,6 @@
require "api/analytics"
require "api/cask"
require "api/cask-source"
require "api/formula"
require "api/versions"
require "extend/cachable"
@ -57,12 +56,13 @@ module Homebrew
end
sig { params(token: String, git_head: T.nilable(String)).returns(String) }
def fetch_source(token, git_head: nil)
def fetch_file_source(filepath, repo:, git_head: nil)
git_head ||= "master"
endpoint = "#{git_head}/Casks/#{token}.rb"
endpoint = "#{git_head}/#{filepath}"
return cache[endpoint] if cache.present? && cache.key?(endpoint)
raw_url = "https://raw.githubusercontent.com/Homebrew/homebrew-cask/#{endpoint}"
raw_url = "https://raw.githubusercontent.com/#{repo}/#{endpoint}"
puts "Fetching #{raw_url}..."
output = Utils::Curl.curl_output("--fail", raw_url, max_time: 5)
raise ArgumentError, "No file found at #{Tty.underline}#{raw_url}#{Tty.reset}" unless output.success?

View File

@ -1,29 +0,0 @@
# typed: false
# frozen_string_literal: true
module Homebrew
module API
# Helper functions for using the cask source API.
#
# @api private
module CaskSource
class << self
extend T::Sig
sig { params(token: String, git_head: T.nilable(String)).returns(Hash) }
def fetch(token, git_head: nil)
token = token.sub(%r{^homebrew/cask/}, "")
Homebrew::API.fetch_source token, git_head: git_head
end
sig { params(token: String).returns(T::Boolean) }
def available?(token)
fetch token
true
rescue ArgumentError
false
end
end
end
end
end

View File

@ -10,9 +10,14 @@ module Homebrew
class << self
extend T::Sig
sig { params(name: String).returns(Hash) }
def fetch(name)
Homebrew::API.fetch "cask/#{name}.json"
sig { params(token: String).returns(Hash) }
def fetch(token)
Homebrew::API.fetch "cask/#{token}.json"
end
sig { params(token: String, git_head: T.nilable(String)).returns(String) }
def fetch_source(token, git_head: nil)
Homebrew::API.fetch_file_source "Casks/#{token}.rb", repo: "Homebrew/homebrew-cask", git_head: git_head
end
sig { returns(Hash) }

View File

@ -212,9 +212,9 @@ module Cask
json_cask.deep_symbolize_keys!
# Use the cask-source API if there are any `*flight` blocks
# Download and use the cask source file if there are any `*flight` blocks
if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) }
cask_source = Homebrew::API::CaskSource.fetch(token, git_head: json_cask[:tap_git_head])
cask_source = Homebrew::API::Cask.fetch_source(token, git_head: json_cask[:tap_git_head])
return FromContentLoader.new(cask_source).load(config: config)
end
@ -372,7 +372,7 @@ module Cask
return loader_class.new(ref)
end
if Homebrew::EnvConfig.install_from_api? && !need_path && Homebrew::API::CaskSource.available?(ref)
if Homebrew::EnvConfig.install_from_api? && !need_path && Homebrew::API::Cask.all_casks.key?(ref)
return FromAPILoader.new(ref)
end