commit-check 2.20.3__py3-none-any.whl → 2.20.4__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/engine.py CHANGED
@@ -278,7 +278,7 @@ class BaseValidator(ABC):
278
278
  is unrelated — the relevant identity is the one git would record:
279
279
  ``GIT_AUTHOR_NAME`` when set (how a tool commits under its own name,
280
280
  and how the Action passes on the author of a commit it pipes in),
281
- else ``user.name``.
281
+ else ``author.name``, else ``user.name``.
282
282
 
283
283
  *Existing commit* (no ``stdin_text``, no ``commit_file``):
284
284
  the last commit is the one being validated. Use its own author
@@ -292,6 +292,7 @@ class BaseValidator(ABC):
292
292
  if context.stdin_text is not None or context.commit_file is not None:
293
293
  return (
294
294
  os.environ.get("GIT_AUTHOR_NAME", "").strip()
295
+ or get_git_config_value("author.name")
295
296
  or get_git_config_value(_USER_NAME)
296
297
  or get_commit_info("an")
297
298
  )
@@ -703,8 +704,8 @@ class AuthorValidator(BaseValidator):
703
704
  def _get_author_value(self, context: ValidationContext) -> str:
704
705
  """Get author value based on rule type.
705
706
 
706
- Checks git config first (for pre-commit validation of the configured identity),
707
- then falls back to the last commit's author info.
707
+ Reads the identity git would record for a new commit first (for
708
+ pre-commit validation), then falls back to the last commit's author.
708
709
  """
709
710
  supplied = context.piped_name
710
711
  if supplied is not None:
@@ -726,12 +727,20 @@ class AuthorValidator(BaseValidator):
726
727
  format_str = git_log_map.get(self.rule.check, "")
727
728
  return get_commit_info(format_str, context.rev) if format_str else ""
728
729
 
729
- # Try git config first (validates configured identity for new commits)
730
+ # The identity git would record for the next commit, in git's order:
731
+ # GIT_AUTHOR_NAME / GIT_AUTHOR_EMAIL (set for the hooks by
732
+ # ``git commit --author``, and by tools that commit under their own
733
+ # name), then author.name / author.email, then user.name / user.email.
730
734
  config_key = git_config_map.get(self.rule.check, "")
731
735
  if config_key:
732
- config_value = get_git_config_value(config_key)
733
- if config_value:
734
- return config_value
736
+ field = config_key.split(".")[1]
737
+ from_env = os.environ.get(f"GIT_AUTHOR_{field.upper()}", "").strip()
738
+ if from_env:
739
+ return from_env
740
+ for key in (f"author.{field}", config_key):
741
+ config_value = get_git_config_value(key)
742
+ if config_value:
743
+ return config_value
735
744
 
736
745
  # Fall back to last commit's author info
737
746
  format_str = git_log_map.get(self.rule.check, "")
@@ -1189,6 +1198,34 @@ class SignoffValidator(BaseValidator):
1189
1198
  return name, email
1190
1199
 
1191
1200
 
1201
+ #: A trailer line: a key with a hyphen (``Signed-off-by``, ``Change-Id``)
1202
+ #: or one of the common one-word keys, then a colon. A one-word key such as
1203
+ #: ``Note:`` is left as body text, since a sentence can start that way.
1204
+ _BODY_TRAILER_LINE = re.compile(
1205
+ r"^(?:[a-z]\w*-[\w-]+|Fixes|Closes|Resolves|Refs|Link|Cc|Bug)[ \t]*:",
1206
+ re.IGNORECASE,
1207
+ )
1208
+
1209
+
1210
+ def _body_without_trailers(message: str) -> str:
1211
+ """The body of *message*: what follows the subject, minus the trailer block.
1212
+
1213
+ ``git commit -s`` adds a ``Signed-off-by:`` line, so a message with only
1214
+ trailers after its subject used to count as having a body.
1215
+ """
1216
+ paragraphs = [
1217
+ p.strip() for p in re.split(r"\n[ \t]*\n", message.strip()) if p.strip()
1218
+ ]
1219
+ # The subject is the first line, even when the body follows it directly.
1220
+ rest = paragraphs[0].partition("\n")[2] if paragraphs else ""
1221
+ body = ([rest.strip()] if rest.strip() else []) + paragraphs[1:]
1222
+ if body and all(
1223
+ _BODY_TRAILER_LINE.match(ln.strip()) for ln in body[-1].splitlines()
1224
+ ):
1225
+ body = body[:-1]
1226
+ return "\n\n".join(body).strip()
1227
+
1228
+
1192
1229
  class BodyValidator(BaseValidator):
