feat: add an argument to limit the length of commit message
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/formatand./scripts/testlocally 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
poetry run python commitizen/cli.py -n cz_conventional_commits c -l 10(orcz -n cz_conventional_commits c -l 10when merged)- ENTER (type of change is
fix:with length 5) - ENTER (no scope)
- type
123456with length 6 - ENTER (no body)
- ENTER (not breaking change)
- 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
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.
Also, great work on the detailed PR description.
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!