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 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

Open
benediktziegler wants to merge 12 commits into commitizen-tools:master
base: master
Choose a base branch
Loading
from benediktziegler:feature/custom-validation

Conversation

Copy link

@benediktziegler benediktziegler commented Sep 13, 2024

Description

This PR adds functionality to customise the commit message validation and to format the InvalidCommitMessageError to give better/more detailed feedback to the user.

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

The developer of a custom commitizen class can override the validate_commit_message and format_error_message methods 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_succeed and test_check_command_with_custom_validator_fail tests in test_check_command.py.

Additional context

This PR implements and fixes the comments from #648.

noirbizarre and Lee-W reacted with heart emoji
Copy link

codecov bot commented Sep 13, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.55%. Comparing base (120d514) to head (866101a).
Report is 538 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@
## master #1236 +/- ##
==========================================
+ Coverage 97.33% 97.55% +0.21% 
==========================================
 Files 42 55 +13 
 Lines 2104 2618 +514 
==========================================
+ Hits 2048 2554 +506 
- Misses 56 64 +8 
Flag Coverage Δ
unittests 97.55% <100.00%> (+0.21%) ⬆️

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
Author

@Lee-W I was wondering if you had any input to this PR?

Copy link
Member

Lee-W commented Sep 25, 2024

I'll be mostly out till at least mid-Oct, will try to check in depth after that. Thanks!

benediktziegler reacted with thumbs up emoji

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.

Overall, I love this idea! left a few improvement suggestions

benediktziegler reacted with thumbs up emoji
Copy link
Member

Lee-W commented Dec 6, 2024

I'll be mostly out for the following month. Will try to take a look when I'm back.

benediktziegler reacted with thumbs up emoji

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.

Sorry for taking so long. Some nitpicks. but we're close to merge I think!

@@ -1,4 +1,4 @@
Customizing commitizen is not hard at all.
from commitizen import BaseCommitizenCustomizing commitizen is not hard at all.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
from commitizen import BaseCommitizenCustomizing commitizen is not hard at all.
Customizing commitizen is not hard at all.

Copy link
Member

Choose a reason for hiding this comment

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

looks like a typo

if max_msg_length:
msg_len = len(commit_msg.partition("\n")[0].strip())
if msg_len > max_msg_length:
return ValidationResult(False, [])
Copy link
Member

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?

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)), [])
Copy link
Member

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?

@Lee-W Lee-W added type: feature A new enhacement proposal and removed pr-status: wait-for-review labels Jan 30, 2025
@Lee-W Lee-W added this to the 4.10.0 milestone Sep 9, 2025
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 left review comments

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

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

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

Assignees
No one assigned
Projects
None yet
Milestone
4.10.0
Development

Successfully merging this pull request may close these issues.

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