GHCR: Use reject to remove empty hash values

This commit is contained in:
Shaun Jackman 2021-04-05 10:08:03 -07:00
parent 6e7857cc4e
commit 2852d9f0de
No known key found for this signature in database
GPG Key ID: D4ED5223F4E57996

View File

@ -206,8 +206,7 @@ class GitHubPackages
"org.opencontainers.image.url" => bottle_hash["formula"]["homepage"], "org.opencontainers.image.url" => bottle_hash["formula"]["homepage"],
"org.opencontainers.image.vendor" => org, "org.opencontainers.image.vendor" => org,
"org.opencontainers.image.version" => version, "org.opencontainers.image.version" => version,
} }.reject { |_, v| v.blank? }
delete_blank_hash_values(formula_annotations_hash)
manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash| manifests = bottle_hash["bottle"]["tags"].map do |bottle_tag, tag_hash|
local_file = tag_hash["local_filename"] local_file = tag_hash["local_filename"]
@ -248,8 +247,7 @@ class GitHubPackages
architecture: architecture, architecture: architecture,
os: os, os: os,
"os.version" => os_version, "os.version" => os_version,
} }.reject { |_, v| v.blank? }
delete_blank_hash_values(platform_hash)
tar_sha256 = Digest::SHA256.hexdigest( tar_sha256 = Digest::SHA256.hexdigest(
Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file), Utils.safe_popen_read("gunzip", "--stdout", "--decompress", local_file),
@ -268,8 +266,7 @@ class GitHubPackages
"sh.brew.bottle.digest" => tar_gz_sha256, "sh.brew.bottle.digest" => tar_gz_sha256,
"sh.brew.bottle.glibc.version" => glibc_version, "sh.brew.bottle.glibc.version" => glibc_version,
"sh.brew.tab" => tab.to_json, "sh.brew.tab" => tab.to_json,
} }.reject { |_, v| v.blank? }
delete_blank_hash_values(descriptor_annotations_hash)
annotations_hash = formula_annotations_hash.merge(descriptor_annotations_hash).merge( annotations_hash = formula_annotations_hash.merge(descriptor_annotations_hash).merge(
{ {
@ -277,8 +274,7 @@ class GitHubPackages
"org.opencontainers.image.documentation" => documentation, "org.opencontainers.image.documentation" => documentation,
"org.opencontainers.image.title" => "#{formula_full_name} #{tag}", "org.opencontainers.image.title" => "#{formula_full_name} #{tag}",
}, },
).sort.to_h ).reject { |_, v| v.blank? }.sort.to_h
delete_blank_hash_values(annotations_hash)
image_manifest = { image_manifest = {
schemaVersion: 2, schemaVersion: 2,
@ -386,10 +382,4 @@ class GitHubPackages
[sha256, json.size] [sha256, json.size]
end end
def delete_blank_hash_values(hash)
hash.each do |key, value|
hash.delete(key) if value.blank?
end
end
end end