git-commit-guard 0.22.3__py3-none-any.whl → 0.23.1__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.
@@ -146,6 +146,10 @@ class Result:
146
146
  def ok(self):
147
147
  return not any(lvl == Level.ERROR for _, lvl, _ in self.errors)
148
148
 
149
+ @property
150
+ def noteworthy(self):
151
+ return any(lvl in (Level.ERROR, Level.WARN) for _, lvl, _ in self.errors)
152
+
149
153
 
150
154
  def _ensure_nltk_data():
151
155
  _download_if_missing("taggers/averaged_perceptron_tagger_eng")
@@ -227,22 +231,22 @@ def check_imperative(desc, result):
227
231
  if not tokens:
228
232
  return
229
233
  first = tokens[0]
230
- if _NON_IMPERATIVE_SUFFIX_RE.search(first):
234
+ base = wordnet.morphy(first, wordnet.VERB)
235
+ if base is not None and base != first:
231
236
  result.error(
232
- f"expected imperative verb, got '{first}' (non-imperative suffix)",
237
+ f"expected imperative verb, got '{first}' (inflected form of '{base}')",
233
238
  check=Check.IMPERATIVE,
234
239
  )
235
240
  return
236
- base = wordnet.morphy(first, wordnet.VERB)
237
- if base is not None and base != first:
241
+ if base is None and _NON_IMPERATIVE_SUFFIX_RE.search(first):
238
242
  result.error(
239
- f"expected imperative verb, got '{first}' (inflected form of '{base}')",
243
+ f"expected imperative verb, got '{first}' (non-imperative suffix)",
240
244
  check=Check.IMPERATIVE,
241
245
  )
242
246
  return
243
247
  tagged = nltk.pos_tag(["to", *tokens])
244
248
  if tagged[1][1] != "VB":
245
- if wordnet.morphy(first, wordnet.VERB) == first:
249
+ if base == first:
246
250
  return
247
251
  if "-" in first:
248
252
  hyphen_prefix, hyphen_base = first.split("-", 1)
@@ -565,6 +569,7 @@ class Args:
565
569
  subject_pattern: re.Pattern | None
566
570
  output: OutputFormat
567
571
  output_file: Path | None
572
+ quiet: bool
568
573
 
569
574
 
570
575
  def _resolve_enabled(args, config, parser):
@@ -662,7 +667,7 @@ def _parse_checks(parser, value):
662
667
  parser.error(str(e))
663
668
 
664
669
 
665
- def _parse_args(): # noqa: PLR0915 Too many statements (59 > 50)
670
+ def _parse_args(): # noqa: PLR0915 Too many statements (60 > 50)
666
671
  checks_list = ",".join(sorted(Check))
667
672
  parser = ArgumentParser(description="conventional commit checker")
668
673
  parser.add_argument("rev", nargs="?", default=None)
@@ -761,6 +766,13 @@ def _parse_args(): # noqa: PLR0915 Too many statements (59 > 50)
761
766
  metavar="FILE",
762
767
  help="write JSONL results to FILE (text still goes to stdout)",
763
768
  )
769
+ parser.add_argument(
770
+ "-q",
771
+ "--quiet",
772
+ action="store_true",
773
+ default=False,
774
+ help="suppress output for commits without errors or warnings",
775
+ )
764
776
  args = parser.parse_args()
765
777
  config = _load_config()
766
778
  enabled = _resolve_enabled(args, config, parser)
@@ -823,6 +835,7 @@ def _parse_args(): # noqa: PLR0915 Too many statements (59 > 50)
823
835
  subject_pattern=subject_pattern,
824
836
  output=OutputFormat(args.output),
825
837
  output_file=args.output_file,
838
+ quiet=args.quiet,
826
839
  )
827
840
 
828
841
 
@@ -838,7 +851,9 @@ def _jsonl_record(result, sha, subject):
838
851
  }
839
852
 
840
853
 
841
- def _report_jsonl(result, sha, subject):
854
+ def _report_jsonl(result, sha, subject, *, quiet=False):
855
+ if quiet and not result.noteworthy:
856
+ return 0
842
857
  print(json.dumps(_jsonl_record(result, sha, subject)))
