From 32a0877cad27ec49cf08b26c1bc53349cf4d63f6 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sat, 28 Jan 2023 02:15:00 -0600 Subject: [PATCH] Remove `CaskSource` API --- Library/Homebrew/api.rb | 8 ++++---- Library/Homebrew/api/cask-source.rb | 29 ---------------------------- Library/Homebrew/api/cask.rb | 11 ++++++++--- Library/Homebrew/cask/cask_loader.rb | 6 +++--- 4 files changed, 15 insertions(+), 39 deletions(-) delete mode 100644 Library/Homebrew/api/cask-source.rb diff --git a/Library/Homebrew/api.rb b/Library/Homebrew/api.rb index fefdd421fe..b365bdd1f0 100644 --- a/Library/Homebrew/api.rb +++ b/Library/Homebrew/api.rb @@ -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? diff --git a/Library/Homebrew/api/cask-source.rb b/Library/Homebrew/api/cask-source.rb deleted file mode 100644 index e0c6296c3f..0000000000 --- a/Library/Homebrew/api/cask-source.rb +++ /dev/null @@ -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 diff --git a/Library/Homebrew/api/cask.rb b/Library/Homebrew/api/cask.rb index f0ed248cdf..4f7c4b8e36 100644 --- a/Library/Homebrew/api/cask.rb +++ b/Library/Homebrew/api/cask.rb @@ -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) } diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index ad60176eb7..79f494a3bc 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -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