-
-
Notifications
You must be signed in to change notification settings - Fork 320
test(init): cover cz without descriptions #1829
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
base: master
Are you sure you want to change the base?
Changes from all commits
b6e6da7
9be6141
15513f7
89f6b8f
209c058
dd2dcca
bd02381
382525e
b0af380
615b888
3c546bd
ac05276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,11 @@ | |
| from commitizen.config.factory import create_config | ||
| from commitizen.cz import registry | ||
| from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS | ||
| from commitizen.exceptions import InitFailedError, NoAnswersError | ||
| from commitizen.exceptions import ( | ||
| InitFailedError, | ||
| MissingCzCustomizeConfigError, | ||
| NoAnswersError, | ||
| ) | ||
| from commitizen.git import get_latest_tag_name, get_tag_names, smart_open | ||
| from commitizen.version_schemes import KNOWN_SCHEMES, Version, get_version_scheme | ||
|
|
||
|
|
@@ -166,13 +170,35 @@ def _ask_config_path(self) -> Path: | |
|
|
||
| def _ask_name(self) -> str: | ||
| name: str = questionary.select( | ||
| "Please choose a cz (commit rule): (default: cz_conventional_commits)", | ||
| choices=list(registry.keys()), | ||
| default="cz_conventional_commits", | ||
| f"Please choose a cz (commit rule): (default: {DEFAULT_SETTINGS['name']})", | ||
| choices=self._construct_name_choices_from_registry(), | ||
| style=self.cz.style, | ||
| ).unsafe_ask() | ||
| return name | ||
|
|
||
| def _construct_name_choices_from_registry(self) -> list[questionary.Choice]: | ||
| """ | ||
| Construct questionary choices of cz names from registry. | ||
| """ | ||
| choices = [] | ||
| for cz_name, cz_class in registry.items(): | ||
| try: | ||
| cz_obj = cz_class(self.config) | ||
| except MissingCzCustomizeConfigError: | ||
| # Fallback if description is not available | ||
| choices.append(questionary.Choice(title=cz_name, value=cz_name)) | ||
| continue | ||
|
|
||
| # Get the first line of the schema as the description | ||
|
Member
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. we'd better add a description in v5.
Collaborator
Author
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. I think it does not have to be a |
||
| # TODO(bearomorphism): schema is a workaround. Add a description method to the cz class. | ||
| description = cz_obj.schema().partition("\n")[0] | ||
| choices.append( | ||
| questionary.Choice( | ||
| title=cz_name, value=cz_name, description=description | ||
| ) | ||
| ) | ||
| return choices | ||
|
|
||
| def _ask_tag(self) -> str: | ||
| latest_tag = get_latest_tag_name() | ||
| if not latest_tag: | ||
|
|
||
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.
Actually, I'm not sure whether this is compatible with plugins. Should we use general exception?
wdyt @Lee-W
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.
why do you think it might not be compatible
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 thought other plugins throw other exceptions when they initialize with empty config, but we actually always initialize that with a
BaseConfigobject.