From cb3f11ab1a6aa0606491de88ff618c871a8d88fe Mon Sep 17 00:00:00 2001 From: stefan6419846 <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:06:46 +0100 Subject: [PATCH 1/4] DEV: Ensure that the PR titles have the correct format --- .github/scripts/check_pr_title.py | 31 +++++++++++++++++++++++++++++++ .github/workflows/github-ci.yaml | 6 ++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/scripts/check_pr_title.py diff --git a/.github/scripts/check_pr_title.py b/.github/scripts/check_pr_title.py new file mode 100644 index 000000000..84d10b1d9 --- /dev/null +++ b/.github/scripts/check_pr_title.py @@ -0,0 +1,31 @@ +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( + 'Please set an appropriate PR title: ' + '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: + print('PR title appears to be valid.') 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 From 4efb2662a2daaa9a80cdda9702844ea4e94dc042 Mon Sep 17 00:00:00 2001 From: stefan6419846 <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:12:03 +0100 Subject: [PATCH 2/4] satisfy ruff --- .github/scripts/check_pr_title.py | 39 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/scripts/check_pr_title.py b/.github/scripts/check_pr_title.py index 84d10b1d9..2a318c7e7 100644 --- a/.github/scripts/check_pr_title.py +++ b/.github/scripts/check_pr_title.py @@ -1,31 +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: ', + "SEC: ", + "BUG: ", + "ENH: ", + "DEP: ", + "PI: ", + "ROB: ", + "DOC: ", + "TST: ", + "DEV: ", + "STY: ", + "MAINT: ", ) -PR_TITLE = os.getenv('PR_TITLE', '') +PR_TITLE = os.getenv("PR_TITLE", "") -if not PR_TITLE.startswith(KNOWN_PREFIXES) or not PR_TITLE.split(': ', maxsplit=1)[1]: +if not PR_TITLE.startswith(KNOWN_PREFIXES) or not PR_TITLE.split(": ", maxsplit=1)[1]: sys.stderr.write( - 'Please set an appropriate PR title: ' - 'https://pypdf.readthedocs.io/en/latest/dev/intro.html#commit-messages\n', + "Please set an appropriate PR title: " + "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', + "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: - print('PR title appears to be valid.') + sys.stdout.write("PR title appears to be valid.\n") From 1046578c1f3c9dd917e9b25f982361146743d568 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:30:47 +0100 Subject: [PATCH 3/4] update positive text Co-authored-by: Martin Thoma --- .github/scripts/check_pr_title.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check_pr_title.py b/.github/scripts/check_pr_title.py index 2a318c7e7..954acd098 100644 --- a/.github/scripts/check_pr_title.py +++ b/.github/scripts/check_pr_title.py @@ -29,4 +29,4 @@ ) sys.exit(1) else: - sys.stdout.write("PR title appears to be valid.\n") + sys.stdout.write(f"PR title '{PR_TITLE}' appears to be valid.\n") From eff869baef82260f783a0a116d8614893ae46dd0 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:31:11 +0100 Subject: [PATCH 4/4] user nicer negative message Co-authored-by: Martin Thoma --- .github/scripts/check_pr_title.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check_pr_title.py b/.github/scripts/check_pr_title.py index 954acd098..dea47b763 100644 --- a/.github/scripts/check_pr_title.py +++ b/.github/scripts/check_pr_title.py @@ -20,7 +20,7 @@ if not PR_TITLE.startswith(KNOWN_PREFIXES) or not PR_TITLE.split(": ", maxsplit=1)[1]: sys.stderr.write( - "Please set an appropriate PR title: " + 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(