Merge pull request #14814 from Rylan12/fix-from-content-tap-loading

Set tap for casks when loading from contents via API
This commit is contained in:
Rylan Polster 2023-02-26 16:58:21 -05:00 committed by GitHub
commit 06cf85ffd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ module Cask
# Loads a cask from a string. # Loads a cask from a string.
class FromContentLoader class FromContentLoader
attr_reader :content attr_reader :content, :tap
def self.can_load?(ref) def self.can_load?(ref)
return false unless ref.respond_to?(:to_str) return false unless ref.respond_to?(:to_str)
@ -32,8 +32,9 @@ module Cask
content.match?(@regex) content.match?(@regex)
end end
def initialize(content) def initialize(content, tap: nil)
@content = content.force_encoding("UTF-8") @content = content.force_encoding("UTF-8")
@tap = tap
end end
def load(config:) def load(config:)
@ -48,7 +49,8 @@ module Cask
checksum = { checksum = {
"sha256" => Digest::SHA256.hexdigest(content), "sha256" => Digest::SHA256.hexdigest(content),
} }
Cask.new(header_token, source: content, source_checksum: checksum, **options, config: @config, &block) Cask.new(header_token, source: content, source_checksum: checksum, tap: tap, **options,
config: @config, &block)
end end
end end
@ -234,6 +236,7 @@ module Cask
cask_source = JSON.pretty_generate(json_cask) cask_source = JSON.pretty_generate(json_cask)
json_cask = Homebrew::API.merge_variations(json_cask).deep_symbolize_keys json_cask = Homebrew::API.merge_variations(json_cask).deep_symbolize_keys
tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")
# Use the cask-source API if there are any `*flight` blocks or the cask has multiple languages # Use the cask-source API if there are any `*flight` blocks or the cask has multiple languages
if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) } || if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) } ||
@ -241,11 +244,9 @@ module Cask
cask_source = Homebrew::API::Cask.fetch_source(token, cask_source = Homebrew::API::Cask.fetch_source(token,
git_head: json_cask[:tap_git_head], git_head: json_cask[:tap_git_head],
sha256: json_cask.dig(:ruby_source_checksum, :sha256)) sha256: json_cask.dig(:ruby_source_checksum, :sha256))
return FromContentLoader.new(cask_source).load(config: config) return FromContentLoader.new(cask_source, tap: tap).load(config: config)
end end
tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")
user_agent = json_cask.dig(:url_specs, :user_agent) user_agent = json_cask.dig(:url_specs, :user_agent)
json_cask[:url_specs][:user_agent] = user_agent[1..].to_sym if user_agent && user_agent[0] == ":" json_cask[:url_specs][:user_agent] = user_agent[1..].to_sym if user_agent && user_agent[0] == ":"
if (using = json_cask.dig(:url_specs, :using)) if (using = json_cask.dig(:url_specs, :using))