Skip to content

Commit cd21e10

Browse files
committed
feat: check the AI declaration in an empty pull request description
With pr-body-ai-attribution on, a pull request opened with no description was not checked at all. The CLI's CC501 fails a description that has none of the AI declaration boxes named in [pull_request] ai_declaration_options, and an empty one has none, so the description now goes to the CLI as empty text. With ai-label alone an empty description is still skipped: it names no tool. The README shows the new setting next to the AI attribution example.
1 parent c5dada8 commit cd21e10

3 files changed

Lines changed: 35 additions & 8 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_options`) 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_options = ["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: 11 additions & 6 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_options
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

‎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

0 commit comments

Comments
 (0)