Skip to content

Conversation

AdrianDC
Copy link
Contributor

Description

Supported APIs: Common Python, commitizen.cz.utils.* functions

Example YAML configurations:

commitizen:
  name: cz_customize
  customize:
    questions:
      - ...
      - type: input
        name: scope
        message: 'Scope of the change :'
        filter: 'lambda text: commitizen.cz.utils.required_validator(text, msg="! Error: Scope is required")'
        default: ''
      - type: input
        name: subject
        message: 'Title of the commit (starting in lower case and without period) :'
        filter: 'lambda text: commitizen.cz.utils.required_validator(text.strip(".").strip(), msg="! Error: Title is required")'
        default: ''
      - type: input
        name: body
        message: 'Additional contextual message (Empty to skip) :'
        default: 'Issue: #...'
        filter: 'commitizen.cz.utils.multiple_line_breaker'

Additional commits to add missing YAML tests, fix YAML configurations, and then add the keys for this feature.

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

? Title of the commit (starting in lower case and without period) :                                                                                                                                                                                    
Hello                                                                                                                                                                                                                                                  
! Error: Title is required

Steps to Test This Pull Request

Example provided in the description

Additional context

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1207      +/-   ##
==========================================
+ Coverage   97.33%   98.26%   +0.92%     
==========================================
  Files          42       58      +16     
  Lines        2104     2712     +608     
==========================================
+ Hits         2048     2665     +617     
+ Misses         56       47       -9     
Flag Coverage Δ
unittests 98.26% <100.00%> (+0.92%) ⬆️

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.

@AdrianDC AdrianDC force-pushed the questions-filter branch 3 times, most recently from e04ce53 to 5011a91 Compare August 17, 2024 00:33
@AdrianDC
Copy link
Contributor Author

  • Coverage resolved, 100% over commit.py
  • TOML faulty types fixed
  • Local containerized tests fixed for 'safe.directory' ownership issues
  • Tests for 'cz_customize' using the .customize config rather than unrelated cz_jira
  • Contents of the questions prompts tested for coverage and types around commands.Commit

@AdrianDC AdrianDC force-pushed the questions-filter branch 2 times, most recently from 780b16b to c24db8a Compare August 18, 2024 13:38
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.

I'm sending a "Request changes" to this PR as I'm -1 to this but would like to get feedback from other maintainers

@AdrianDC AdrianDC changed the title feat(commit): implement questions 'filter' support with evaluations feat(commit): implement questions 'filter' support with handlers Aug 25, 2024
@AdrianDC AdrianDC force-pushed the questions-filter branch 2 times, most recently from 65f4d93 to 314f3bf Compare August 25, 2024 03:38
@AdrianDC
Copy link
Contributor Author

Refactored as discussed : feat(commit): implement questions 'filter' support with handlers

Supported APIs:

  • multiple_line_breaker
  • required_validator
  • required_validator_scope
  • required_validator_subject_strip
  • required_validator_title_strip

Example YAML configurations:

commitizen:
  name: cz_customize
  customize:
    questions:
      - ...
      - type: input
        name: scope
        message: 'Scope of the change :'
        filter: 'required_validator_scope'
        default: ''
      - type: input
        name: subject
        message: 'Title of the commit (starting in lower case and without period) :'
        filter: 'required_validator_subject_strip'
        default: ''
      - type: input
        name: body
        message: 'Additional contextual message (Empty to skip) :'
        default: 'Issue: #...'
        filter: 'multiple_line_breaker'

@AdrianDC AdrianDC force-pushed the questions-filter branch 2 times, most recently from 8e411f3 to 33bbf0f Compare November 16, 2024 15:13
@Lee-W Lee-W self-requested a review November 18, 2024 14:44
@AdrianDC
Copy link
Contributor Author

Rebased 😉 .

Please cherry-pick at least the coverage improvements and minor fixes before the filter features review 👍 .

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. Just left some comments

@Lee-W
Copy link
Member

Lee-W commented Jun 8, 2025

I'll come back to this one after 4.8.3 release. As for another PR, I'll take a look at these 2 days. Sorry for the long waiting and thanks so much for still being around!

@Lee-W Lee-W modified the milestones: 4.9.0, 4.10.0 Sep 9, 2025
Signed-off-by: Adrian DC <radian.dc@gmail.com>
> commitizen.exceptions.InvalidConfigurationError: Failed to parse not_exist.yaml: while scanning a double-quoted scalar
> found unknown escape character 's'

Signed-off-by: Adrian DC <radian.dc@gmail.com>
> test_commit_parser[config2] - AssertionError:
>   assert '(?P<message>.*)' == '^(?P<change_...<message>.*)?'
> test_changelog_pattern[config2] - AssertionError:
>   assert '.*' == '^(feature|bug fix)?(!)?'
> test_change_type_map[config2] - AssertionError:
>   assert None == {'bug fix': 'Fix', 'feature': 'Feat'}

Signed-off-by: Adrian DC <radian.dc@gmail.com>
Details: If using a TOML configuration, the type was 'tomlkit.items.AoT'
---

Signed-off-by: Adrian DC <radian.dc@gmail.com>
Signed-off-by: Adrian DC <radian.dc@gmail.com>
Supported APIs:
  - multiple_line_breaker
  - required_validator
  - required_validator_scope
  - required_validator_subject_strip
  - required_validator_title_strip

Example YAML configurations:
---
commitizen:
  name: cz_customize
  customize:
    questions:
      - ...
      - type: input
        name: scope
        message: 'Scope of the change :'
        filter: 'required_validator_scope'
        default: ''
      - type: input
        name: subject
        message: 'Title of the commit (starting in lower case and without period) :'
        filter: 'required_validator_subject_strip'
        default: ''
      - type: input
        name: body
        message: 'Additional contextual message (Empty to skip) :'
        default: 'Issue: #...'
        filter: 'multiple_line_breaker'
---

Signed-off-by: Adrian DC <radian.dc@gmail.com>
Signed-off-by: Adrian DC <radian.dc@gmail.com>
@AdrianDC
Copy link
Contributor Author

Rebased from last year's PR, to update towards 4.9.1+adriandc.20250914
for pre-commit-crocodile 8.0.0 (prek becoming default btw).

Feel free to edit the PR or cherry-pick at will.


I also implemented a check-commitizen-branch wrapper to the commitizen-branch hook,
handling set-head if needed, covering #704, also #593, but fixing upstream needs analysis.


For the record, I'm not a fan of pinning to a patched & customized fork for so long,
blocking my users + coworkers on a specific version of commitizen-tools that I rebase 2-3 times a year,
including now v5-moved fixes and questions features, but works fine since August 2024.

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