forked from docs/doc-exports
64 lines
1.9 KiB
Python
Executable File
64 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Generate PR comment for metadata registration check violations.
|
|
|
|
This script reads violations.json (created by metadata-check.py) and generates
|
|
a formatted markdown comment to be posted on the PR. The comment includes:
|
|
- HTML file path that was added but not registered
|
|
- Which metadata files it's missing from (CLASS.TXT.json, ALL_META.TXT.json)
|
|
- Whether the metadata files don't exist or the file is simply missing from them
|
|
|
|
Usage:
|
|
Run after metadata-check.py fails. Reads violations.json and outputs JSON
|
|
with 'body' field containing the markdown comment text.
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
|
|
|
|
def main():
|
|
try:
|
|
with open("violations.json", "r") as f:
|
|
violations = json.load(f)
|
|
except Exception:
|
|
violations = []
|
|
|
|
if not violations:
|
|
print(json.dumps({"body": "No violations to report"}))
|
|
sys.exit(0)
|
|
|
|
# Build message
|
|
lines = [
|
|
"❌ **HTML file not registered in metadata**",
|
|
"",
|
|
"The following HTML files were added but are not properly registered in the metadata files:",
|
|
"",
|
|
]
|
|
|
|
for v in violations:
|
|
html_file = v["file"]
|
|
missing_from = v["missing_from"]
|
|
|
|
lines.append(f"**{html_file}**")
|
|
for missing in missing_from:
|
|
# Check if it's a "file not found" case
|
|
if "(file not found)" in missing:
|
|
lines.append(
|
|
f" ❌ Missing from: `{missing.split(' (')[0]}` (metadata file does not exist)"
|
|
)
|
|
else:
|
|
lines.append(f" ❌ Missing from: `{missing}`")
|
|
lines.append("")
|
|
|
|
lines.append(
|
|
"**Please add the new HTML files to both `CLASS.TXT.json` and `ALL_META.TXT.json` in the same directory.**"
|
|
)
|
|
|
|
message = "\n".join(lines)
|
|
print(json.dumps({"body": message}))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|