Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set tap for casks when loading from contents via API #14814

Merged
merged 1 commit into from Feb 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions Library/Homebrew/cask/cask_loader.rb
Expand Up @@ -14,7 +14,7 @@ module CaskLoader

# Loads a cask from a string.
class FromContentLoader
attr_reader :content
attr_reader :content, :tap

def self.can_load?(ref)
return false unless ref.respond_to?(:to_str)
Expand All @@ -32,8 +32,9 @@ def self.can_load?(ref)
content.match?(@regex)
end

def initialize(content)
def initialize(content, tap: nil)
@content = content.force_encoding("UTF-8")
@tap = tap
end

def load(config:)
Expand All @@ -48,7 +49,8 @@ def cask(header_token, **options, &block)
checksum = {
"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

Expand Down Expand Up @@ -234,18 +236,17 @@ def load(config:)
cask_source = JSON.pretty_generate(json_cask)

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
if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) } ||
json_cask[:languages].any?
cask_source = Homebrew::API::Cask.fetch_source(token,
git_head: json_cask[:tap_git_head],
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

tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")

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] == ":"
if (using = json_cask.dig(:url_specs, :using))
Expand Down