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 config option for line length warning #1574

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

Open
Narwhal-fish wants to merge 5 commits into commitizen-tools:master
base: master
Choose a base branch
Loading
from Narwhal-fish:feat/Add-config-option-for-line-length-warning

Conversation

Copy link

@Narwhal-fish Narwhal-fish commented Aug 12, 2025

Description

This PR implements configuration file support for the message_length_limit option, addressing issue #1571 . Previously, users could only set commit message length limits via command-line arguments (-l/--message-length-limit). Now they can define a default limit in their configuration file.

Checklist

Code Changes

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run poetry doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external) in the documentation

Expected Behavior

Users can now set default commit message length limits in their configuration file:

[tool.commitizen]
message_length_limit = 72

Steps to Test This Pull Request

  1. Test Configuration File Support
# Add the following to your pyproject.toml:
[tool.commitizen]
message_length_limit = 30
# Test with long message (should fail)
cz check -m "fix: this is a very long commit message that exceeds 30 characters"
# Test with short message (should pass) 
cz check -m "fix: short message"
  1. Test CLI Override
# CLI argument should override config setting
cz check -m "fix: this message is longer than 30 chars but shorter than 60" -l 60
# Disable limit with CLI
cz check -m "fix: very long message that would normally fail config limit" -l 0

Additional Context

Copy link

codecov bot commented Aug 12, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.25%. Comparing base (120d514) to head (e70271b).
⚠️ Report is 807 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@
## master #1574 +/- ##
==========================================
+ Coverage 97.33% 98.25% +0.91% 
==========================================
 Files 42 58 +16 
 Lines 2104 2695 +591 
==========================================
+ Hits 2048 2648 +600 
+ Misses 56 47 -9 
Flag Coverage Δ
unittests 98.25% <100.00%> (+0.91%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Lee-W Lee-W added this to the 4.9.0 milestone Aug 12, 2025
@Lee-W Lee-W changed the base branch from master to v4-9-0-test August 12, 2025 06:51
Copy link
Author

Sorry, I accidentally closed this pull request.

Lee-W reacted with thumbs up emoji

Copy link
Member

Lee-W commented Aug 12, 2025

let's rebase from v4-9-test

@Narwhal-fish Narwhal-fish force-pushed the feat/Add-config-option-for-line-length-warning branch from 9a2622f to c300b70 Compare August 12, 2025 17:58
Copy link
Author

I have rebased my branch onto v4-9-0.
I’m not very familiar with Git, so please let me know if I missed anything.

Copy link
Member

Lee-W commented Aug 13, 2025

I have rebased my branch onto v4-9-0. I’m not very familiar with Git, so please let me know if I missed anything.

You've done it perfectly 🙂 I'll take a look when bandwidth allow

Narwhal-fish reacted with thumbs up emoji

Copy link
Contributor

@bearomorphism bearomorphism left a comment

Choose a reason for hiding this comment

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

Thanks! A few suggestion:

raise CommitMessageLengthExceededError(
f"commit validation: failed!\n"
f"commit message length exceeds the limit.\n"
f'commit "": "{commit_msg}"\n'
Copy link
Contributor

@bearomorphism bearomorphism Aug 13, 2025

Choose a reason for hiding this comment

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

what does "" mean here

Copy link
Contributor

@bearomorphism bearomorphism Aug 13, 2025

Choose a reason for hiding this comment

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

I guess you forgot to put something like commit hash here in the error message

Copy link
Author

@Narwhal-fish Narwhal-fish Aug 13, 2025
edited
Loading

Choose a reason for hiding this comment

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

You’re right. I referenced the error handling for invalid messages and forgot to add the commit hash. I’ll make the correction.

"always_signoff": False,
"template": None, # default provided by plugin
"extras": {},
"message_length_limit": 0, # 0 for no limit
Copy link
Contributor

@bearomorphism bearomorphism Aug 13, 2025

Choose a reason for hiding this comment

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

Why don't we just use None for no limit?

Copy link
Author

@Narwhal-fish Narwhal-fish Aug 13, 2025

Choose a reason for hiding this comment

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

Initially, I set it to 0 simply because I thought commit messages wouldn't have a 0-character scenario, but your suggestion of using None is more clear. I've made this change accordingly.

Copy link
Contributor

@bearomorphism bearomorphism Sep 28, 2025

Choose a reason for hiding this comment

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

I see why you used 0 for no limit. It is because you wanted to align with the original design.

I will probably be a breaking change if we change the default value of this option. wdyt @Lee-W ?

Copy link
Member

Lee-W commented Aug 24, 2025

we might need to resolve the conflict first. Thanks!

@Lee-W Lee-W modified the milestones: 4.9.0, 4.10.0 Sep 9, 2025
@Lee-W Lee-W deleted the branch commitizen-tools:master September 9, 2025 06:09
@Lee-W Lee-W closed this Sep 9, 2025
@Lee-W Lee-W reopened this Sep 9, 2025
@Lee-W Lee-W changed the base branch from v4-9-0-test to master September 9, 2025 06:18
Copy link
Contributor

Hi @Narwhal-fish , could you help to rebase your branch when you have a moment?

You can run

git fetch upstream
git rebase upstream master -i

and then drop all commits but yours.

Narwhal-fish reacted with thumbs up emoji

@Narwhal-fish Narwhal-fish force-pushed the feat/Add-config-option-for-line-length-warning branch from db902f9 to de2e785 Compare September 23, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

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

@Lee-W Lee-W Awaiting requested review from Lee-W Lee-W is a code owner

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

1 more reviewer

@bearomorphism bearomorphism bearomorphism left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
Projects
None yet
Milestone
4.11.0
Development

Successfully merging this pull request may close these issues.

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