feat: configurable commit validation
Allow clients overriding the BaseCommitizen object to have more custom commit message validation beyond just matching a regex schema. This lets clients have custom error messages and more intelligent pattern matching.
Description
This change lets users add certain things like bad word filters or more intelligent task ID listing (for example, make sure one or more IDs appears in the commit message, and in no particular order).
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
Override validate_commit or validate_commits in BaseCommitizen for commit validation functions that are expressible in Python, and not just by a regular expression.
Steps to Test This Pull Request
Run the test_check_custom_validation_succeeds and test_check_custom_validation_fails test cases in tests/commands/test_check_command.py.
Additional context
I noticed during my development that the test_check_command_with_empty_range case was failing with the error:
commitizen.exceptions.GitCommandError: fatal: ambiguous argument 'master..master': unknown revision or path not in the working tree.
instead of generating its expected output. I did my best to make sure that this failure wasn't related to my changes, since it also reproduced when I ran the test suite against master. It could just be an issue with my local environment.
Codecov Report
Base: 97.92% // Head: 98.01% // Increases project coverage by +0.08% :tada:
Coverage data is based on head (
006026a) compared to base (db42a95). Patch coverage: 91.89% of modified lines in pull request are covered.
:exclamation: Current head 006026a differs from pull request most recent head bbe424a. Consider uploading reports for the commit bbe424a to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #648 +/- ##
==========================================
+ Coverage 97.92% 98.01% +0.08%
==========================================
Files 35 39 +4
Lines 1252 1710 +458
==========================================
+ Hits 1226 1676 +450
- Misses 26 34 +8
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 98.01% <91.89%> (+0.08%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| commitizen/commands/init.py | 87.93% <84.00%> (-3.74%) |
:arrow_down: |
| commitizen/cz/customize/customize.py | 95.34% <96.29%> (+0.26%) |
:arrow_up: |
| commitizen/__version__.py | 100.00% <100.00%> (ø) |
|
| commitizen/commands/changelog.py | 98.86% <100.00%> (ø) |
|
| commitizen/commands/check.py | 100.00% <100.00%> (ø) |
|
| commitizen/cz/__init__.py | 100.00% <100.00%> (ø) |
|
| commitizen/cz/base.py | 100.00% <100.00%> (ø) |
|
| commitizen/cz/customize/__init__.py | 100.00% <100.00%> (ø) |
|
| commitizen/exceptions.py | 100.00% <100.00%> (ø) |
|
| commitizen/changelog.py | 99.43% <0.00%> (ø) |
|
| ... and 3 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
I'm not sure why the patch check is failing - it's complaining about a lack of test code coverage in a file that I didn't touch.
It seems the latest version didn't pass the CI. @protonjohn could you please take a look? Thanks!