-
-
Couldn't load subscription status.
- Fork 302
feat: add custom validation #1236
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
base: master
Are you sure you want to change the base?
feat: add custom validation #1236
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1236 +/- ##
==========================================
+ Coverage 97.33% 97.93% +0.59%
==========================================
Files 42 58 +16
Lines 2104 2713 +609
==========================================
+ Hits 2048 2657 +609
Misses 56 56
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fbf3813 to
7bd16c3
Compare
|
@Lee-W I was wondering if you had any input to this PR? |
|
I'll be mostly out till at least mid-Oct, will try to check in depth after that. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I love this idea! left a few improvement suggestions
|
I'll be mostly out for the following month. Will try to take a look when I'm back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long. Some nitpicks. but we're close to merge I think!
commitizen/cz/base.py
Outdated
| if max_msg_length: | ||
| msg_len = len(commit_msg.partition("\n")[0].strip()) | ||
| if msg_len > max_msg_length: | ||
| return ValidationResult(False, []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably would like to add errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an error message here and append all errors in InvalidCommitMessageError.
Let me know if that was your intention.
commitizen/cz/base.py
Outdated
| msg_len = len(commit_msg.partition("\n")[0].strip()) | ||
| if msg_len > max_msg_length: | ||
| return ValidationResult(False, []) | ||
| return ValidationResult(bool(re.match(pattern, commit_msg)), []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and probably here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added error message here too.
| if any(map(commit_msg.startswith, allowed_prefixes)): | ||
| return ValidationResult(True, []) | ||
| if max_msg_length: | ||
| msg_len = len(commit_msg.partition("\n")[0].strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want user perceived length? Unicode characters may take more than 1 char, if we want the user perceived length we'll need to measure "graphemes". For example, an emoji like 🎏 may take up to 4 chars. And languages outside english may have the same problem.
What do you think @Lee-W ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are not many library options in python:
- uniseg-py, last release: Jan 23, 2025, version 0.10.0, no dependencies, typed, supports Unicode 16
- grapheme, relatively popular, last release 2020, no dependencies, no typed, supports Unicode 13
- pyuegc, last release Jan 14, 2025, version 16.0.3, not sure I like the code, no typing. Supports Unicode 16.0.3
- unicode-segmentation-py bindings to the well-maintained rust version, last release Mar 22, 2025
Tracking issue on cpython:
python/cpython#74902
Description
This PR adds functionality to customise the commit message validation and to format the
InvalidCommitMessageErrorto give better/more detailed feedback to the user.Checklist
./scripts/formatand./scripts/testlocally to ensure this change passes linter check and testExpected behavior
The developer of a custom commitizen class can override the
validate_commit_messageandformat_error_messagemethods to perform more complex commit message format checks then just a regex match and give more detailed feedback on failure.Steps to Test This Pull Request
Run the the
test_check_command_with_custom_validator_succeedandtest_check_command_with_custom_validator_failtests intest_check_command.py.Additional context
This PR implements and fixes the comments from #648.