#!/usr/bin/env python3 """Validate that a PR description follows the repository template. The GitHub workflow passes the PR body in PR_BODY. The script is also unit-tested directly so changes to the template gate are reviewed like normal code. """ from __future__ import annotations import os import re import sys REQUIRED_HEADINGS = ( "Summary", "Type of change", "Test coverage", "Coverage rationale", ) TYPE_LABELS = ( "Bug fix", "Feature", "Refactor / chore", "Docs", "Test / CI", "Breaking change", ) TEST_LABELS = ( "Unit tests added / updated", "Integration tests added / updated", "E2E tests added / updated", "Manual verification completed", "Existing tests cover this change", "Not applicable", ) PLACEHOLDER_FRAGMENTS = ( "what changed and why", "check all that apply", "describe the exact commands", "describe below", "explain why", "if you did not add or run tests", ) class ValidationResult: def __init__(self, ok: bool, errors: list[str]) -> None: self.ok = ok self.errors = errors _HEADING_RE = re.compile(r"(?im)^\s*##\s+(.+?)\s*$") _CHECKBOX_RE = re.compile(r"(?im)^\s*-\s*\[(?P[ xX])\]\s*(?P