From fefc9ca16f43d9791a35cbbeb0127ace18df43c4 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:06:57 +0100 Subject: [PATCH] fix: refuse numbered review tags in commits A subject that points at a numbered private review names notes no clone holds, and pushed history cannot be rewritten. The hook now refuses those tags like the tracked-file test does. --- scripts/commit_rules.py | 10 ++++++++++ tests/test_autorun.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/scripts/commit_rules.py b/scripts/commit_rules.py index 1dc2bf6fa..356b3a871 100644 --- a/scripts/commit_rules.py +++ b/scripts/commit_rules.py @@ -21,6 +21,14 @@ REFUSED_WORDS = re.compile( r"comprehensive|implement)", re.IGNORECASE, ) +# A numbered pointer at a private review ("audit 24", "review 3", "round 5") +# names notes no clone holds. tests/test_prose_style.py refuses the same tags +# in tracked files, and history cannot be rewritten once pushed. +REVIEW_TAG = re.compile( + r"\b(audit|review|round|batch|finding)s? #?\d+|\baudit (batch|findings?)\b" + r"|[a-z]+_audit_\d+", + re.IGNORECASE, +) CO_AUTHOR = re.compile(r"^co-authored-by", re.IGNORECASE | re.MULTILINE) @@ -35,6 +43,8 @@ def problems(message: str) -> list[str]: text = "\n".join(line for line in message.splitlines() if not line.startswith("#")) if REFUSED_WORDS.search(text): found.append("the message uses a word this repository's history does not carry") + if REVIEW_TAG.search(text): + found.append("say what the change does, not which review asked for it") if CO_AUTHOR.search(message): found.append("no Co-Authored-By trailer here") return found diff --git a/tests/test_autorun.py b/tests/test_autorun.py index aa32b1d05..c8c04e0ad 100644 --- a/tests/test_autorun.py +++ b/tests/test_autorun.py @@ -955,6 +955,23 @@ class SubjectsFollowTheRepositoryRules(unittest.TestCase): self.assertTrue(ar.check_subject(subject)) self.assertEqual(ar.check_subject("chore: tidy the cache"), []) + def test_review_numbers_are_refused(self): + """47 pushed subjects pointed at a numbered private review, which no + clone can follow. The subject says what the change does.""" + import commit_rules # noqa: PLC0415 + + for subject in ("chore: audit 24 and 17 cases, host kept out", + "fix: polish the screens audit 11 named", + "chore: merge audit batch, resolver and profiles", + "fix: settle the review 3 notes"): + with self.subTest(subject=subject): + self.assertTrue(commit_rules.problems(subject)) + for subject in ("fix: scroll long messages in the installer", + "feat: read regions in region_audit.py", + "chore: merge resolver and profile fixes"): + with self.subTest(subject=subject): + self.assertEqual(commit_rules.problems(subject), []) + def test_the_rules_run_as_a_hook(self): with tempfile.TemporaryDirectory() as tmp: message = Path(tmp) / "MSG"