Skip to content

Commit 114e678

Browse files
committed
feat: add more pre-commit ci checks
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 040c5c0 commit 114e678

File tree

6 files changed

+85
-7
lines changed

6 files changed

+85
-7
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ci:
2-
autoupdate_commit_msg: "chore: update pre-commit hooks"
2+
autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
33
autofix_commit_msg: "style: pre-commit fixes"
44
autoupdate_schedule: "quarterly"
55

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ for family, grp in itertools.groupby(collected.checks.items(), key=lambda x: x[1
384384
- [`PC190`](https://learn.scientific-python.org/development/guides/style#PC190): Uses Ruff
385385
- [`PC191`](https://learn.scientific-python.org/development/guides/style#PC191): Ruff show fixes if fixes enabled
386386
- [`PC192`](https://learn.scientific-python.org/development/guides/style#PC192): Ruff uses `ruff-check` instead of `ruff` (legacy)
387-
- [`PC901`](https://learn.scientific-python.org/development/guides/style#PC901): Custom pre-commit CI message
387+
- [`PC901`](https://learn.scientific-python.org/development/guides/style#PC901): Custom pre-commit CI update message
388+
- [`PC902`](https://learn.scientific-python.org/development/guides/style#PC902): Custom pre-commit CI autofix message
389+
- [`PC903`](https://learn.scientific-python.org/development/guides/style#PC903): Specified pre-commit CI schedule
388390

389391
### Ruff
390392
- [`RF001`](https://learn.scientific-python.org/development/guides/style#RF001): Has Ruff config

docs/pages/guides/style.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,18 @@ docker), you cannot enable a `--manual` flag, so extra checks will not run, and
7272
jobs should not download packages (use `additional-dependencies:` to add what
7373
you need).
7474

75-
{% rr PC901 %} You can customize the pre-commit message with:
75+
{% rr PC901 %} {% rr PC902 %} {% rr PC903 %} You can customize the pre-commit
76+
message with:
7677

7778
```yaml
7879
ci:
79-
autoupdate_commit_msg: "chore: update pre-commit hooks"
80+
autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
81+
autofix_commit_msg: "style: pre-commit fixes"
82+
autoupdate_schedule: "monthly"
8083
```
8184

85+
The frequencies can be "weekly" (the default), "monthly", and "quarterly".
86+
8287
## Format
8388

8489
{% rr PC110 %} [Black](https://black.readthedocs.io/en/latest/) is a popular

src/sp_repo_review/checks/precommit.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def check(cls, precommit: dict[str, Any]) -> bool | None:
195195

196196

197197
class PC901(PreCommit):
198-
"Custom pre-commit CI message"
198+
"Custom pre-commit CI update message"
199199

200200
@staticmethod
201201
def check(precommit: dict[str, Any]) -> bool:
@@ -204,12 +204,46 @@ def check(precommit: dict[str, Any]) -> bool:
204204
205205
```yaml
206206
ci:
207-
autoupdate_commit_msg: 'chore: update pre-commit hooks'
207+
autoupdate_commit_msg: 'chore(deps): update pre-commit hooks'
208208
```
209209
"""
210210

211211
return "autoupdate_commit_msg" in precommit.get("ci", {})
212212

213213

214+
class PC902(PreCommit):
215+
"Custom pre-commit CI autofix message"
216+
217+
@staticmethod
218+
def check(precommit: dict[str, Any]) -> bool:
219+
"""
220+
Should have something like this in `.pre-commit-config.yaml`:
221+
222+
```yaml
223+
ci:
224+
autofix_commit_msg: "style: pre-commit fixes"
225+
```
226+
"""
227+
228+
return "autofix_commit_msg" in precommit.get("ci", {})
229+
230+
231+
class PC903(PreCommit):
232+
"Specified pre-commit CI schedule"
233+
234+
@staticmethod
235+
def check(precommit: dict[str, Any]) -> bool:
236+
"""
237+
Should set some schedule: `weekly` (default), `monthly`, or `quarterly`.
238+
239+
```yaml
240+
ci:
241+
autoupdate_schedule: "monthly"
242+
```
243+
"""
244+
245+
return "autoupdate_schedule" in precommit.get("ci", {})
246+
247+
214248
def repo_review_checks() -> dict[str, PreCommit]:
215249
return {p.__name__: p() for p in PreCommit.__subclasses__()}

tests/test_precommit.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,38 @@ def test_pc901_no_msg():
248248
res = compute_check("PC901", precommit=precommit)
249249
assert not res.result
250250
assert "autoupdate_commit_msg" in res.err_msg
251+
252+
253+
def test_pc902():
254+
precommit = yaml.safe_load("""
255+
ci:
256+
autofix_commit_msg: 'style: pre-commit fixes'
257+
""")
258+
assert compute_check("PC902", precommit=precommit).result
259+
260+
261+
def test_pc902_no_msg():
262+
precommit = yaml.safe_load("""
263+
repos:
264+
""")
265+
res = compute_check("PC902", precommit=precommit)
266+
assert not res.result
267+
assert "autofix_commit_msg" in res.err_msg
268+
269+
270+
def test_pc903():
271+
precommit = yaml.safe_load("""
272+
ci:
273+
autoupdate_schedule: "monthly"
274+
275+
""")
276+
assert compute_check("PC903", precommit=precommit).result
277+
278+
279+
def test_pc903_no_msg():
280+
precommit = yaml.safe_load("""
281+
repos:
282+
""")
283+
res = compute_check("PC903", precommit=precommit)
284+
assert not res.result
285+
assert "autoupdate_schedule" in res.err_msg

{{cookiecutter.project_name}}/.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ci:
2-
autoupdate_commit_msg: "chore: update pre-commit hooks"
2+
autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
33
autofix_commit_msg: "style: pre-commit fixes"
4+
autoupdate_schedule: "monthly"
5+
46

57
exclude: ^.cruft.json|.copier-answers.yml$
68

0 commit comments

Comments
 (0)