bump-cask-pr: edit fetch_resource to reduce code duplication

`fetch_resource` now returns a SHA-256 string instead of file path
This commit is contained in:
Seeker 2021-02-24 03:23:15 -08:00
parent f65f0f9245
commit 6aa4145e3c
No known key found for this signature in database
GPG Key ID: DAC8CD3021038C62

View File

@ -126,14 +126,11 @@ module Homebrew
tmp_url = tmp_cask.url.to_s tmp_url = tmp_cask.url.to_s
if old_hash != :no_check if old_hash != :no_check
if new_hash.nil? new_hash = fetch_resource(cask, new_version, tmp_url) if new_hash.nil?
resource_path = fetch_resource(cask, new_version, tmp_url)
Utils::Tar.validate_file(resource_path)
new_hash = resource_path.sha256
end
if tmp_contents.include?("Hardware::CPU.intel?") if tmp_contents.include?("Hardware::CPU.intel?")
other_contents = tmp_contents.gsub("Hardware::CPU.intel?", (!Hardware::CPU.intel?).to_s) other_intel = !Hardware::CPU.intel?
other_contents = tmp_contents.gsub("Hardware::CPU.intel?", other_intel.to_s)
replacement_pairs << fetch_cask(other_contents, new_version) replacement_pairs << fetch_cask(other_contents, new_version)
end end
end end
@ -186,7 +183,10 @@ module Homebrew
resource.url(url, specs) resource.url(url, specs)
resource.owner = Resource.new(cask.token) resource.owner = Resource.new(cask.token)
resource.version = version resource.version = version
resource.fetch
resource_path = resource.fetch
Utils::Tar.validate_file(resource_path)
resource_path.sha256
end end
def fetch_cask(contents, version, config: nil) def fetch_cask(contents, version, config: nil)
@ -194,11 +194,7 @@ module Homebrew
cask.config = config if config.present? cask.config = config if config.present?
url = cask.url.to_s url = cask.url.to_s
old_hash = cask.sha256.to_s old_hash = cask.sha256.to_s
new_hash = fetch_resource(cask, version, url)
resource_path = fetch_resource(cask, version, url)
Utils::Tar.validate_file(resource_path)
new_hash = resource_path.sha256
[old_hash, new_hash] [old_hash, new_hash]
end end