Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -165,9 +169,25 @@ def _ask_config_path(self) -> Path:
return Path(filename)

def _ask_name(self) -> str:
def construct_choice_with_description() -> list[questionary.Choice]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to make it a function inside _ask_name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unittest for construct_choice_with_description

choices = []
for cz_name, cz_class in registry.items():
try:
cz_obj = cz_class(self.config)
except MissingCzCustomizeConfigError:
choices.append(questionary.Choice(title=cz_name, value=cz_name))
continue
first_example = cz_obj.schema().partition("\n")[0]
choices.append(
questionary.Choice(
title=cz_name, value=cz_name, description=first_example
)
)
return choices

name: str = questionary.select(
"Please choose a cz (commit rule): (default: cz_conventional_commits)",
choices=list(registry.keys()),
choices=construct_choice_with_description(),
default="cz_conventional_commits",
style=self.cz.style,
).unsafe_ask()
Expand Down
Loading