Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---
Expand Down
4 changes: 2 additions & 2 deletions tests/project/test_conventions_doc_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
43 changes: 43 additions & 0 deletions tests/project/test_pr_template_commit_types_1102_unit.py
Original file line number Diff line number Diff line change
@@ -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()
Loading