Skip to content

Commit 1c814c8

Browse files
authored
feat: check the AI declaration in an empty pull request description (#341)
2 parents c5dada8 + e80565e commit 1c814c8

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ runners need a few tools — see [Good to know](#good-to-know).
8181
| `author-email` | `false` | Check each commit's author email |
8282
| `pr-title` | `false` | Check the pull request title against Conventional Commits — the one that matters for squash merges. Pull request events only |
8383
| `message-ai-attribution` | `false` | Check every commit against the AI rules of `cchk.toml` (`ai_attribution`) only, author included, without the format rules. Takes the place of `message` |
84-
| `pr-body-ai-attribution` | `false` | Check the pull request description against the AI rules of `cchk.toml` (`ai_attribution`) only. Pull request events only |
84+
| `pr-body-ai-attribution` | `false` | Check the pull request description against the AI rules of `cchk.toml` (`ai_attribution`, and the AI declaration boxes of `[pull_request] ai_declaration_checkboxes`) only. Pull request events only |
8585
| `ai-label` | `false` | Label the pull request when an AI tool wrote any of it (a commit, the description, or an agent's app that opened it): `true` for `ai-assisted`, or the label's name. Labels are only added, never removed. Needs `pull-requests: write`; skipped on fork pull requests under `pull_request` |
8686
| `pr-comments` | `false` | Post the report as a pull request comment, edited in place on later runs. Needs `pull-requests: write`; skipped on fork pull requests |
8787
| `job-summary` | `true` | Write the report to the job summary |
@@ -212,6 +212,20 @@ the line to remove:
212212
> - Co-Authored-By: Claude <noreply@anthropic.com>
213213
> ```
214214

215+
If your pull request template asks the author to tick "No AI tools were used"
216+
or "AI tools were used", name those boxes and the description must tick exactly
217+
one of them (CC501). An empty description fails too:
218+
219+
```toml
220+
[pull_request]
221+
ai_declaration_checkboxes = ["No AI tools were used", "AI tools were used"]
222+
```
223+
224+
> ```diff
225+
> @@ PR description @@
226+
> # Tick the box that applies: "No AI tools were used" or "AI tools were used"
227+
> ```
228+
215229
With `ai-label: true`, a pull request an AI tool wrote also gets the
216230
`ai-assisted` label.
217231

‎main.py‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,20 @@ def run_commit_check() -> tuple[int, list[ScopeResult]]:
994994
# ---- 2. PR description ------------------------------------------------
995995
if (PR_BODY_AI_ATTRIBUTION_ENABLED or ai_label_name()) and is_pr_event():
996996
pr_body = get_pr_body()
997-
if pr_body:
997+
if PR_BODY_AI_ATTRIBUTION_ENABLED:
998+
# An empty description is checked too: it has no AI declaration,
999+
# which CC501 fails when [pull_request] ai_declaration_checkboxes
1000+
# names the boxes. The attribution rules pass empty text.
1001+
scope = check_scope(
1002+
"PR description", ["--ai-attribution-only"], input_text=pr_body or ""
1003+
)
1004+
name_the_line_changes(scope, pr_body or "")
1005+
results.append(skip_when_no_ai_rule_ran(scope))
1006+
elif pr_body:
9981007
scope = check_scope(
9991008
"PR description", ["--ai-attribution-only"], input_text=pr_body
10001009
)
1001-
if PR_BODY_AI_ATTRIBUTION_ENABLED:
1002-
name_the_line_changes(scope, pr_body)
1003-
results.append(skip_when_no_ai_rule_ran(scope))
1004-
else:
1005-
PR_BODY_AI_TOOLS[:] = scope.ai_tools
1010+
PR_BODY_AI_TOOLS[:] = scope.ai_tools
10061011

10071012
# ---- 3. Commit message checks -----------------------------------------
10081013
pr_commits: list[Commit] | None = None
@@ -1971,7 +1976,7 @@ def _all_checks(results: list[ScopeResult]) -> list[str]:
19711976
#
19721977
# </details>
19731978
#
1974-
# <sub>Checked by [Commit Check](https://commit-check.com) 2.20.5 · [Rules](…) · [Check before you push](…)</sub>
1979+
# <sub>Checked by [Commit Check](https://commit-check.com) 2.21.0 · [Rules](…) · [Check before you push](…)</sub>
19751980
#
19761981
# Success: the heading reads "<mark:passed> Commit Check passed", then the
19771982
# group lines, the folded listing and the footer. No diff, no "How to fix".

‎main_test.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4604,8 +4604,16 @@ def test_off_by_default(self):
46044604
mock_scope.assert_not_called()
46054605
self.assertEqual(results, [])
46064606

4607-
def test_no_description_nothing_to_check(self):
4607+
def test_no_description_is_checked_as_empty_text(self):
4608+
"""A description left empty has no AI declaration for CC501 to find."""
46084609
results, mock_scope = self._run(True, "true", body=None)
4610+
mock_scope.assert_called_once_with(
4611+
"PR description", ["--ai-attribution-only"], input_text=""
4612+
)
4613+
self.assertEqual([r.label for r in results], ["PR description"])
4614+
4615+
def test_no_description_nothing_to_label(self):
4616+
results, mock_scope = self._run(False, "true", body=None)
46094617
mock_scope.assert_not_called()
46104618
self.assertEqual(results, [])
46114619

‎requirements.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Install commit-check CLI
22
# For details please see: https://github.com/commit-check/commit-check
3-
commit-check==2.20.5
3+
commit-check==2.21.0
44
# Interact with the GitHub API.
55
PyGithub==2.10.0

0 commit comments

Comments
 (0)