1193
1230
  """Validates that commit messages contain a body when required."""
1194
1231
 
@@ -1202,24 +1239,9 @@ class BodyValidator(BaseValidator):
1202
1239
 
1203
1240
  self._checked_value = message
1204
1241
 
1205
- # Split message into lines and check if there's content after the subject
1206
- lines = message.strip().split("\n")
1207
-
1208
- # Filter out empty lines
1209
- non_empty_lines = [line.strip() for line in lines if line.strip()]
1210
-
1211
- # If there's more than just the subject line, we have a body
1212
- if len(non_empty_lines) > 1:
1242
+ if _body_without_trailers(message):
1213
1243
  return ValidationResult.PASS
1214
1244
 
1215
- # Check if there's content after the first line (even if separated by empty lines)
1216
- # Unreachable: the message is stripped, so two or more lines always
1217
- # hold two non-empty ones and have passed above.
1218
- if len(lines) > 1: # pragma: no cover
1219
- body_content = "\n".join(lines[1:]).strip()
1220
- if body_content:
1221
- return ValidationResult.PASS
1222
-
1223
1245
  self._print_failure(message)
1224
1246
  return ValidationResult.FAIL
1225
1247
 
@@ -222,6 +222,22 @@ def _check_booleans(config: dict[str, Any]) -> None:
222
222
  )
223
223
 
224
224
 
225
+ def _check_author_lists(config: dict[str, Any]) -> None:
226
+ """Make each ``ignore_authors`` a list, or refuse it.
227
+
228
+ A string such as ``"renovate[bot], Bot User"`` was tested with ``in``,
229
+ which on a string is a substring match: any author whose name was part
230
+ of it, ``bot`` or ``Bot``, skipped every check. A comma-separated string
231
+ is now split, as ``--ignore-authors`` and ``CCHK_IGNORE_AUTHORS`` split it.
232
+ """
233
+ for section in ("commit", "branch"):
234
+ values = config.get(section)
235
+ if isinstance(values, dict) and "ignore_authors" in values:
236
+ values["ignore_authors"] = _string_list(
237
+ values, "ignore_authors", [], f"[{section}] ignore_authors"
238
+ )
239
+
240
+
225
241
  class RuleBuilder:
226
242
  """Builds validation rules from config and catalog entries."""
227
243
 
@@ -233,6 +249,7 @@ class RuleBuilder:
233
249
  self.tag_config = config.get("tag", {})
234
250
  self.files_config = config.get("files", {})
235
251
  _check_booleans(config)
252
+ _check_author_lists(config)
236
253
  self.warn_checks = self._resolve_warn_list(config.get("warn", []))
237
254
 
238
255
  def build_all_rules(self) -> list[ValidationRule]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commit-check
3
- Version: 2.20.3
3
+ Version: 2.20.4
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.3
90
+ rev: v2.20.4
91
91
  hooks:
92
92
  - id: check-message
93
93
  - id: check-branch
@@ -5,17 +5,17 @@ commit_check/ai_signatures_data.py,sha256=lvJDZ_-eH2RYqVn8MMry9oNXVv27u9okLawPZx
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=oZZ_FnDXYh_zXF_-JoShKyosOSrAUk5bj1vCLMCZuPc,78395
8
+ commit_check/engine.py,sha256=O1h3X9C297GUFJvXXj2B8Ke8Hmf9qX8QtdtO3cMuri0,79358
9
9
  commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
10
10
  commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
11
11
  commit_check/main.py,sha256=5nchWwh4axbrVBkUCVtedjccEBHxm9ynKSJjSq5VcvQ,31165
12
12
  commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- commit_check/rule_builder.py,sha256=kujszrki8VKXAarrmUwOCu0Yv7QzIiu5lm5mRBAQVns,34950
13
+ commit_check/rule_builder.py,sha256=N_3qkZpLG1Yb_hUTMFNro2w7VsWtXLGjjyGPEOEPs88,35708
14
14
  commit_check/rules_catalog.py,sha256=KtP64QRFSI_p3fRtaF1XDx3MUikIU__p1o-XmQBpSMY,12736
15
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,,
16
+ commit_check-2.20.4.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
17
+ commit_check-2.20.4.dist-info/METADATA,sha256=hHNsaefNqZv9iNVR6Scnl6GGV_ntjyFnyRYhAatiwl8,18084
18
+ commit_check-2.20.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
+ commit_check-2.20.4.dist-info/entry_points.txt,sha256=YMrkFGeub-3-IanV1d9qnopXVaRQM7MA9foXKW9iZ88,86
20
+ commit_check-2.20.4.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
21
+ commit_check-2.20.4.dist-info/RECORD,,