Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Copy link
Contributor

@kevin1kevin1k kevin1kevin1k commented Apr 21, 2024
edited by Lee-W
Loading

Description

Re-opened another PR for #191 as the long-hanging #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

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • 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

Copy link

codecov bot commented Apr 21, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

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%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @kevin1kevin1k ! Left a few nitpicks. But we're pretty close to merge this one

return cz.message(answers)

message = cz.message(answers)
message_len = len(message.partition("\n")[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know we could use partition 👀 Great job

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we strip() as well?

kevin1kevin1k reacted with thumbs up emoji
Copy link
Contributor Author

@kevin1kevin1k kevin1kevin1k Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for the suggestion!

Copy link
Member

Lee-W commented Apr 23, 2024

Also, great work on the detailed PR description.

kevin1kevin1k reacted with laugh emoji

@Lee-W Lee-W added pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check and removed pr-status: wait-for-review labels Apr 24, 2024
Copy link
Member

Lee-W commented Apr 29, 2024

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!

kevin1kevin1k reacted with rocket emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@Lee-W Lee-W Lee-W approved these changes

@woile woile Awaiting requested review from woile woile is a code owner

@noirbizarre noirbizarre Awaiting requested review from noirbizarre noirbizarre is a code owner

Assignees
No one assigned
Labels
pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check pr-status: wait-for-modification pr-status: wait-for-review
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Feature Request] Line length warning

AltStyle によって変換されたページ (->オリジナル) /