tap: Add helper to generate core formula API hash
This abstracts away this helper to make it easier to test and reason about.
This commit is contained in:
parent
670e2188d7
commit
cefd3273cc
@ -58,14 +58,6 @@ module Homebrew
|
||||
Formulary.enable_factory_cache!
|
||||
Formula.generating_hash!
|
||||
|
||||
homebrew_core_tap_hash = {
|
||||
"tap_git_head" => tap.git_head,
|
||||
"aliases" => tap.alias_table,
|
||||
"renames" => tap.formula_renames,
|
||||
"tap_migrations" => tap.tap_migrations,
|
||||
"formulae" => {},
|
||||
}
|
||||
|
||||
tap.formula_names.each do |name|
|
||||
formula = Formulary.factory(name)
|
||||
name = formula.name
|
||||
@ -77,15 +69,12 @@ module Homebrew
|
||||
File.write("api/formula/#{name}.json", FORMULA_JSON_TEMPLATE)
|
||||
File.write("formula/#{name}.html", html_template_name)
|
||||
end
|
||||
|
||||
homebrew_core_tap_hash["formulae"][formula.name] =
|
||||
formula.to_hash_with_variations(hash_method: :to_api_hash)
|
||||
rescue
|
||||
onoe "Error while generating data for formula '#{name}'."
|
||||
raise
|
||||
end
|
||||
|
||||
homebrew_core_tap_json = JSON.generate(homebrew_core_tap_hash)
|
||||
homebrew_core_tap_json = JSON.generate(tap.to_api_hash)
|
||||
File.write("api/internal/v3/homebrew-core.json", homebrew_core_tap_json) unless args.dry_run?
|
||||
canonical_json = JSON.pretty_generate(tap.formula_renames.merge(tap.alias_table))
|
||||
File.write("_data/formula_canonical.json", "#{canonical_json}\n") unless args.dry_run?
|
||||
|
@ -1190,6 +1190,23 @@ class CoreTap < AbstractCoreTap
|
||||
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length
|
||||
end
|
||||
end
|
||||
|
||||
sig { returns(T::Hash[String, T.untyped]) }
|
||||
def to_api_hash
|
||||
formulae_api_hash = formula_names.to_h do |name|
|
||||
formula = Formulary.factory(name)
|
||||
formula_hash = formula.to_hash_with_variations(hash_method: :to_api_hash)
|
||||
[name, formula_hash]
|
||||
end
|
||||
|
||||
{
|
||||
"tap_git_head" => git_head,
|
||||
"aliases" => alias_table,
|
||||
"renames" => formula_renames,
|
||||
"tap_migrations" => tap_migrations,
|
||||
"formulae" => formulae_api_hash,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# A specialized {Tap} class for homebrew-cask.
|
||||
|
Loading…
x
Reference in New Issue
Block a user