Skip to content

Commit

Permalink
tap_auditor: validate pypi_formula_mappings.json
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Cho <[email protected]>
  • Loading branch information
cho-m committed Mar 5, 2024
1 parent cf7c093 commit 254c900
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Library/Homebrew/Gemfile
Expand Up @@ -30,9 +30,6 @@ end
group :man, optional: true do
gem "ronn", require: false
end
group :pr_upload, optional: true do
gem "json_schemer", require: false
end
group :prof, optional: true do
gem "ruby-prof", require: false
gem "stackprof", require: false
Expand Down Expand Up @@ -71,6 +68,9 @@ end
group :audit, :bump_unversioned_casks, :livecheck, optional: true do
gem "rexml", require: false
end
group :audit, :pr_upload, optional: true do
gem "json_schemer", require: false
end

# vendored gems (no group)
gem "addressable"
Expand Down
25 changes: 25 additions & 0 deletions Library/Homebrew/data/schemas/pypi_formula_mappings.schema.json
@@ -0,0 +1,25 @@
{
"type": "object",
"additionalProperties": {
"type": ["string", "object"],
"properties": {
"package_name": {"type": "string"},
"exclude_packages": {
"type": "array",
"items": {"type": "string"},
"minItems": 1
},
"extra_packages": {
"type": "array",
"items": {"type": "string"},
"minItems": 1
},
"dependencies": {
"type": "array",
"items": {"type": "string"},
"minItems": 1
}
},
"additionalProperties": false
}
}
16 changes: 16 additions & 0 deletions Library/Homebrew/tap_auditor.rb
Expand Up @@ -45,13 +45,29 @@ def audit_json_files
rescue JSON::ParserError
problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON"
end

require "json_schemer"
schemer = JSONSchemer.schema(HOMEBREW_DATA_PATH/"schemas/pypi_formula_mappings.schema.json")

Check warning on line 50 in Library/Homebrew/tap_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap_auditor.rb#L49-L50

Added lines #L49 - L50 were not covered by tests
return if schemer.valid?(@tap_pypi_formula_mappings)

problem <<~EOS

Check warning on line 53 in Library/Homebrew/tap_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap_auditor.rb#L53

Added line #L53 was not covered by tests
pypi_formula_mappings.json schema validation failed with following errors:
#{schemer.validate(@tap_pypi_formula_mappings).map { |error| "* #{error["error"]}" }.join("\n")}
EOS
end

sig { void }
def audit_tap_formula_lists
check_formula_list_directory "audit_exceptions", @tap_audit_exceptions
check_formula_list_directory "style_exceptions", @tap_style_exceptions
check_formula_list "pypi_formula_mappings", @tap_pypi_formula_mappings

@tap_pypi_formula_mappings.each_value do |formula_mapping|

Check warning on line 65 in Library/Homebrew/tap_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap_auditor.rb#L65

Added line #L65 was not covered by tests
next unless formula_mapping.is_a?(Hash)
next unless formula_mapping.key?("dependencies")

check_formula_list "pypi_formula_mappings", formula_mapping["dependencies"]

Check warning on line 69 in Library/Homebrew/tap_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap_auditor.rb#L69

Added line #L69 was not covered by tests
end
end

sig { void }
Expand Down

0 comments on commit 254c900

Please sign in to comment.