Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__pycache__

.cline_storage
/projects/hip/_build

Expand Down
12 changes: 11 additions & 1 deletion tools/systems_pr_bot/policy_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,23 @@ def ensure_pr_not_draft(policy: Policy, is_draft: bool, errors: List[str]) -> No
)


def _strip_markdown_comments(text: str) -> str:
"""Remove HTML comment blocks from Markdown text."""
# Note: using re.DOTALL to match _any_ character, including newlines so this
# can handle multiline comments.
return re.sub(r"<!--.*?(?:-->|$)", "", text, flags=re.DOTALL)


def ensure_pr_description(policy: Policy, body: str, errors: List[str]) -> None:
"""Validate the PR description (minimum length, JIRA/ISSUE reference, checklist).

Appends a structured message to `errors` if the body is too short, does
not contain a recognised tracking reference, or has an unticked checklist item.
"""
body = (body or "").strip()
# Strip comments so we only check the visible text against the policies.
# This lets pull request templates use examples that _would_ pass the check.
body = _strip_markdown_comments(body or "").strip()

if policy.description_min_length and len(body) < policy.description_min_length:
errors.append(
f"**Error:** PR description is too short ({len(body)} characters).\n"
Expand Down
25 changes: 22 additions & 3 deletions tools/systems_pr_bot/test_policy_check_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def make_policy(**overrides: Any) -> pc.Policy:
description_checklist_patterns=[re.compile(p) for p in _CHECKLIST_PATTERNS],
block_draft=True,
forbidden_title_patterns=[re.compile(r"(?i)\bWIP\b")],
max_files_changed=50,
max_total_changes=2000,
max_single_file_changes=700,
forbidden_paths=["**/*.pem", "**/.env", "**/id_rsa"],
unit_test_code_extensions=[".py", ".cpp"],
unit_test_patterns=[
Expand Down Expand Up @@ -196,6 +193,28 @@ def test_missing_issue_reference(self) -> None:
pc.ensure_pr_description(policy, "A long enough description with no ref.", e)
self.assertTrue(any("must reference a JIRA ID" in x for x in e))

def test_issue_reference_in_comment_does_not_pass(self) -> None:
# Isolate reference detection (skip min-length and checklist).
policy = make_policy(
description_min_length=0, description_checklist_patterns=[]
)
multiline_comment = """<!--
Fixes #1234
-->"""
multiple_comments = """This description has no visible issue reference.
<!-- Related to #1234 -->
Some visible text between the comments.
<!-- https://github.com/ROCm/TheRock/issues/5678 -->"""
for body in [
"<!-- GitHub issue: https://github.com/ROCm/TheRock/issues/1234 -->",
multiline_comment,
multiple_comments,
]:
with self.subTest(body=body):
e: List[str] = []
pc.ensure_pr_description(policy, body, e)
self.assertTrue(any("must reference a JIRA ID" in x for x in e))

def test_issue_reference_variants_pass(self) -> None:
# Isolate reference detection (skip min-length and checklist).
policy = make_policy(
Expand Down
Loading