Skip to content

Commit 2f4f705

Browse files
DEV: Ensure that the PR titles have the correct format (#2378)
1 parent ed0f29c commit 2f4f705

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

.github/scripts/check_pr_title.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Check that all PR titles follow the desired scheme.""" # noqa: INP001
2+
3+
import os
4+
import sys
5+
6+
KNOWN_PREFIXES = (
7+
"SEC: ",
8+
"BUG: ",
9+
"ENH: ",
10+
"DEP: ",
11+
"PI: ",
12+
"ROB: ",
13+
"DOC: ",
14+
"TST: ",
15+
"DEV: ",
16+
"STY: ",
17+
"MAINT: ",
18+
)
19+
PR_TITLE = os.getenv("PR_TITLE", "")
20+
21+
if not PR_TITLE.startswith(KNOWN_PREFIXES) or not PR_TITLE.split(": ", maxsplit=1)[1]:
22+
sys.stderr.write(
23+
f"The PR title '{PR_TITLE}' does not follow the projects naming scheme: "
24+
"https://pypdf.readthedocs.io/en/latest/dev/intro.html#commit-messages\n",
25+
)
26+
sys.stderr.write(
27+
"If you do not know which one to choose or if multiple apply, make a best guess. "
28+
"Nobody will complain if it does not quite fit :-)\n",
29+
)
30+
sys.exit(1)
31+
else:
32+
sys.stdout.write(f"PR title '{PR_TITLE}' appears to be valid.\n")

.github/workflows/github-ci.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ jobs:
164164
- name: Test with mypy
165165
run : |
166166
mypy pypdf
167+
- name: Check PR title
168+
env:
169+
PR_TITLE: ${{ github.event.pull_request.title }}
170+
run: |
171+
python .github/scripts/check_pr_title.py
172+
if: github.event_name == 'pull_request'
167173

168174
package:
169175
name: Build & verify package

0 commit comments

Comments
 (0)