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

Next gen api formula json v3 #16541

Merged
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion Library/Homebrew/dev-cmd/generate-formula-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def generate_formula_api
raise TapUnavailableError, tap.name unless tap.installed?

unless args.dry_run?
directories = ["_data/formula", "api/formula", "formula"]
directories = ["_data/formula", "api/formula", "formula", "api/internal/v3"]
FileUtils.rm_rf directories + ["_data/formula_canonical.json"]
FileUtils.mkdir_p directories
end
Expand All @@ -58,6 +58,14 @@ def generate_formula_api
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
Expand All @@ -69,11 +77,16 @@ def generate_formula_api
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
formula.to_hash_with_variations(hash_method: :to_api_hash)
formula.to_hash_with_variations(hash_method: :to_api_internal_v3_hash)

or similar? may also be worth renaming the existing one, too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt we'll run into a situation where we have more than 2 hash types we're generating with this method and if we do run into that problem, we can change the names then.

rescue
onoe "Error while generating data for formula '#{name}'."
raise
end

homebrew_core_tap_json = JSON.generate(homebrew_core_tap_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?
end
Expand Down