diff --git a/.github/scripts/check_pr_title.py b/.github/scripts/check_pr_title.py new file mode 100644 index 000000000..dea47b763 --- /dev/null +++ b/.github/scripts/check_pr_title.py @@ -0,0 +1,32 @@ +"""Check that all PR titles follow the desired scheme.""" # noqa: INP001 + +import os +import sys + +KNOWN_PREFIXES = ( + "SEC: ", + "BUG: ", + "ENH: ", + "DEP: ", + "PI: ", + "ROB: ", + "DOC: ", + "TST: ", + "DEV: ", + "STY: ", + "MAINT: ", +) +PR_TITLE = os.getenv("PR_TITLE", "") + +if not PR_TITLE.startswith(KNOWN_PREFIXES) or not PR_TITLE.split(": ", maxsplit=1)[1]: + sys.stderr.write( + f"The PR title '{PR_TITLE}' does not follow the projects naming scheme: " + "https://pypdf.readthedocs.io/en/latest/dev/intro.html#commit-messages\n", + ) + sys.stderr.write( + "If you do not know which one to choose or if multiple apply, make a best guess. " + "Nobody will complain if it does not quite fit :-)\n", + ) + sys.exit(1) +else: + sys.stdout.write(f"PR title '{PR_TITLE}' appears to be valid.\n") diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 7d0f1426c..54f986cb2 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -164,6 +164,12 @@ jobs: - name: Test with mypy run : | mypy pypdf + - name: Check PR title + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: | + python .github/scripts/check_pr_title.py + if: github.event_name == 'pull_request' package: name: Build & verify package