diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index cecd98ce0..72b27e2cb 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -20,6 +20,7 @@ Tick the [commit type](https://github.com/JarryShaw/PyPCAPKit/blob/main/CONTRIBU - [ ] `test` — tests only - [ ] `docs` — documentation only - [ ] `ci` — workflows or build tooling +- [ ] `release` — bumps the version or rolls up a distribution - [ ] `chore` — anything else --- diff --git a/tests/project/test_conventions_doc_claims.py b/tests/project/test_conventions_doc_claims.py index 629d8d25b..a41a1f0e8 100644 --- a/tests/project/test_conventions_doc_claims.py +++ b/tests/project/test_conventions_doc_claims.py @@ -1410,8 +1410,8 @@ def test_the_page_names_every_commit_type_the_template_ticks(self) -> 'None': :file:`.github/PULL_REQUEST_TEMPLATE.md` is where a contributor actually meets the list, so it is the ground truth rather than a list retyped into this file. - Note the label set is a **superset**: ``release`` and ``const`` are type-ish - labels with no tickbox, so this is a one-way check by design. + Note the label set is a **superset**: ``const`` is a type-ish label with no + tickbox, so this is a one-way check by design. """ types = re.findall(r'^- \[ \] `([a-z]+)` ', self.TEMPLATE.read_text(encoding='utf-8'), diff --git a/tests/project/test_pr_template_commit_types_1102_unit.py b/tests/project/test_pr_template_commit_types_1102_unit.py new file mode 100644 index 000000000..584c14071 --- /dev/null +++ b/tests/project/test_pr_template_commit_types_1102_unit.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +"""Every commit type :file:`CONTRIBUTING.md` allows has a box in the PR template (#1102). + +:file:`CONTRIBUTING.md` lists the valid ``type`` prefixes of a commit subject, and +:file:`.github/PULL_REQUEST_TEMPLATE.md` asks the contributor to tick the one their +subject carries. The template had no ``release`` box although ``release`` is a listed +type with commits in the history, so a version-bump pull request had nothing to tick. + +""" + +import pathlib +import re +import unittest + +ROOT = pathlib.Path(__file__).resolve().parents[2] + + +class TestPullRequestTemplateCommitTypes(unittest.TestCase): + """The template's commit-type boxes match :file:`CONTRIBUTING.md`'s type list.""" + + def _contributing_types(self) -> 'list[str]': + text = ' '.join((ROOT / 'CONTRIBUTING.md').read_text(encoding='utf-8').split()) + match = re.search(r'`type` is one of (.*?) —', text) + self.assertIsNotNone(match, 'CONTRIBUTING.md no longer states "`type` is one of ..."') + return re.findall(r'`([a-z]+)`', match.group(1)) # type: ignore[union-attr] + + def _template_types(self) -> 'list[str]': + text = (ROOT / '.github' / 'PULL_REQUEST_TEMPLATE.md').read_text(encoding='utf-8') + return re.findall(r'^- \[ \] `([a-z]+)` — ', text, re.MULTILINE) + + def test_every_contributing_type_has_a_template_box(self) -> 'None': + """Each type :file:`CONTRIBUTING.md` lists is tickable, and nothing else is.""" + listed = self._contributing_types() + self.assertGreaterEqual(len(listed), 9, + f'only {listed!r} parsed out of CONTRIBUTING.md; ' + 'the comparison below would pass vacuously') + self.assertEqual(sorted(self._template_types()), sorted(listed), + 'the pull request template\'s commit-type boxes differ from ' + 'the types CONTRIBUTING.md lists') + + +if __name__ == '__main__': + unittest.main()