Skip to content

Commit 8129521

Browse files
committed
fix: fix initialization error of BaseCommitizen in construct_choice_with_description
1 parent c24f08a commit 8129521

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

commitizen/commands/init.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
from commitizen.config.factory import create_config
1212
from commitizen.cz import registry
1313
from commitizen.defaults import CONFIG_FILES, DEFAULT_SETTINGS
14-
from commitizen.exceptions import InitFailedError, NoAnswersError
14+
from commitizen.exceptions import (
15+
InitFailedError,
16+
MissingCzCustomizeConfigError,
17+
NoAnswersError,
18+
)
1519
from commitizen.git import get_latest_tag_name, get_tag_names, smart_open
1620
from commitizen.version_schemes import KNOWN_SCHEMES, Version, get_version_scheme
1721

@@ -166,18 +170,20 @@ def _ask_config_path(self) -> Path:
166170

167171
def _ask_name(self) -> str:
168172

169-
def construct_choice_with_example(cz_name: str) -> questionary.Choice:
170-
cz_class = registry.get(cz_name)
171-
if cz_class:
172-
first_example = cz_class.example().splitlines()[0]
173-
title = f"{cz_name}: {first_example}"
174-
return questionary.Choice(title=title, value=cz_name)
173+
def construct_choice_with_description(cz_name: str) -> questionary.Choice:
174+
try:
175+
cz_class = registry.get(cz_name)(self.config)
176+
if cz_class:
177+
first_example = cz_class.schema().partition("\n")[0]
178+
return questionary.Choice(title=cz_name, value=cz_name, description=f"{first_example}")
179+
except MissingCzCustomizeConfigError:
180+
pass
175181
return questionary.Choice(title=cz_name, value=cz_name)
176182

177183
name: str = questionary.select(
178184
"Please choose a cz (commit rule): (default: cz_conventional_commits)",
179185
choices=[
180-
construct_choice_with_example(cz_name) for cz_name in registry.keys()
186+
construct_choice_with_description(cz_name) for cz_name in registry.keys()
181187
],
182188
default="cz_conventional_commits",
183189
style=self.cz.style,

0 commit comments

Comments
 (0)