-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(commit): implement questions 'filter' support with handlers #1207
base: master
Are you sure you want to change the base?
Changes from all commits
33aa454
0741b43
05d50f6
1a42408
de33de3
c5a37be
8e80df2
d0307fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,13 +6,34 @@ | |||||
from commitizen.cz import exceptions | ||||||
|
||||||
|
||||||
def required_validator(answer, msg=None): | ||||||
def required_validator(answer: str, msg=None) -> str: | ||||||
if not answer: | ||||||
raise exceptions.AnswerRequiredError(msg) | ||||||
return answer | ||||||
|
||||||
|
||||||
def multiple_line_breaker(answer, sep="|"): | ||||||
def required_validator_scope( | ||||||
answer: str, | ||||||
msg: str = "! Error: Scope is required", | ||||||
) -> str: | ||||||
return required_validator(answer, msg) | ||||||
|
||||||
|
||||||
def required_validator_subject_strip( | ||||||
answer: str, | ||||||
msg: str = "! Error: Subject is required", | ||||||
) -> str: | ||||||
return required_validator(answer.strip(".").strip(), msg) | ||||||
|
||||||
|
||||||
def required_validator_title_strip( | ||||||
answer: str, | ||||||
msg: str = "! Error: Title is required", | ||||||
) -> str: | ||||||
return required_validator(answer.strip(".").strip(), msg) | ||||||
|
||||||
|
||||||
def multiple_line_breaker(answer: str, sep: str = "|") -> str: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return "\n".join(line.strip() for line in answer.split(sep) if line) | ||||||
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,13 +110,13 @@ And the correspondent example for a yaml json file: | |
commitizen: | ||
name: cz_customize | ||
customize: | ||
message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" | ||
message_template: '{{change_type}}:{% if show_message %} {{message}}{% endif %}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I know why do we want to change from " to ' here? |
||
example: 'feature: this feature enable customize through config file' | ||
schema: "<type>: <body>" | ||
schema_pattern: "(feature|bug fix):(\\s.*)" | ||
bump_pattern: "^(break|new|fix|hotfix)" | ||
commit_parser: "^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?", | ||
changelog_pattern: "^(feature|bug fix)?(!)?", | ||
schema: '<type>: <body>' | ||
schema_pattern: '(feature|bug fix):(\\s.*)' | ||
bump_pattern: '^(break|new|fix|hotfix)' | ||
commit_parser: '^(?P<change_type>feature|bug fix):\\s(?P<message>.*)?' | ||
changelog_pattern: '^(feature|bug fix)?(!)?' | ||
change_type_map: | ||
feature: Feat | ||
bug fix: Fix | ||
|
@@ -125,7 +125,7 @@ commitizen: | |
new: MINOR | ||
fix: PATCH | ||
hotfix: PATCH | ||
change_type_order: ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"] | ||
change_type_order: ['BREAKING CHANGE', 'feat', 'fix', 'refactor', 'perf'] | ||
info_path: cz_customize_info.txt | ||
info: This is customized info | ||
questions: | ||
|
@@ -176,7 +176,8 @@ commitizen: | |
| `choices` | `list` | `None` | (OPTIONAL) The choices when `type = list`. Either use a list of values or a list of dictionaries with `name` and `value` keys. Keyboard shortcuts can be defined via `key`. See examples above. | | ||
| `default` | `Any` | `None` | (OPTIONAL) The default value for this question. | | ||
| `filter` | `str` | `None` | (OPTIONAL) Validator for user's answer. **(Work in Progress)** | | ||
| `multiline` | `bool` | `False` | (OPTIONAL) Enable multiline support when `type = input`. | | ||
| `filter` | `str` | `None` | (OPTIONAL) Validator for user's answer. The string is the name of a `commitizen.cz.utils.NAME(answer...)` function like `multiple_line_breaker` | | ||
| `multiline` | `bool` | `False` | (OPTIONAL) Enable multiline support when `type = input`. | | ||
[different-question-types]: https://github.com/tmbo/questionary#different-question-types | ||
|
||
#### Shortcut keys | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ set -e | |
export PREFIX='poetry run python -m ' | ||
export REGEX='^(?![.]|venv).*' | ||
|
||
${PREFIX}pytest -n 3 --dist=loadfile --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ | ||
${PREFIX}pytest -n 3 --dist=loadfile --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen "${@}" tests/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What it this for? |
||
${PREFIX}ruff check commitizen/ tests/ --fix | ||
${PREFIX}mypy commitizen/ tests/ | ||
${PREFIX}commitizen -nr 3 check --rev-range origin/master.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably would like to add test cases to validate these validators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we named it as
required_validator
but would be great if we change them to something likerequire_validator