feat: add custom validation
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
- [x] Add test cases to all the changes you introduce
- [x] Run
./scripts/formatand./scripts/testlocally to ensure this change passes linter check and test - [x] Test the changes on the local machine manually
- [x] 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 Report
:white_check_mark: All modified and coverable lines are covered by tests.
:warning: Please upload report for BASE (v4-11-0@1d0f6cb). Learn more about missing BASE report.
Additional details and impacted files
@@ Coverage Diff @@
## v4-11-0 #1236 +/- ##
==========================================
Coverage ? 98.64%
==========================================
Files ? 60
Lines ? 2664
Branches ? 0
==========================================
Hits ? 2628
Misses ? 36
Partials ? 0
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 98.64% <100.00%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@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!
I'll be mostly out for the following month. Will try to take a look when I'm back.
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
Hey @benediktziegler , I think we're almost good to merge this one. But could you please help us rebase from the branch v4-11-0? I tried a bit, but I'm worried I might mess it up.
@Lee-W I agree the merging was a bit messy and seems to even contain unwanted changes in the end. I propose I force push the squashed changes from this branch into this PR: https://github.com/benediktziegler/commitizen/tree/feature/custom-validation-clean instead. Do you have any objections?
Or we merge this one instead: https://github.com/commitizen-tools/commitizen/pull/1680
either way works perfect :) I'll take one final look at the other draft PR, if your force push didn't beat me haha
Both are the same now, so I drop the draft PR.
Potential conflict with #1657.
Super! Thanks so much!