commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

feat: add an argument to limit the length of commit message

Open kevin1kevin1k opened this issue 1 year ago • 2 comments

Description

Re-opened another PR for #191 as the long-hanging https://github.com/commitizen-tools/commitizen/pull/557 has been closed. Check if the length of commit message exceeds the specified limit. The limit can be specified via, for example, -l 72 or --message-length-limit 72.

Checklist

  • [x] Add test cases to all the changes you introduce
  • [x] Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • [x] Test the changes on the local machine manually
  • [x] Update the documentation for the changes

Expected behavior

If one runs cz commit -l/--message-length-limit N, the commit would fail (with the exception CommitMessageLengthExceededError) when the message is longer than N characters. Note that for ConventionalCommitsCz, the limit applies only from the prefix to the subject. In other words, everything after the first line (the body and the footer) are not counted in the length.

Steps to Test This Pull Request

  1. poetry run python commitizen/cli.py -n cz_conventional_commits c -l 10 (or cz -n cz_conventional_commits c -l 10 when merged)
  2. ENTER (type of change is fix: with length 5)
  3. ENTER (no scope)
  4. type 123456 with length 6
  5. ENTER (no body)
  6. ENTER (not breaking change)
  7. ENTER (no footer)

As 5+6 = 11 > 10 the process should exit with message Length of commit message exceeds limit (11/10) and error code 32.

Additional context

Closes: #191

kevin1kevin1k avatar Apr 21 '24 08:04 kevin1kevin1k

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.58%. Comparing base (120d514) to head (39792f2). Report is 297 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1076      +/-   ##
==========================================
+ Coverage   97.33%   97.58%   +0.24%     
==========================================
  Files          42       55      +13     
  Lines        2104     2486     +382     
==========================================
+ Hits         2048     2426     +378     
- Misses         56       60       +4     
Flag Coverage Δ
unittests 97.58% <100.00%> (+0.24%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 21 '24 09:04 codecov[bot]

Also, great work on the detailed PR description.

Lee-W avatar Apr 23 '24 14:04 Lee-W

Great job @kevin1kevin1k !

@woile @noirbizarre I'm planing to merge this one these days. Let me know if you want to take a deeper look. Thanks!

Lee-W avatar Apr 29 '24 02:04 Lee-W