843
858
  return 0 if result.ok else 1
844
859
 
@@ -847,7 +862,9 @@ def _write_jsonl_record(result, sha, subject, file):
847
862
  file.write(json.dumps(_jsonl_record(result, sha, subject)) + "\n")
848
863
 
849
864
 
850
- def _report_text(result):
865
+ def _report_text(result, *, quiet=False):
866
+ if quiet and not result.noteworthy:
867
+ return 0
851
868
  color = sys.stdout.isatty()
852
869
  for check, level, msg in result.errors:
853
870
  prefix = f"[{check}] " if check else ""
@@ -892,6 +909,14 @@ def _run_checks(args, rev, message, result):
892
909
  check_signature(rev, result)
893
910
 
894
911
 
912
+ def _report_commit(args, result, sha, subject):
913
+ if args.output == OutputFormat.JSONL:
914
+ return _report_jsonl(result, sha, subject, quiet=args.quiet)
915
+ if args.rev_range and (not args.quiet or result.noteworthy):
916
+ print(f"{sha[:7]} {subject}")
917
+ return _report_text(result, quiet=args.quiet)
918
+
919
+
895
920
  def main():
896
921
  args = _parse_args()
897
922
 
@@ -911,13 +936,8 @@ def main():
911
936
  subject = message.split("\n")[0]
912
937
  result = Result()
913
938
  _run_checks(args, rev, message, result)
914
- if args.output == OutputFormat.JSONL:
915
- if _report_jsonl(result, rev, subject) != 0:
916
- failed = True
917
- else:
918
- print(f"{rev[:7]} {subject}")
919
- if _report_text(result) != 0:
920
- failed = True
939
+ if _report_commit(args, result, rev, subject) != 0:
940
+ failed = True
921
941
  if out_file:
922
942
  _write_jsonl_record(result, rev, subject, out_file)
923
943
  return 1 if failed else 0
@@ -927,6 +947,4 @@ def main():
927
947
  _run_checks(args, args.rev, args.message, result)
928
948
  if out_file:
929
949
  _write_jsonl_record(result, args.rev, subject, out_file)
930
- if args.output == OutputFormat.JSONL:
931
- return _report_jsonl(result, args.rev, subject)
932
- return _report_text(result)
950
+ return _report_commit(args, result, args.rev, subject)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-commit-guard
3
- Version: 0.22.3
3
+ Version: 0.23.1
4
4
  Summary: Opinionated conventional commit message linter with imperative mood detection
5
5
  Project-URL: Homepage, https://github.com/benner/commit-guard
6
6
  Project-URL: Repository, https://github.com/benner/commit-guard
@@ -316,7 +316,7 @@ COMMIT_GUARD_GIT_TIMEOUT=30 commit-guard --range origin/main..HEAD
316
316
  In GitHub Actions, set it at the step or job level:
317
317
 
318
318
  ```yaml
319
- - uses: benner/commit-guard@v0.22.3
319
+ - uses: benner/commit-guard@v0.23.1
320
320
  env:
321
321
  COMMIT_GUARD_GIT_TIMEOUT: 30
322
322
  with:
@@ -352,6 +352,22 @@ misconfigured range specs in CI. Use `--allow-empty` to exit 0 instead:
352
352
  commit-guard --range origin/main..HEAD --allow-empty
353
353
  ```
354
354
 
355
+ ### Quiet mode
356
+
357
+ Use `--quiet` (or `-q`) to suppress output for commits that have nothing to
358
+ report — only commits with errors or warnings are printed. On a long range
359
+ this leaves exactly the offending commits in the output; a fully compliant
360
+ range prints nothing and exits 0:
361
+
362
+ ```bash
363
+ commit-guard --range origin/main..HEAD --quiet
364
+ ```
365
+
366
+ Quiet mode applies to single-commit and range mode, in both text and
367
+ `--output jsonl` formats. Exit codes are unchanged, so it composes with CI
368
+ gating. `--output-file` is not affected — the file always receives the
369
+ complete record stream.
370
+
355
371
  ### Machine-readable output
356
372
 
357
373
  Use `--output jsonl` to emit one JSON line per commit to stdout instead of the
@@ -400,7 +416,7 @@ steps:
400
416
  - uses: actions/checkout@v4
401
417
  with:
402
418
  fetch-depth: 0
403
- - uses: benner/commit-guard@v0.22.3
419
+ - uses: benner/commit-guard@v0.23.1
404
420
  ```
405
421
 
406
422
  Check all commits in a pull request:
@@ -416,7 +432,7 @@ jobs:
416
432
  - uses: actions/checkout@v4
417
433
  with:
418
434
  fetch-depth: 0
419
- - uses: benner/commit-guard@v0.22.3
435
+ - uses: benner/commit-guard@v0.23.1
420
436
  with:
421
437
  range: ${{ env.PR_BASE }}..${{ env.PR_HEAD }}
422
438
  ```
@@ -424,7 +440,7 @@ jobs:
424
440
  Check a specific commit SHA (mirrors the positional CLI argument):
425
441
 
426
442
  ```yaml
427
- - uses: benner/commit-guard@v0.22.3
443
+ - uses: benner/commit-guard@v0.23.1
428
444
  with:
429
445
  rev: ${{ github.sha }}
430
446
  ```
@@ -442,7 +458,7 @@ jobs:
442
458
  - uses: actions/checkout@v4
443
459
  with:
444
460
  fetch-depth: 0
445
- - uses: benner/commit-guard@v0.22.3
461
+ - uses: benner/commit-guard@v0.23.1
446
462
  with:
447
463
  range: ${{ env.PR_BASE }}..${{ env.PR_HEAD }}
448
464
  disable: signed-off,signature
@@ -462,7 +478,7 @@ jobs:
462
478
  When `output-file` is set the action exposes the path as an output:
463
479
 
464
480
  ```yaml
465
- - uses: benner/commit-guard@v0.22.3
481
+ - uses: benner/commit-guard@v0.23.1
466
482
  id: cg
467
483
  with:
468
484
  range: ${{ env.PR_BASE }}..${{ env.PR_HEAD }}
@@ -478,7 +494,7 @@ Add to your `.pre-commit-config.yaml`:
478
494
  ---
479
495
  repos:
480
496
  - repo: https://github.com/benner/commit-guard
481
- rev: v0.22.3
497
+ rev: v0.23.1
482
498
  hooks:
483
499
  - id: commit-guard
484
500
  - id: commit-guard-signature
@@ -0,0 +1,6 @@
1
+ git_commit_guard/__init__.py,sha256=tDxuZattxvqrIESBLwYux9fbgwC4O4Qf2HcuAYEBv6g,30125
2
+ git_commit_guard-0.23.1.dist-info/METADATA,sha256=i3vZ0BoJ8ws0qwtXIakGZZUxIkKfERGmpciNys1kBfk,16043
3
+ git_commit_guard-0.23.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
4
+ git_commit_guard-0.23.1.dist-info/entry_points.txt,sha256=24HK4TwCgn3tSQHOWnGE6zJK6nvg7EMAut7VHe9nuH4,55
5
+ git_commit_guard-0.23.1.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
6
+ git_commit_guard-0.23.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.30.1
2
+ Generator: hatchling 1.31.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- git_commit_guard/__init__.py,sha256=NbdRkWxWEzt3-uunql1FYl4vA2Vt7ULbDI1i0yNRLXg,29621
2
- git_commit_guard-0.22.3.dist-info/METADATA,sha256=PgMzlU9yXNHl3HvCI6-qPxECULeOxJqfX982gbGRvYM,15462
3
- git_commit_guard-0.22.3.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
4
- git_commit_guard-0.22.3.dist-info/entry_points.txt,sha256=24HK4TwCgn3tSQHOWnGE6zJK6nvg7EMAut7VHe9nuH4,55
5
- git_commit_guard-0.22.3.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
6
- git_commit_guard-0.22.3.dist-info/RECORD,,