diff --git a/README.md b/README.md index 92bbe03..2bfbe03 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ runners need a few tools — see [Good to know](#good-to-know). | `author-email` | `false` | Check each commit's author email | | `pr-title` | `false` | Check the pull request title against Conventional Commits — the one that matters for squash merges. Pull request events only | | `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` | -| `pr-body-ai-attribution` | `false` | Check the pull request description against the AI rules of `cchk.toml` (`ai_attribution`) only. Pull request events only | +| `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 | | `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` | | `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 | | `job-summary` | `true` | Write the report to the job summary | @@ -212,6 +212,20 @@ the line to remove: > - Co-Authored-By: Claude > ``` +If your pull request template asks the author to tick "No AI tools were used" +or "AI tools were used", name those boxes and the description must tick exactly +one of them (CC501). An empty description fails too: + +```toml +[pull_request] +ai_declaration_checkboxes = ["No AI tools were used", "AI tools were used"] +``` + +> ```diff +> @@ PR description @@ +> # Tick the box that applies: "No AI tools were used" or "AI tools were used" +> ``` + With `ai-label: true`, a pull request an AI tool wrote also gets the `ai-assisted` label. diff --git a/main.py b/main.py index e496ac4..78e1811 100755 --- a/main.py +++ b/main.py @@ -994,15 +994,20 @@ def run_commit_check() -> tuple[int, list[ScopeResult]]: # ---- 2. PR description ------------------------------------------------ if (PR_BODY_AI_ATTRIBUTION_ENABLED or ai_label_name()) and is_pr_event(): pr_body = get_pr_body() - if pr_body: + if PR_BODY_AI_ATTRIBUTION_ENABLED: + # An empty description is checked too: it has no AI declaration, + # which CC501 fails when [pull_request] ai_declaration_checkboxes + # names the boxes. The attribution rules pass empty text. + scope = check_scope( + "PR description", ["--ai-attribution-only"], input_text=pr_body or "" + ) + name_the_line_changes(scope, pr_body or "") + results.append(skip_when_no_ai_rule_ran(scope)) + elif pr_body: scope = check_scope( "PR description", ["--ai-attribution-only"], input_text=pr_body ) - if PR_BODY_AI_ATTRIBUTION_ENABLED: - name_the_line_changes(scope, pr_body) - results.append(skip_when_no_ai_rule_ran(scope)) - else: - PR_BODY_AI_TOOLS[:] = scope.ai_tools + PR_BODY_AI_TOOLS[:] = scope.ai_tools # ---- 3. Commit message checks ----------------------------------------- pr_commits: list[Commit] | None = None @@ -1971,7 +1976,7 @@ def _all_checks(results: list[ScopeResult]) -> list[str]: # # # -# Checked by [Commit Check](https://commit-check.com) 2.20.5 · [Rules](…) · [Check before you push](…) +# Checked by [Commit Check](https://commit-check.com) 2.21.0 · [Rules](…) · [Check before you push](…) # # Success: the heading reads " Commit Check passed", then the # group lines, the folded listing and the footer. No diff, no "How to fix". diff --git a/main_test.py b/main_test.py index e3476c5..95ec0c8 100644 --- a/main_test.py +++ b/main_test.py @@ -4604,8 +4604,16 @@ def test_off_by_default(self): mock_scope.assert_not_called() self.assertEqual(results, []) - def test_no_description_nothing_to_check(self): + def test_no_description_is_checked_as_empty_text(self): + """A description left empty has no AI declaration for CC501 to find.""" results, mock_scope = self._run(True, "true", body=None) + mock_scope.assert_called_once_with( + "PR description", ["--ai-attribution-only"], input_text="" + ) + self.assertEqual([r.label for r in results], ["PR description"]) + + def test_no_description_nothing_to_label(self): + results, mock_scope = self._run(False, "true", body=None) mock_scope.assert_not_called() self.assertEqual(results, []) diff --git a/requirements.txt b/requirements.txt index 57b10bd..5fcf7af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Install commit-check CLI # For details please see: https://github.com/commit-check/commit-check -commit-check==2.20.5 +commit-check==2.21.0 # Interact with the GitHub API. PyGithub==2.10.0