Skip to content

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
wants to merge 6 commits into
base: v4-9-0-test
Choose a base branch
from

Conversation

Narwhal-fish
Copy link

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

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v4-9-0-test@d417cf7). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             v4-9-0-test    #1574   +/-   ##
==============================================
  Coverage               ?   98.09%           
==============================================
  Files                  ?       58           
  Lines                  ?     2684           
  Branches               ?        0           
==============================================
  Hits                   ?     2633           
  Misses                 ?       51           
  Partials               ?        0           
Flag Coverage Δ
unittests 98.09% <100.00%> (?)

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
@Narwhal-fish Narwhal-fish reopened this Aug 12, 2025
@Narwhal-fish
Copy link
Author

Sorry, I accidentally closed this pull request.

@Lee-W
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
@Narwhal-fish
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.

@Lee-W
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

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

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

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

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.

@@ -108,6 +109,7 @@ class Settings(TypedDict, total=False):
"always_signoff": False,
"template": None, # default provided by plugin
"extras": {},
"message_length_limit": 0, # 0 for no limit
Copy link
Contributor

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants