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
28 changes: 27 additions & 1 deletion scripts/pr_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
import argparse, os, re, subprocess, sys

SECTIONS = ("Tested", "Not tested", "AI use")
HEADINGS = ("What is in it", "Tested", "Regression run", "Not tested", "AI use")
# placeholder lines copied verbatim from .github/pull_request_template.md (#965)
TEMPLATE_PLACEHOLDERS = frozenset({
"hardware (GPU + driver, CPU), Rust version, debug / release:",
"`cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: …)",
"`cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: ...)",
"none / tool and model, and what it did",
})
# small / open-weight models are not accepted for code (CONTRIBUTING.md, "AI-assisted contributions")
BANNED_MODELS = r"\b(qwen|deepseek|llama|mistral|mixtral|gemma|phi-?\d)"
# game data never goes into the repository (CONTRIBUTING.md, "Licence and provenance")
Expand Down Expand Up @@ -48,14 +56,32 @@ def runtime(path):
return path.startswith("crates/xcl/src/") and "/tests" not in path and not path.endswith("tests.rs")


def section_has_content(body, section):
"""True when `**section**` exists and has at least one non-placeholder line."""
next_heading = "|".join(re.escape(h) for h in HEADINGS)
m = re.search(
r"\*\*" + re.escape(section) + r"\*\*[ \t]*\n(.*?)(?=\n\*\*(?:" + next_heading + r")\*\*|\Z)",
body,
re.S,
)
if not m:
return False
text = re.sub(r"<!--.*?-->", "", m.group(1), flags=re.S)
for raw in text.splitlines():
line = re.sub(r"^\s*[-*•]+\s*", "", raw).strip()
if line and line not in TEMPLATE_PLACEHOLDERS:
return True
return False


def check(body, head, files, is_main_ancestor, *, test_only=False):
"""The problems (empty: mergeable as far as this check goes). `files`: (path, status, binary,
size) with `size` a function giving the file's bytes; `is_main_ancestor(sha)`: whether the
commit is on main."""
body = body.replace("\r\n", "\n")
problems = []
for section in SECTIONS:
if not re.search(r"\*\*" + section + r"\*\*\s*\n\s*\S", body):
if not section_has_content(body, section):
problems.append(f"the **{section}** section is missing or empty")

ai = re.search(r"\*\*AI use\*\*(.*?)(\n\*\*|\Z)", body, re.S)
Expand Down
34 changes: 34 additions & 0 deletions scripts/test_pr_check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import unittest

from pr_check import check, smoke_blocks
Expand Down Expand Up @@ -51,5 +52,38 @@ def test_blocks_in_separate_fences_stay_separate(self):
self.assertEqual(["1111111aaaa", "1234567890"], [b["commit"] for b in smoke_blocks(body)])


class TemplatePlaceholderTests(unittest.TestCase):
def test_untouched_pr_template_fails_all_required_sections(self):
template = Path(__file__).resolve().parent.parent / ".github" / "pull_request_template.md"
body = template.read_text(encoding="utf-8")
problems = check(body, HEAD, [changed("README.md")], lambda _: True)
self.assertEqual(
[
"the **Tested** section is missing or empty",
"the **Not tested** section is missing or empty",
"the **AI use** section is missing or empty",
],
problems,
)

def test_filled_template_with_comments_and_real_lines_passes(self):
body = (
"**Tested**\n"
"<!-- comment only does not count, real line below does -->\n"
"- hardware (GPU + driver, CPU), Rust version, debug / release: RTX 3070 Ti, Rust 1.88.0\n"
"- `cargo test --workspace -- --test-threads=4`: N passed, N failed, N ignored (SKIPPED GPU tests: …)\n"
"**Not tested**\n"
"- AMD GPUs\n"
"**AI use**\n"
"- none\n"
)
self.assertEqual([], check(body, HEAD, [changed("README.md")], lambda _: True))

def test_bare_bullets_and_html_comments_only_fail(self):
body = "**Tested**\n<!-- todo -->\n-\n**Not tested**\n*\n**AI use**\n - \n"
problems = check(body, HEAD, [changed("README.md")], lambda _: True)
self.assertEqual(3, len(problems))


if __name__ == "__main__":
unittest.main()
Loading