GeezerVison is showing github.com — fix: name the AI-rules-only option --ai-attribution-only (#677) · commit-check/commit-check@9aba6ad
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: README.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -184,14 +184,14 @@ author is on an `ignore_authors` list: `"author dependabot[bot] is in [commit].i | 184 | 184 |
| 185 | 185 | With a message checked, the output also has `ai_tools`: the AI tools found by | 186 | 186 | their known signatures in the message (and by a commit's author), under any | 187 | | -`ai_attribution` policy. `--ai-only` runs only the AI rules (CC013 to CC016), | | 187 | +`ai_attribution` policy. `--ai-attribution-only` runs only the AI rules (CC013 to CC016), | 188 | 188 | for text that is not a commit message, such as a pull request description. | 189 | 189 | Under the default `ai_attribution = "ignore"` no AI rule runs, so the result | 190 | 190 | passes and only `ai_tools` reports what was found; set `forbid` or `disclose` | 191 | 191 | to enforce a policy: | 192 | 192 |
| 193 | 193 | ```bash | 194 | | -commit-check --ai-only --format json < pr-description.md | | 194 | +commit-check --ai-attribution-only --format json < pr-description.md | 195 | 195 | ``` | 196 | 196 |
| 197 | 197 | Validate a commit message with the Python API, without a subprocess: | |
Collapse file Copy file name to clipboardExpand all lines: commit_check/engine.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -131,7 +131,7 @@ class ValidationContext: | 131 | 131 | # commits the remote lacks, so a ref pushed alongside it -- a tag that | 132 | 132 | # ``git push --follow-tags`` sends after a branch -- is not in the line. | 133 | 133 | push_from_pre_commit: bool = False | 134 | | - # Set by --ai-only: the text is not a commit message (a pull request | | 134 | + # Set by --ai-attribution-only: the text is not a commit message (a pull request | 135 | 135 | # description, say), so advice must not tell the reader to re-commit. | 136 | 136 | not_a_commit: bool = False | 137 | 137 |
| |
Collapse file Copy file name to clipboardExpand all lines: commit_check/main.py +14-5Lines changed: 14 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -191,12 +191,19 @@ def _get_parser() -> argparse.ArgumentParser: | 191 | 191 | ) | 192 | 192 |
| 193 | 193 | check_group.add_argument( | 194 | | - "--ai-only", | | 194 | + "--ai-attribution-only", | 195 | 195 | action="store_true", | 196 | 196 | help="check only the AI attribution of the message (CC013 to CC016), " | 197 | 197 | "for text that is not a commit message, such as a pull request " | 198 | 198 | "description; implies --message", | 199 | 199 | ) | | 200 | + # The name it shipped with in 2.20.1, kept so existing scripts still work. | | 201 | + check_group.add_argument( | | 202 | + "--ai-only", | | 203 | + dest="ai_attribution_only", | | 204 | + action="store_true", | | 205 | + help=argparse.SUPPRESS, | | 206 | + ) | 200 | 207 |
| 201 | 208 | check_group.add_argument( | 202 | 209 | "-b", | @@ -688,7 +695,9 @@ def _get_requested_checks(args: argparse.Namespace) -> set[str]: | 688 | 695 | requested_checks: set[str] = set() | 689 | 696 |
| 690 | 697 | if args.message: | 691 | | - requested_checks |= AI_TEXT_CHECKS if args.ai_only else MESSAGE_CHECKS | | 698 | + requested_checks |= ( | | 699 | + AI_TEXT_CHECKS if args.ai_attribution_only else MESSAGE_CHECKS | | 700 | + ) | 692 | 701 | if args.branch: | 693 | 702 | requested_checks |= BRANCH_CHECKS | 694 | 703 | if args.tag: | @@ -742,7 +751,7 @@ def _run_json_output( | 742 | 751 | "checks": [o.to_dict() for o in outcomes], | 743 | 752 | } | 744 | 753 | if args.message: | 745 | | - report["ai_tools"] = ai_tools_in(context, author=not args.ai_only) | | 754 | + report["ai_tools"] = ai_tools_in(context, author=not args.ai_attribution_only) | 746 | 755 | print(json.dumps(report, indent=2)) | 747 | 756 | # Only a failure is an error. A skipped run validated nothing, but that | 748 | 757 | # is not a policy violation, so it must not turn into a non-zero exit. | @@ -759,7 +768,7 @@ def main() -> int: | 759 | 768 |
| 760 | 769 | try: | 761 | 770 | # Handle positional commit_msg_file argument for pre-commit compatibility | 762 | | - if args.commit_msg_file or args.ai_only: | | 771 | + if args.commit_msg_file or args.ai_attribution_only: | 763 | 772 | args.message = True | 764 | 773 |
| 765 | 774 | if args.rev is not None: | @@ -870,7 +879,7 @@ def main() -> int: | 870 | 879 | and (stdin_content is None or stdin_is_message), | 871 | 880 | stdin_is_message=stdin_is_message, | 872 | 881 | push_from_pre_commit=push_from_pre_commit, | 873 | | - not_a_commit=args.ai_only, | | 882 | + not_a_commit=args.ai_attribution_only, | 874 | 883 | ) | 875 | 884 |
| 876 | 885 | # Run validation – choose output mode based on --format | |
Collapse file Copy file name to clipboardExpand all lines: commit_check/rules_catalog.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -326,7 +326,7 @@ def docs_url(self) -> str | None: | 326 | 326 | for entry in COMMIT_RULES | 327 | 327 | if entry.check not in {"author_name", "author_email", "ignore_authors"} | 328 | 328 | ) | 329 | | -#: What ``--ai-only`` runs: the AI attribution a text makes (CC013 to CC016), | | 329 | +#: What ``--ai-attribution-only`` runs: the AI attribution a text makes (CC013 to CC016), | 330 | 330 | #: for text that is not a commit, such as a pull request description. CC017 | 331 | 331 | #: is left out: it judges a commit's author, which such text does not have. | 332 | 332 | AI_TEXT_CHECKS: frozenset[str] = frozenset( | |
Collapse file Copy file name to clipboardExpand all lines: tests/main_test.py +30-6Lines changed: 30 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2242,8 +2242,8 @@ def test_the_message_or_the_type_is_printed( | 2242 | 2242 | assert capsys.readouterr().err == expected | 2243 | 2243 |
| 2244 | 2244 |
| 2245 | | -class TestAiOnly: | 2246 | | - """``--ai-only``: the AI rules on text that is not a commit message.""" | | 2245 | +class TestAiAttributionOnly: | | 2246 | + """``--ai-attribution-only``: the AI rules on text that is not a commit message.""" | 2247 | 2247 |
| 2248 | 2248 | BODY = ( | 2249 | 2249 | "This adds a parser.\n\n" | @@ -2264,7 +2264,7 @@ def test_only_the_ai_rules_run(self, mocker, capsys, monkeypatch, pinned_author) | 2264 | 2264 | capsys, | 2265 | 2265 | monkeypatch, | 2266 | 2266 | self.BODY, | 2267 | | - "--ai-only", | | 2267 | + "--ai-attribution-only", | 2268 | 2268 | "--ai-attribution", | 2269 | 2269 | "forbid", | 2270 | 2270 | ) | @@ -2287,7 +2287,7 @@ def test_under_disclose_the_three_rules_run( | 2287 | 2287 | capsys, | 2288 | 2288 | monkeypatch, | 2289 | 2289 | "This adds a parser.\n\nAssisted-by: Claude Code\n", | 2290 | | - "--ai-only", | | 2290 | + "--ai-attribution-only", | 2291 | 2291 | "--ai-attribution", | 2292 | 2292 | "disclose", | 2293 | 2293 | ) | @@ -2302,7 +2302,9 @@ def test_ignore_runs_nothing_but_still_names_the_tools( | 2302 | 2302 | self, mocker, capsys, monkeypatch, pinned_author | 2303 | 2303 | ): | 2304 | 2304 | """Label-only: no verdict, but the tools are reported.""" | 2305 | | - rc, data = self._run_json(mocker, capsys, monkeypatch, self.BODY, "--ai-only") | | 2305 | + rc, data = self._run_json( | | 2306 | + mocker, capsys, monkeypatch, self.BODY, "--ai-attribution-only" | | 2307 | + ) | 2306 | 2308 | assert rc == 0 | 2307 | 2309 | assert data["status"] == "pass" | 2308 | 2310 | assert data["checks"] == [] | @@ -2319,13 +2321,35 @@ def test_the_author_is_not_judged(self, mocker, capsys, monkeypatch): | 2319 | 2321 | capsys, | 2320 | 2322 | monkeypatch, | 2321 | 2323 | "This adds a parser.\n", | 2322 | | - "--ai-only", | | 2324 | + "--ai-attribution-only", | 2323 | 2325 | "--ai-attribution", | 2324 | 2326 | "forbid", | 2325 | 2327 | ) | 2326 | 2328 | assert rc == 0 | 2327 | 2329 | assert data["ai_tools"] == [] | 2328 | 2330 |
| | 2331 | + def test_the_old_name_still_works(self, mocker, capsys, monkeypatch, pinned_author): | | 2332 | + """``--ai-only``, the name it shipped with in 2.20.1, is a hidden alias.""" | | 2333 | + rc, data = self._run_json( | | 2334 | + mocker, | | 2335 | + capsys, | | 2336 | + monkeypatch, | | 2337 | + self.BODY, | | 2338 | + "--ai-only", | | 2339 | + "--ai-attribution", | | 2340 | + "forbid", | | 2341 | + ) | | 2342 | + assert rc == 1 | | 2343 | + assert [c["rule_id"] for c in data["checks"]] == ["CC013"] | | 2344 | + | | 2345 | + def test_the_old_name_is_not_in_the_help(self, capsys, monkeypatch): | | 2346 | + monkeypatch.setattr("sys.argv", [CMD, "--help"]) | | 2347 | + with pytest.raises(SystemExit): | | 2348 | + main() | | 2349 | + out = capsys.readouterr().out | | 2350 | + assert "--ai-attribution-only" in out | | 2351 | + assert "--ai-only" not in out | | 2352 | + | 2329 | 2353 |
| 2330 | 2354 | class TestAiToolsInJson: | 2331 | 2355 | """``ai_tools`` names the AI tools of a checked message, whatever the policy.""" | |
|