commit-check 2.20.2__py3-none-any.whl → 2.20.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
commit_check/__init__.py CHANGED
@@ -49,6 +49,8 @@ RED = "\033[91m" if _colored else ""
49
49
  GREEN = "\033[92m" if _colored else ""
50
50
  YELLOW = "\033[93m" if _colored else ""
51
51
  RESET_COLOR = "\033[0m" if _colored else ""
52
+ BOLD = "\033[1m" if _colored else ""
53
+ DIM = "\033[2m" if _colored else ""
52
54
 
53
55
  # Follow conventional commits
54
56
  DEFAULT_COMMIT_TYPES = [
commit_check/engine.py CHANGED
@@ -247,7 +247,7 @@ class BaseValidator(ABC):
247
247
  # Populated by _print_failure() on every failure, regardless of mode.
248
248
  self._last_failure: dict[str, str] | None = None
249
249
  # The failure blocks as the printer takes them, (rule dict, value),
250
- # kept so the engine can print them after the banner.
250
+ # kept so the engine can print them after the header.
251
251
  self._failure_blocks: list[tuple[dict, str]] = []
252
252
  # Populated by subclasses on every validation (pass or fail) with the
253
253
  # concrete value that was checked (subject, branch, author, ...), so
@@ -1642,13 +1642,18 @@ def _author_identity(context: ValidationContext) -> tuple[str, str]:
1642
1642
  An existing commit (``--rev``, or HEAD) by its recorded author; a message
1643
1643
  not yet committed by the author git would record for it.
1644
1644
  """
1645
- if context.rev is None and (
1646
- context.stdin_text is not None or context.commit_file is not None
1647
- ):
1645
+ if _is_pending(context):
1648
1646
  return get_pending_author_identity()
1649
1647
  return get_commit_author_identity(context.rev or "HEAD")
1650
1648
 
1651
1649
 
1650
+ def _is_pending(context: ValidationContext) -> bool:
1651
+ """Whether the message under test is not committed yet (stdin or a file)."""
1652
+ return context.rev is None and (
1653
+ context.stdin_text is not None or context.commit_file is not None
1654
+ )
1655
+
1656
+
1652
1657
  def ai_tools_in(context: ValidationContext, *, author: bool) -> list[str]:
1653
1658
  """The AI tools the message under test names, sorted, whatever the policy.
1654
1659
 
@@ -1687,7 +1692,19 @@ class AiAuthorValidator(BaseValidator):
1687
1692
  if tool is None:
1688
1693
  return ValidationResult.PASS
1689
1694
 
1690
- suggest = "Author the commit yourself: git commit --amend --reset-author"
1695
+ if _is_pending(context):
1696
+ # Usually no commit exists yet (a hook, a piped message): --amend
1697
+ # would rewrite the one before it, and --reset-author on its own
1698
+ # records this same identity again. The Action pipes existing
1699
+ # pull request commits this way too, hence the last clause.
1700
+ suggest = (
1701
+ "Commit as yourself: set git config user.name and user.email "
1702
+ "to your own, and unset GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL "
1703
+ "if a tool set them; a commit that already exists then needs "
1704
+ "git commit --amend --reset-author"
1705
+ )
1706
+ else:
1707
+ suggest = "Author the commit yourself: git commit --amend --reset-author"
1691
1708
  if self.rule.value == "disclose":
1692
1709
  trailers = self.rule.allowed or list(DEFAULT_AI_DISCLOSURE_TRAILERS)
1693
1710
  suggest += f', and disclose the tool with "{trailers[0]}: {tool}"'
@@ -1739,7 +1756,7 @@ class ValidationEngine:
1739
1756
  """Run all validations, print the findings, and return the overall result.
1740
1757
 
1741
1758
  The failure blocks are printed once every rule has run, not as each
1742
- rule fails: the banner above them names what was rejected, and that
1759
+ rule fails: the header above them names what was rejected, and that
1743
1760
  is only known once it is clear whether the failures are all about the
1744
1761
  commit, all about the branch, or spread across both.
1745
1762
  """
@@ -1769,7 +1786,7 @@ class ValidationEngine:
1769
1786
  continue # Skip unknown validators
1770
1787
 
1771
1788
  validator: BaseValidator = validator_class(rule)
1772
- validator._suppress_output = True # printed later, after the banner
1789
+ validator._suppress_output = True # printed later, after the header
1773
1790
  result = validator.validate(context)
1774
1791
  blocks.extend(validator._failure_blocks)
1775
1792
  if result == ValidationResult.SKIP:
@@ -1786,11 +1803,11 @@ class ValidationEngine:
1786
1803
  def _print_blocks(
1787
1804
  context: ValidationContext, failed: list[str], blocks: list[tuple[dict, str]]
1788
1805
  ) -> None:
1789
- """Print the banner, named for *failed*, then every failure block."""
1806
+ """Print the header, named for *failed*, then every failure block."""
1790
1807
  if not blocks:
1791
1808
  return
1792
1809
 
1793
- # Only an enforced failure earns the banner; a warning rejects
1810
+ # Only an enforced failure earns the header; a warning rejects
1794
1811
  # nothing. --compact and --no-banner keep it off entirely.
1795
1812
  if (
1796
1813
  failed
@@ -1798,7 +1815,7 @@ class ValidationEngine:
1798
1815
  and not context.compact
1799
1816
  and not print_error_header.has_been_called
1800
1817
  ):
1801
- print_error_header(rejection_headline(failed))
1818
+ print_error_header(rejection_headline(failed), failed=len(failed))
1802
1819
  for rule_dict, value in blocks:
1803
1820
  _print_failure(
1804
1821
  rule_dict,
commit_check/main.py CHANGED
@@ -286,7 +286,7 @@ def _get_parser() -> argparse.ArgumentParser:
286
286
  "--no-banner",
287
287
  action="store_true",
288
288
  default=False,
289
- help="suppress the ASCII art banner on failure",
289
+ help="suppress the one-line rejection header on failure",
290
290
  )
291
291
 
292
292
  check_group.add_argument(
@@ -620,6 +620,11 @@ def _resolve_commit_message_source(
620
620
  return None, args.commit_msg_file
621
621
 
622
622
  stdin_content = stdin_reader.read_piped_input()
623
+ if args.ai_attribution_only:
624
+ # The text under test is what was piped, a pull request description
625
+ # say. None of it, an empty description, is empty text: falling back
626
+ # to HEAD would judge the last commit's message in its place.
627
+ return stdin_content or "", None
623
628
  return stdin_content or None, None
624
629
 
625
630
 
@@ -865,7 +870,7 @@ def main() -> int:
865
870
  if args.fix and commit_file_path and not args.dry_run:
866
871
  _fix_message_file(commit_file_path, filtered_rules, config_data)
867
872
 
868
- # Reset banner state for this run
873
+ # Reset header state for this run
869
874
  print_error_header.has_been_called = False
870
875
 
871
876
  context = ValidationContext(
commit_check/util.py CHANGED
@@ -14,7 +14,7 @@ import sys
14
14
  from collections.abc import Iterable
15
15
  from subprocess import CalledProcessError
16
16
 
17
- from commit_check import GREEN, RED, RESET_COLOR, YELLOW
17
+ from commit_check import BOLD, DIM, GREEN, RED, RESET_COLOR, YELLOW
18
18
  from commit_check.rules_catalog import display_name
19
19
 
20
20
  # C0 and C1 control characters, and DEL, except the newline and tab that a
@@ -55,7 +55,7 @@ def _print_failure(
55
55
  """Print a standardized failure message.
56
56
 
57
57
  A rule whose ``severity`` is ``"warn"`` prints the same block with the
58
- word ``warning`` in place of ``failed``, no rejection banner, and one
58
+ word ``warning`` in place of ``failed``, no rejection header, and one
59
59
  closing line saying the run is not failed by it.
60
60
  """
61
61
  rule_id = check.get("rule_id", "")
@@ -66,7 +66,7 @@ def _print_failure(
66
66
  label = f"{rule_id} {name}" if rule_id else name
67
67
  print(f"[{'WARN' if warn else 'FAIL'}] {label}: {compact_value}")
68
68
  return
69
- # The banner announces a rejection; a warning rejects nothing.
69
+ # The header announces a rejection; a warning rejects nothing.
70
70
  if not warn and not no_banner and not print_error_header.has_been_called:
71
71
  print_error_header(rejection_headline([check["check"]]))
72
72
  docs_url = check.get("docs_url", "") or ""
@@ -88,9 +88,14 @@ def _print_failure(
88
88
  # to read. Without hyperlink support — a pipe, a CI log — it is the only
89
89
  # way the reader gets the address at all, so it stays.
90
90
  if docs_url and not (rule_id and supports_hyperlinks()):
91
- print(f"Docs: {docs_url}")
91
+ print(
92
+ f"{_DETAIL_INDENT}{DIM}Docs:{RESET_COLOR} {DIM}{docs_url}{RESET_COLOR}"
93
+ )
92
94
  if warn:
93
- print("This rule is set to warn in the config; it does not fail the run.")
95
+ print(
96
+ f"{_DETAIL_INDENT}{DIM}This rule is set to warn in the config; "
97
+ f"it does not fail the run.{RESET_COLOR}"
98
+ )
94
99
  # Blank line closes the whole block, rather than splitting it before the
95
100
  # documentation link.
96
101
  print()
@@ -786,7 +791,7 @@ def track_print_call(func):
786
791
  return wrapper
787
792
 
788
793
 
789
- #: What the banner says was rejected, by the check that failed. A check not
794
+ #: What the header says was rejected, by the check that failed. A check not
790
795
  #: listed here is about the commit itself: its message, its author, the files
791
796
  #: it touches.
792
797
  _REJECTED_SUBJECTS = {
@@ -796,12 +801,26 @@ _REJECTED_SUBJECTS = {
796
801
  "no_force_push": "Push",
797
802
  }
798
803
 
799
- #: Width of the banner's ASCII art; the text lines are padded to match it.
800
- _BANNER_WIDTH = 66
804
+ #: Detail lines (explanation, suggestion, docs) sit under the failing value,
805
+ #: indented past the marker so the rule IDs form a column to scan down.
806
+ _DETAIL_INDENT = " "
807
+
808
+
809
+ def _symbol(fancy: str, plain: str) -> str:
810
+ """*fancy* when stdout can encode it, else *plain*.
811
+
812
+ A Windows console on a legacy code page cannot print every symbol, and a
813
+ failure report that crashes with UnicodeEncodeError reports nothing.
814
+ """
815
+ try:
816
+ fancy.encode(getattr(sys.stdout, "encoding", None) or "ascii")
817
+ except (UnicodeEncodeError, LookupError):
818
+ return plain
819
+ return fancy
801
820
 
802
821
 
803
822
  def rejection_headline(checks: Iterable[str]) -> str:
804
- """The banner's first line, naming what the failing *checks* rejected.
823
+ """The header's text, naming what the failing *checks* rejected.
805
824
 
806
825
  A developer who pushed a badly named branch reads "Commit rejected" and
807
826
  goes looking at their commit, so the line names the branch, tag or push
@@ -810,27 +829,25 @@ def rejection_headline(checks: Iterable[str]) -> str:
810
829
  """
811
830
  subjects = {_REJECTED_SUBJECTS.get(check, "Commit") for check in checks}
812
831
  if len(subjects) == 1:
813
- return f"{subjects.pop()} rejected by Commit-Check."
814
- return "Checks failed - rejected by Commit-Check."
832
+ return f"{subjects.pop()} rejected by Commit Check"
833
+ return "Rejected by Commit Check"
815
834
 
816
835
 
817
836
  @track_print_call
818
- def print_error_header(headline: str = "Commit rejected by Commit-Check.") -> None:
819
- """Print the rejection banner: *headline*, then the ASCII art.
837
+ def print_error_header(
838
+ headline: str = "Commit rejected by Commit Check", failed: int = 0
839
+ ) -> None:
840
+ """Print the one-line rejection header, then a blank line.
820
841
 
821
- :param headline: the first line, from :func:`rejection_headline`
842
+ :param headline: the text, from :func:`rejection_headline`
843
+ :param failed: how many enforced checks failed; named when given
822
844
  """
823
- print(headline.ljust(_BANNER_WIDTH))
824
- print(" ")
825
- print(r" (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) ")
826
- print(r" / ._. \ / ._. \ / ._. \ / ._. \ / ._. \ ")
827
- print(r" __\( C )/__ __\( H )/__ __\( E )/__ __\( C )/__ __\( K )/__ ")
828
- print(r"(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)")
829
- print(r" || E || || R || || R || || O || || R || ")
830
- print(r" _.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._ _.' '-' '._ ")
831
- print(r"(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)(.-./`-´\.-.)")
832
- print(r" `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ `-´ ")
833
- print(" ")
845
+ count = ""
846
+ if failed:
847
+ noun = "check" if failed == 1 else "checks"
848
+ count = f" {DIM}· {failed} {noun} failed{RESET_COLOR}"
849
+ print(f"{BOLD}{RED}{_symbol('✖', 'x')} {headline}{RESET_COLOR}{count}")
850
+ print()
834
851
 
835
852
 
836
853
  #: Terminals known to render OSC 8 hyperlinks, by ``TERM_PROGRAM``.
@@ -908,10 +925,21 @@ def print_error_message(
908
925
  label = rule_id
909
926
  if rule_id and docs_url and supports_hyperlinks():
910
927
  label = hyperlink(rule_id, docs_url)
911
- prefix = f"{YELLOW}{label}{RESET_COLOR} " if rule_id else ""
912
- verdict, colour = ("warning", YELLOW) if warn else ("failed", RED)
928
+ prefix = f"{BOLD}{label}{RESET_COLOR} " if rule_id else ""
929
+ if warn:
930
+ marker, verdict, colour = _symbol("▲", "!"), "warning", YELLOW
931
+ else:
932
+ marker, verdict, colour = _symbol("✖", "x"), "failed", RED
933
+ # A whole commit message is the value of several rules; its subject names
934
+ # the commit, and the rest would push the explanation off the screen.
935
+ first, _, rest = reason.partition("\n")
936
+ more = sum(1 for line in rest.splitlines() if line.strip())
937
+ tail = ""
938
+ if more:
939
+ tail = f" {DIM}(+{more} more line{'s' if more > 1 else ''}){RESET_COLOR}"
913
940
  print(
914
- f"{prefix}{YELLOW}{name}{RESET_COLOR} check {verdict} ==> {colour}{reason}{RESET_COLOR}"
941
+ f"{colour}{marker}{RESET_COLOR} {prefix}{YELLOW}{name}{RESET_COLOR} "
942
+ f"{verdict}: {colour}{first}{RESET_COLOR}{tail}"
915
943
  )
916
944
  if error:
917
945
  # Same trade-off as the Docs: line above — once the spec name is a
@@ -920,7 +948,7 @@ def print_error_message(
920
948
  if spec_name and spec_url and supports_hyperlinks():
921
949
  error = error.replace(f". See {spec_url}", "")
922
950
  error = error.replace(spec_name, hyperlink(spec_name, spec_url))
923
- print(error)
951
+ print(f"{_DETAIL_INDENT}{error}")
924
952
 
925
953
 
926
954
  def print_suggestion(suggest: str) -> None:
@@ -928,4 +956,6 @@ def print_suggestion(suggest: str) -> None:
928
956
  :param suggest: what message to print out
929
957
  """
930
958
  if suggest:
931
- print(f"Suggest: {GREEN}{suggest}{RESET_COLOR}")
959
+ print(
960
+ f"{_DETAIL_INDENT}{BOLD}{GREEN}Suggest:{RESET_COLOR} {GREEN}{suggest}{RESET_COLOR}"
961
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commit-check
3
- Version: 2.20.2
3
+ Version: 2.20.3
4
4
  Summary: Commit policy as code for teams and AI agents: check commit messages, branch names, authors, tags, files and AI attribution.
5
5
  Author-email: Xianpeng Shen <xianpeng.shen@gmail.com>
6
6
  License-Expression: MIT
@@ -87,7 +87,7 @@ Stop bad commits before they exist. In `.pre-commit-config.yaml`:
87
87
  ```yaml
88
88
  repos:
89
89
  - repo: https://github.com/commit-check/commit-check
90
- rev: v2.20.2
90
+ rev: v2.20.3
91
91
  hooks:
92
92
  - id: check-message
93
93
  - id: check-branch
@@ -107,7 +107,7 @@ The same `cchk.toml` drives all of them:
107
107
  |---|---|
108
108
  | GitHub, no workflow | [Install the GitHub App](https://github.com/apps/commit-check) — one check run per commit |
109
109
  | GitHub Actions | `uses: commit-check/commit-check-action@v2` — see [commit-check-action](https://github.com/commit-check/commit-check-action) |
110
- | AI agents | `--format json`, the [Python API](#ai-native-usage), or the [MCP server](https://github.com/commit-check/commit-check-mcp) |
110
+ | AI agents | The [agent skill](#agent-skill), `--format json`, the [Python API](#ai-native-usage), or the [MCP server](https://github.com/commit-check/commit-check-mcp) |
111
111
 
112
112
  ## What it checks
113
113
 
@@ -252,6 +252,21 @@ a value of the wrong type (`subject_max_length = "abc"`), or git cannot read the
252
252
  repository (not a repository, or "dubious ownership"). A `[files]` value it
253
253
  cannot use turns that rule off with a notice instead. `--dry-run` reports everything and exits `0`. More output formats: [examples](https://commit-check.com/example/).
254
254
 
255
+ ### Agent skill
256
+
257
+ [`skills/commit-check`](https://github.com/commit-check/commit-check/blob/main/skills/commit-check/SKILL.md) teaches a coding agent
258
+ to read the project's `cchk.toml`, check a message before it commits, follow
259
+ the AI attribution policy and never skip the hook. It uses the
260
+ [Agent Skills](https://agentskills.io) format, which Claude Code, GitHub
261
+ Copilot, Codex, Cursor and others load:
262
+
263
+ ```bash
264
+ npx skills add https://github.com/commit-check/commit-check --skill commit-check
265
+ ```
266
+
267
+ Or copy the folder into your agent's skills directory, such as
268
+ `.claude/skills/commit-check/` for Claude Code.
269
+
255
270
  ## Why Commit Check
256
271
 
257
272
  | | Commit Check | commitlint | GitHub Rulesets |
@@ -280,3 +295,8 @@ Questions and ideas go to [Discussions](https://github.com/commit-check/commit-c
280
295
  bugs to [Issues](https://github.com/commit-check/commit-check/issues).
281
296
  Releases follow [Semantic Versioning](https://semver.org/). Released under the
282
297
  [MIT License](https://github.com/commit-check/commit-check/blob/main/LICENSE).
298
+
299
+ Thanks to everyone who has contributed. Want to join them? Start with
300
+ [CONTRIBUTING.md](https://github.com/commit-check/commit-check/blob/main/CONTRIBUTING.md).
301
+
302
+ [![Contributors](https://contrib.rocks/image?repo=commit-check/commit-check)](https://github.com/commit-check/commit-check/graphs/contributors)
@@ -1,21 +1,21 @@
1
- commit_check/__init__.py,sha256=UAg0cSgL4QKAOc9GEbqFdoQ94JejOupRGoGgaDwIcF0,5456
1
+ commit_check/__init__.py,sha256=rzJMSqdTrxg7PmxRDY4yWhCbGkEXAT3hK4C9Y6NwxSU,5529
2
2
  commit_check/ai_policy.py,sha256=gYC3ROLgGL1TDyhPkFXkV-NiYbvMt80Qt0MFrJcbJY4,8131
3
3
  commit_check/ai_signatures.py,sha256=qPbyVndU5egHRtDtu3S2vEO5_lKyDsz1PLUWqKPMMvU,11054
4
4
  commit_check/ai_signatures_data.py,sha256=lvJDZ_-eH2RYqVn8MMry9oNXVv27u9okLawPZx_y4XA,22851
5
5
  commit_check/api.py,sha256=07bvBtV8PrhZIOwCDHiHfu_7CXsX_4U2_K2xMAucd6c,12905
6
6
  commit_check/config.py,sha256=I7yMZBJynjVUuY-GWAkuu9a59aT9fDTJsGh4znu2hDU,13941
7
7
  commit_check/config_merger.py,sha256=52m45cPOVzQnjvxgjf8pHPbK3BKVHPrvBMmtocztU-0,13707
8
- commit_check/engine.py,sha256=x4vOON6I7IEid3M7YWhgrE9spvGwfK902myKlRc0J-0,77528
8
+ commit_check/engine.py,sha256=oZZ_FnDXYh_zXF_-JoShKyosOSrAUk5bj1vCLMCZuPc,78395
9
9
  commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
10
10
  commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
11
- commit_check/main.py,sha256=Bq1ThH0KVdS1MAeNcvvBLASPEkIVD3dbyKnYF_BkTh0,30859
11
+ commit_check/main.py,sha256=5nchWwh4axbrVBkUCVtedjccEBHxm9ynKSJjSq5VcvQ,31165
12
12
  commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  commit_check/rule_builder.py,sha256=kujszrki8VKXAarrmUwOCu0Yv7QzIiu5lm5mRBAQVns,34950
14
14
  commit_check/rules_catalog.py,sha256=KtP64QRFSI_p3fRtaF1XDx3MUikIU__p1o-XmQBpSMY,12736
15
- commit_check/util.py,sha256=dCMbRKMPiysjxcOQWOIM-vJT2DdE2BsnGDgvTJsgnFs,34486
16
- commit_check-2.20.2.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
17
- commit_check-2.20.2.dist-info/METADATA,sha256=7OVmIeAbGVUFIy9IEo3H3CPjSx-A7jXP_Rw7eec1zSM,17135
18
- commit_check-2.20.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
- commit_check-2.20.2.dist-info/entry_points.txt,sha256=YMrkFGeub-3-IanV1d9qnopXVaRQM7MA9foXKW9iZ88,86
20
- commit_check-2.20.2.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
21
- commit_check-2.20.2.dist-info/RECORD,,
15
+ commit_check/util.py,sha256=pl_UZIgluo9wGdqlaePWNbULKqAlQpZd3LTHm9OytCc,35170
16
+ commit_check-2.20.3.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
17
+ commit_check-2.20.3.dist-info/METADATA,sha256=5XLZHm--1_ZKOTYJREm7M018AhFyIvSgmZwVdp6axKA,18084
18
+ commit_check-2.20.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
+ commit_check-2.20.3.dist-info/entry_points.txt,sha256=YMrkFGeub-3-IanV1d9qnopXVaRQM7MA9foXKW9iZ88,86
20
+ commit_check-2.20.3.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
21
+ commit_check-2.20.3.dist-info/RECORD,,