Skip to content

Conversation

@benediktziegler
Copy link

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.

@codecov
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1236      +/-   ##
==========================================
+ Coverage   97.33%   98.68%   +1.34%     
==========================================
  Files          42       60      +18     
  Lines        2104     2664     +560     
==========================================
+ Hits         2048     2629     +581     
+ Misses         56       35      -21     
Flag Coverage Δ
unittests 98.68% <100.00%> (+1.34%) ⬆️

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.

@benediktziegler benediktziegler force-pushed the feature/custom-validation branch from fbf3813 to 7bd16c3 Compare September 13, 2024 13:57
@benediktziegler
Copy link
Author

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

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

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

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

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!

@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
allow_abort: bool,
allowed_prefixes: list[str],
max_msg_length: int,
) -> tuple[bool, list]:
Copy link
Member

Choose a reason for hiding this comment

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

Let's also use ValidationResult here

mocker.patch.object(sys, "argv", testargs)
mocker.patch(
"commitizen.commands.check.open",
mocker.mock_open(read_data="ABC-123 add commitizen pre-commit hook"),
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it obvious wrong. I read a few time to notice the missing :



@pytest.fixture
def use_cz_custom_validator(mocker):
Copy link
Member

Choose a reason for hiding this comment

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

nit: If it's only used in tests/commands/test_check_command.py, we probably can move it there.

@Lee-W Lee-W changed the base branch from master to v4-11-0 November 19, 2025 03:20
@Lee-W
Copy link
Member

Lee-W commented Nov 19, 2025

Hey @benediktziegler , I left a few nits, but overall this PR is great! We're super close to merging.
We'll include it in 4.11. Hopefully to release some time early Dec

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants