Skip to content

Commit

Permalink
Merge pull request #14814 from Rylan12/fix-from-content-tap-loading
Browse files Browse the repository at this point in the history
Set tap for casks when loading from contents via API
  • Loading branch information
Rylan12 committed Feb 26, 2023
2 parents 09f4be8 + 29bb0ee commit 06cf85f
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit 06cf85f

Please sign in to comment.