Files
mandy/tests/test_docs_pr_template.py
Mouad-Scriptz-0 4f7a347775 ci: label pull requests that conflict with main needs rebase (PR-CONFLICT-LABEL)
Every pull request is reviewed by hand, and with over a hundred open the
reviewer has no quick way to skip the ones that cannot merge as they
stand. tools/pr_conflict_label.py asks the GitHub API for each open pull
request's `mergeable` and labels the conflicting ones `needs rebase`,
removing the label once they merge cleanly again; an answer GitHub has
not computed yet is asked again a few times and otherwise left for the
next run. .github/workflows/conflict-label.yml runs it on a push to main
(all open pull requests), on a pull request being opened, reopened or
pushed to (that one), and hourly.

The job uses pull_request_target so a fork's pull request can be
labeled, and is safe with it: it checks out main, never the pull
request, and the tool reads only the API, so no pull request code runs.
Its token can read contents and write pull requests, nothing else;
tests/test_pr_conflict_label.py checks that, and the tool against a fake
API.

The pull request template also asks for `Fixes: #N` and `GPUs tested:`
lines and has checklist items for "based on current main" and "one
topic"; tests/test_docs_pr_template.py checks the new prompts, and
CONTRIBUTING.md gets a short Pull requests section. The process is
modelled on AnyPS5's (boykopovar/AnyPS5); the code is written here, not
copied.
2026-11-24 02:30:45 +00:00

39 lines
1.7 KiB
Python

"""The pull request template prompts for `Depends on:`, `Fixes:`, `GPUs tested:` and whether it was AI-assisted.
python -I tests/test_docs_pr_template.py
The coordination issue builds its merge chains from `Depends on: #N` lines, AGENTS.md asks a pull request to say
that it was AI-assisted, `Fixes: #N` closes the issue on merge and `GPUs tested:` is what a reviewer checks a GPU
change against. Without a prompt in `.github/pull_request_template.md` those are the lines authors leave out. This
reads the template only, so rewording AGENTS.md or CONTRIBUTING.md cannot fail it. No game files.
"""
import os
import re
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE = os.path.join(".github", "pull_request_template.md")
# A prompt is a line of its own that starts with the words an author fills in.
PROMPTS = ("Depends on:", "Fixes:", "GPUs tested:", "AI-assisted:")
def missing_prompts(template):
"""The prompts of PROMPTS that no line of `template` starts with."""
return [p for p in PROMPTS if not re.search("^" + re.escape(p), template, re.M)]
class PullRequestTemplateTest(unittest.TestCase):
def test_template_has_every_prompt(self):
with open(os.path.join(ROOT, TEMPLATE), encoding="utf-8") as f:
self.assertEqual(missing_prompts(f.read()), [])
def test_a_template_without_a_prompt_is_reported(self):
self.assertEqual(missing_prompts("### Tested\n"), list(PROMPTS))
# A mention inside another sentence is not a prompt: the line has to start with it.
self.assertEqual(missing_prompts("no Depends on: here\nFixes: none\nGPUs tested: n/a\nAI-assisted: no\n"),
["Depends on:"])
if __name__ == "__main__":
unittest.main()