GRM-20: fix: enforce GRM-N: conventional on master commits and PR titles

This commit is contained in:
Emil Simeonov
2026-06-19 15:10:32 +02:00
parent 129cfe3c79
commit 3048d7ade7
4 changed files with 62 additions and 16 deletions
+18 -5
View File
@@ -2,8 +2,9 @@
"""Validate commit messages for GRM.
Rules:
- On master branch: allow anything (merge commits already have task ID).
- On feature branches: must use conventional commit format, must NOT include GRM-N prefix.
- On feature branches: conventional commits ONLY, must NOT include GRM-N prefix.
- On master branch: must follow '<task-id>: <conventional commit>' pattern,
e.g. 'GRM-24: fix: resolve timeout'.
"""
import re
import subprocess
@@ -41,11 +42,23 @@ def main(args=None) -> None:
branch = get_branch()
if branch == "master":
return
subject = first_line(msg)
if branch == "master":
if not TASK_ID_RE.match(subject):
print("ERROR: Master branch commits must start with a task ID.")
print(" Expected: GRM-N: <conventional commit message>")
print(f" Got: {subject}")
sys.exit(1)
# Strip task-id prefix and validate the remainder as conventional
remainder = TASK_ID_RE.sub("", subject).strip()
if not CONVENTIONAL_RE.match(remainder):
print("ERROR: Master branch commit message must follow conventional format after task ID.")
print(" Expected: GRM-N: <type>: <description>")
print(f" Got: {subject}")
sys.exit(1)
return
if TASK_ID_RE.match(subject):
print("ERROR: Do not include task ID (GRM-N) in feature branch commits.")
print(" Task ID will be added automatically on merge via CI.")