Skip to content

Commit 85e5a18

Browse files
committed
chore(github): add a release commit-type box to the PR template
CONTRIBUTING.md lists release as a commit type, and release: commits exist in the history, but the PR template had no box for it. Add one above chore, which stays last as the catch-all, worded from process.rst's release label definition, and pin the template's boxes against CONTRIBUTING.md's type list in a new tests/project module. Closes #1102
1 parent b10e795 commit 85e5a18

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Tick the [commit type](https://github.com/JarryShaw/PyPCAPKit/blob/main/CONTRIBU
2020
- [ ] `test` — tests only
2121
- [ ] `docs` — documentation only
2222
- [ ] `ci` — workflows or build tooling
23+
- [ ] `release` — bumps the version or rolls up a distribution
2324
- [ ] `chore` — anything else
2425

2526
---

‎tests/project/test_conventions_doc_claims.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,8 @@ def test_the_page_names_every_commit_type_the_template_ticks(self) -> 'None':
14101410
14111411
:file:`.github/PULL_REQUEST_TEMPLATE.md` is where a contributor actually meets
14121412
the list, so it is the ground truth rather than a list retyped into this file.
1413-
Note the label set is a **superset**: ``release`` and ``const`` are type-ish
1414-
labels with no tickbox, so this is a one-way check by design.
1413+
Note the label set is a **superset**: ``const`` is a type-ish label with no
1414+
tickbox, so this is a one-way check by design.
14151415
14161416
"""
14171417
types = re.findall(r'^- \[ \] `([a-z]+)` ', self.TEMPLATE.read_text(encoding='utf-8'),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""Every commit type :file:`CONTRIBUTING.md` allows has a box in the PR template (#1102).
3+
4+
:file:`CONTRIBUTING.md` lists the valid ``type`` prefixes of a commit subject, and
5+
:file:`.github/PULL_REQUEST_TEMPLATE.md` asks the contributor to tick the one their
6+
subject carries. The template had no ``release`` box although ``release`` is a listed
7+
type with commits in the history, so a version-bump pull request had nothing to tick.
8+
9+
"""
10+
11+
import pathlib
12+
import re
13+
import unittest
14+
15+
ROOT = pathlib.Path(__file__).resolve().parents[2]
16+
17+
18+
class TestPullRequestTemplateCommitTypes(unittest.TestCase):
19+
"""The template's commit-type boxes match :file:`CONTRIBUTING.md`'s type list."""
20+
21+
def _contributing_types(self) -> 'list[str]':
22+
text = ' '.join((ROOT / 'CONTRIBUTING.md').read_text(encoding='utf-8').split())
23+
match = re.search(r'`type` is one of (.*?) —', text)
24+
self.assertIsNotNone(match, 'CONTRIBUTING.md no longer states "`type` is one of ..."')
25+
return re.findall(r'`([a-z]+)`', match.group(1)) # type: ignore[union-attr]
26+
27+
def _template_types(self) -> 'list[str]':
28+
text = (ROOT / '.github' / 'PULL_REQUEST_TEMPLATE.md').read_text(encoding='utf-8')
29+
return re.findall(r'^- \[ \] `([a-z]+)` — ', text, re.MULTILINE)
30+
31+
def test_every_contributing_type_has_a_template_box(self) -> 'None':
32+
"""Each type :file:`CONTRIBUTING.md` lists is tickable, and nothing else is."""
33+
listed = self._contributing_types()
34+
self.assertGreaterEqual(len(listed), 9,
35+
f'only {listed!r} parsed out of CONTRIBUTING.md; '
36+
'the comparison below would pass vacuously')
37+
self.assertEqual(sorted(self._template_types()), sorted(listed),
38+
'the pull request template\'s commit-type boxes differ from '
39+
'the types CONTRIBUTING.md lists')
40+
41+
42+
if __name__ == '__main__':
43+
unittest.main()

0 commit comments

Comments
 (0)