-
-
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: next-release
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -171,24 +171,30 @@ def _ask_config_path(self) -> Path: | |
| def _ask_name(self) -> str: | ||
| name: str = questionary.select( | ||
| f"Please choose a cz (commit rule): (default: {DEFAULT_SETTINGS['name']})", | ||
| choices=self._construct_name_choice_with_description(), | ||
| default=DEFAULT_SETTINGS["name"], | ||
| choices=self._construct_name_choices_from_registry(), | ||
| style=self.cz.style, | ||
| ).unsafe_ask() | ||
| return name | ||
|
|
||
| def _construct_name_choice_with_description(self) -> list[questionary.Choice]: | ||
| 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 | ||
| first_example = cz_obj.schema().partition("\n")[0] | ||
|
|
||
| # 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=first_example | ||
| title=cz_name, value=cz_name, description=description | ||
| ) | ||
| ) | ||
| return choices | ||
|
|
||
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.