Skip to content

Commit 77c2404

Browse files
authored
Merge pull request #67 from RNA4219/codex/add-validation-for-pr-body-requirements
Enforce PR body requirements in governance gate
2 parents 1225081 + 195df94 commit 77c2404

File tree

2 files changed

+69
-20
lines changed

2 files changed

+69
-20
lines changed

tests/test_check_governance_gate.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tools.ci.check_governance_gate import (
99
find_forbidden_matches,
1010
load_forbidden_patterns,
11-
validate_priority_score,
11+
validate_pr_body,
1212
)
1313

1414

@@ -29,22 +29,49 @@ def test_find_forbidden_matches(changed_paths, patterns, expected):
2929
assert find_forbidden_matches(changed_paths, normalized) == expected
3030

3131

32-
@pytest.mark.parametrize(
33-
"body",
34-
[
35-
"Priority Score: 5 / 安全性強化",
36-
"Priority Score: 1 / 即応性向上",
37-
"Priority Score: 3",
38-
"Priority Score: / 理由",
39-
"Priority Score: abc / 理由",
40-
"Priority Score: <!-- 例: 5 / prioritization.yaml#phase1 -->",
41-
"priority score: 3",
42-
"",
43-
None,
44-
],
45-
)
46-
def test_validate_priority_score_is_now_noop(body):
47-
assert validate_priority_score(body) is True
32+
def test_validate_pr_body_success(capsys):
33+
body = """
34+
Intent: INT-123
35+
## EVALUATION
36+
Priority Score: 4.5 / 安全性強化
37+
"""
38+
39+
assert validate_pr_body(body) is True
40+
captured = capsys.readouterr()
41+
assert captured.err == ""
42+
43+
44+
def test_validate_pr_body_missing_intent(capsys):
45+
body = """
46+
## EVALUATION
47+
Priority Score: 2
48+
"""
49+
50+
assert validate_pr_body(body) is False
51+
captured = capsys.readouterr()
52+
assert "PR body must include 'Intent: INT-xxx'" in captured.err
53+
54+
55+
def test_validate_pr_body_missing_evaluation(capsys):
56+
body = """
57+
Intent: INT-001
58+
Priority Score: 3
59+
"""
60+
61+
assert validate_pr_body(body) is False
62+
captured = capsys.readouterr()
63+
assert "PR must reference EVALUATION" in captured.err
64+
65+
66+
def test_validate_pr_body_warns_without_priority_score(capsys):
67+
body = """
68+
Intent: INT-789
69+
## EVALUATION
70+
"""
71+
72+
assert validate_pr_body(body) is True
73+
captured = capsys.readouterr()
74+
assert "Consider adding 'Priority Score: <number>'" in captured.err
4875

4976

5077
def test_load_forbidden_patterns(tmp_path):

tools/ci/check_governance_gate.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import re
56
import subprocess
67
import sys
78
from fnmatch import fnmatch
@@ -85,8 +86,28 @@ def read_event_body(event_path: Path) -> str | None:
8586
return body
8687

8788

88-
def validate_priority_score(body: str | None) -> bool:
89-
return True
89+
INTENT_PATTERN = re.compile(r"Intent:\s*INT-\d+", re.IGNORECASE)
90+
EVALUATION_PATTERN = re.compile(r"EVALUATION", re.IGNORECASE)
91+
PRIORITY_PATTERN = re.compile(r"Priority\s*Score\s*:\s*\d+(?:\.\d+)?", re.IGNORECASE)
92+
93+
94+
def validate_pr_body(body: str | None) -> bool:
95+
normalized_body = body or ""
96+
success = True
97+
98+
if not INTENT_PATTERN.search(normalized_body):
99+
print("PR body must include 'Intent: INT-xxx'", file=sys.stderr)
100+
success = False
101+
if not EVALUATION_PATTERN.search(normalized_body):
102+
print("PR must reference EVALUATION (acceptance) anchor", file=sys.stderr)
103+
success = False
104+
if not PRIORITY_PATTERN.search(normalized_body):
105+
print(
106+
"Consider adding 'Priority Score: <number>' based on prioritization.yaml",
107+
file=sys.stderr,
108+
)
109+
110+
return success
90111

91112

92113
def main() -> int:
@@ -112,7 +133,8 @@ def main() -> int:
112133
print("GITHUB_EVENT_PATH is not set", file=sys.stderr)
113134
return 1
114135
body = read_event_body(Path(event_path_value))
115-
validate_priority_score(body)
136+
if not validate_pr_body(body):
137+
return 1
116138

117139
return 0
118140

0 commit comments

Comments
 (0)