Skip to content

Commit a5e437f

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/message-ai-attribution
2 parents 7f4ead1 + dd5f113 commit a5e437f

4 files changed

Lines changed: 79 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
**Catch bad commits before they merge — on every pull request.**
99

1010
[![Release](https://img.shields.io/github/v/release/commit-check/commit-check-action?labelColor=0b1620&color=2c9ccd&label=release)](https://github.com/commit-check/commit-check-action/releases)
11-
[![Used by](https://img.shields.io/static/v1?label=Used%20by&message=186&color=2c9ccd&logo=github&logoColor=white&labelColor=0b1620)](https://github.com/commit-check/commit-check-action/network/dependents)<!-- used by badge -->
11+
[![Used by](https://img.shields.io/static/v1?label=Used%20by&message=190&color=2c9ccd&logo=github&logoColor=white&labelColor=0b1620)](https://github.com/commit-check/commit-check-action/network/dependents)<!-- used by badge -->
1212
[![Marketplace](https://img.shields.io/badge/Marketplace-commit--check--action-2c9ccd?labelColor=0b1620&logo=githubactions&logoColor=white)](https://github.com/marketplace/actions/commit-check-action)
1313
[![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://github.com/commit-check/commit-check-action/blob/main/action.yml#L84-L94)
1414
[![Coverage](https://img.shields.io/codecov/c/github/commit-check/commit-check-action?labelColor=0b1620&color=2c9ccd&label=coverage)](https://codecov.io/gh/commit-check/commit-check-action)
@@ -130,8 +130,9 @@ click away:
130130
> <summary>Show all 4 checks</summary>
131131
>
132132
> ```text
133-
> Commit message
133+
> Pull request
134134
> ✔ PR title (feat: add login page)
135+
> Commit message
135136
> ✔ Commit 1/2 (d87faca) (feat: add login page)
136137
> ✖ Commit 2/2 (5584f46) (1 failure)
137138
> CC001 message
@@ -173,7 +174,7 @@ names the line to remove:
173174
> | PR description | `Claude Code` | [CC013 ai-attribution](https://commit-check.com/rules/#cc013) |
174175
>
175176
> ```text
176-
> PR description
177+
> Pull request
177178
> ✖ PR description (1 failure)
178179
> CC013 ai-attribution
179180
> value: Claude Code

‎commit-check.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
inherit_from = "github:commit-check/.github:commit-check.toml"
44

5+
[commit]
6+
# Exercises pr-body-ai-attribution in the self-test: under the default
7+
# "ignore" the PR description check runs no rule.
8+
ai_attribution = "forbid"
9+
510
[branch]
611
require_rebase_target = "origin/main"
712
allow_branch_names = ["create-pull-request/.+"]

‎main.py‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,35 @@ def skipped_author_scope(flag: str) -> ScopeResult:
447447
)
448448

449449

450+
#: Why an AI-only scope ran no rule: under the default policy there is none to run.
451+
AI_POLICY_IGNORED = 'ai_attribution is "ignore": set it to "forbid" or "disclose"'
452+
453+
454+
def skip_when_no_ai_rule_ran(scope: ScopeResult) -> ScopeResult:
455+
"""Report an AI-only scope that ran no rule as skipped, not passed.
456+
457+
Under the default ``ai_attribution = "ignore"`` the CLI builds none of
458+
the AI rules, so it returns an empty list of checks. Shown as a pass, that
459+
read as "checked, nothing found" to someone who turned the input on and
460+
forgot the policy.
461+
"""
462+
if scope.checks or scope.raw_text:
463+
return scope
464+
scope.checks = [
465+
{
466+
"rule_id": "CC013",
467+
"check": "ai_attribution",
468+
"status": "skip",
469+
"value": "",
470+
"error": "",
471+
"suggest": "",
472+
"docs_url": "",
473+
"reason": AI_POLICY_IGNORED,
474+
}
475+
]
476+
return scope
477+
478+
450479
def get_pr_title() -> str | None:
451480
"""Read PR title from GitHub event payload."""
452481
if not is_pr_event():
@@ -872,7 +901,7 @@ def run_commit_check() -> tuple[int, list[ScopeResult]]:
872901
)
873902
if PR_BODY_AI_ATTRIBUTION_ENABLED:
874903
name_the_line_changes(scope, pr_body)
875-
results.append(scope)
904+
results.append(skip_when_no_ai_rule_ran(scope))
876905
else:
877906
PR_BODY_AI_TOOLS[:] = scope.ai_tools
878907

@@ -942,7 +971,9 @@ def _rule_markdown_link(check: dict[str, str]) -> str:
942971

943972
def _scope_group(label: str) -> str:
944973
"""Group name for a scope label, used to fold the step log output."""
945-
if label == "PR title" or label.startswith("Commit"):
974+
if label in ("PR title", "PR description"):
975+
return "Pull request"
976+
if label.startswith("Commit"):
946977
return "Commit message"
947978
if label.startswith("Author"):
948979
return "Author"

‎main_test.py‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,11 +1788,22 @@ def test_groups_scopes_by_category(self):
17881788
fail_scope("Branch"),
17891789
]
17901790
output = self._run(results)
1791-
# One group for commit-message scopes, one for the branch scope.
1792-
self.assertEqual(output.count("::group::"), 2)
1791+
# One group each for the pull request, the commits and the branch.
1792+
self.assertEqual(output.count("::group::"), 3)
1793+
self.assertIn("::group::Pull request", output)
17931794
self.assertIn("::group::Commit message", output)
17941795
self.assertIn("::group::Branch", output)
17951796

1797+
def test_title_and_description_share_one_group(self):
1798+
"""The commits come after both, so the commit group is not split."""
1799+
results = [
1800+
pass_scope("PR title"),
1801+
pass_scope("PR description"),
1802+
pass_scope("Commit 1/1"),
1803+
]
1804+
groups = [name for name, _ in main._grouped(results)]
1805+
self.assertEqual(groups, ["Pull request", "Commit message"])
1806+
17961807
def test_raw_text_fallback_is_printed(self):
17971808
scope = main.ScopeResult(label="Branch", raw_text="unexpected output")
17981809
output = self._run([scope])
@@ -1854,8 +1865,9 @@ def test_success_golden_output(self):
18541865
"<summary>Show all 4 checks</summary>\n"
18551866
"\n"
18561867
"```text\n"
1857-
"Commit message\n"
1868+
"Pull request\n"
18581869
" ✔ PR title (feat: add login page)\n"
1870+
"Commit message\n"
18591871
" ✔ Commit 1/2 (feat: add user auth)\n"
18601872
" ✔ Commit 2/2 (fix: resolve timeout)\n"
18611873
"Branch\n"
@@ -1892,8 +1904,9 @@ def test_failure_golden_output(self):
18921904
"<summary>Show all 3 checks</summary>\n"
18931905
"\n"
18941906
"```text\n"
1895-
"Commit message\n"
1907+
"Pull request\n"
18961908
" ✔ PR title (feat: add login page)\n"
1909+
"Commit message\n"
18971910
" ✖ Commit 2/2 (1 failure)\n"
18981911
" CC001 message\n"
18991912
" value: bad message\n"
@@ -1943,8 +1956,9 @@ def test_failure_golden_output_with_commits(self):
19431956
"<summary>Show all 5 checks</summary>\n"
19441957
"\n"
19451958
"```text\n"
1946-
"Commit message\n"
1959+
"Pull request\n"
19471960
" ✔ PR title (feat: Add login page)\n"
1961+
"Commit message\n"
19481962
" ✖ Commit 1/3 (d87faca) (1 failure)\n"
19491963
" CC001 message\n"
19501964
" value: bad message\n"
@@ -3003,8 +3017,9 @@ def test_all_skipped_golden_output(self):
30033017
"<summary>Show all 2 checks</summary>\n"
30043018
"\n"
30053019
"```text\n"
3006-
"Commit message\n"
3020+
"Pull request\n"
30073021
" ⊘ PR title (skipped)\n"
3022+
"Commit message\n"
30083023
" ⊘ Commit 1/1 (skipped)\n"
30093024
"```\n"
30103025
"\n"
@@ -3251,7 +3266,7 @@ def test_warning_only_golden_output(self):
32513266
"<summary>Show all 2 checks</summary>\n"
32523267
"\n"
32533268
"```text\n"
3254-
"Commit message\n"
3269+
"Pull request\n"
32553270
" ✔ PR title (feat: add login page)\n"
32563271
"Branch\n"
32573272
" ⚠ Branch (1 warning)\n"
@@ -3773,6 +3788,21 @@ def test_pr_body_is_a_scope_checked_with_the_ai_rules_only(self):
37733788
)
37743789
self.assertEqual([r.label for r in results], ["PR description"])
37753790

3791+
def test_no_ai_rule_ran_reads_as_skipped_not_passed(self):
3792+
"""Under ai_attribution = "ignore" the CLI runs no rule on the description."""
3793+
results, _ = self._run(True, "false")
3794+
self.assertEqual(results[0].status, "skip")
3795+
self.assertEqual(results[0].skip_reason, main.AI_POLICY_IGNORED)
3796+
3797+
def test_a_rule_that_ran_keeps_its_verdict(self):
3798+
checks = [{"rule_id": "CC013", "check": "ai_attribution", "status": "pass"}]
3799+
scope = main.ScopeResult(label="PR description", checks=list(checks))
3800+
self.assertEqual(main.skip_when_no_ai_rule_ran(scope).checks, checks)
3801+
3802+
def test_unparsable_output_still_fails(self):
3803+
scope = main.ScopeResult(label="PR description", raw_text="Error: bad config")
3804+
self.assertEqual(main.skip_when_no_ai_rule_ran(scope).status, "fail")
3805+
37763806
def test_ai_label_alone_reads_it_but_reports_no_scope(self):
37773807
results, mock_scope = self._run(False, "true")
37783808
mock_scope.assert_called_once()

0 commit comments

Comments
 (0)