forked from docs/doc-exports
53 lines
1.4 KiB
Python
Executable File
53 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Generate PR comment from violations."""
|
|
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)
|
|
|
|
# Group violations by file
|
|
by_file = {}
|
|
for v in violations:
|
|
key = v['file']
|
|
if key not in by_file:
|
|
by_file[key] = []
|
|
by_file[key].append(v)
|
|
|
|
# Build message
|
|
lines = [
|
|
"❌ **Underscore check failed**",
|
|
"",
|
|
"Found words ending with underscore (not followed by alphanumeric characters):",
|
|
""
|
|
]
|
|
|
|
for filepath, file_violations in by_file.items():
|
|
lines.append(f"**{filepath}:**")
|
|
for v in file_violations:
|
|
word = v['word']
|
|
line_num = v['line']
|
|
context = v['context']
|
|
# Escape markdown special chars in context
|
|
context = context.replace('`', '\\`')
|
|
lines.append(f" - Line {line_num}: `{word}` in context: `{context}`")
|
|
lines.append("")
|
|
|
|
lines.append("**Please fix these issues as soon as possible.** Words should not end with an underscore unless followed by alphanumeric characters (A-Za-z0-9).")
|
|
|
|
message = "\n".join(lines)
|
|
print(json.dumps({'body': message}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|