commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

feat: add custom validation

Open benediktziegler opened this issue 1 year ago • 4 comments

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/format and ./scripts/test locally 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.

benediktziegler avatar Sep 13 '24 12:09 benediktziegler

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.

codecov[bot] avatar Sep 13 '24 12:09 codecov[bot]

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

benediktziegler avatar Sep 20 '24 06:09 benediktziegler

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

Lee-W avatar Sep 25 '24 00:09 Lee-W

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

Lee-W avatar Dec 06 '24 15:12 Lee-W

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

Lee-W avatar Nov 19 '25 03:11 Lee-W

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 avatar Nov 30 '25 03:11 Lee-W

@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

benediktziegler avatar Dec 01 '25 08:12 benediktziegler

either way works perfect :) I'll take one final look at the other draft PR, if your force push didn't beat me haha

Lee-W avatar Dec 01 '25 11:12 Lee-W

Both are the same now, so I drop the draft PR.

Potential conflict with #1657.

benediktziegler avatar Dec 02 '25 07:12 benediktziegler

Super! Thanks so much!

Lee-W avatar Dec 03 '25 02:12 Lee-W