Skip to content

Commit 6887336

Browse files
committed
refactor(Init): remove unnecessary methods from ProjectInfo and refactor _ask_tag
1 parent 6b4f8b0 commit 6887336

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

commitizen/commands/init.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ def is_npm_package(self) -> bool:
6363
def is_php_composer(self) -> bool:
6464
return os.path.isfile("composer.json")
6565

66-
@property
67-
def latest_tag(self) -> str | None:
68-
return get_latest_tag_name()
69-
70-
def tags(self) -> list | None:
71-
"""Not a property, only use if necessary"""
72-
if self.latest_tag is None:
73-
return None
74-
return get_tag_names()
75-
7666
@property
7767
def is_pre_commit_installed(self) -> bool:
7868
return bool(shutil.which("pre-commit"))
@@ -181,30 +171,34 @@ def _ask_name(self) -> str:
181171
return name
182172

183173
def _ask_tag(self) -> str:
184-
latest_tag = self.project_info.latest_tag
174+
latest_tag = get_latest_tag_name()
185175
if not latest_tag:
186176
out.error("No Existing Tag. Set tag to v0.0.1")
187177
return "0.0.1"
188178

189179
is_correct_tag = questionary.confirm(
190180
f"Is {latest_tag} the latest tag?", style=self.cz.style, default=False
191181
).unsafe_ask()
192-
if not is_correct_tag:
193-
tags = self.project_info.tags()
194-
if not tags:
195-
out.error("No Existing Tag. Set tag to v0.0.1")
196-
return "0.0.1"
197-
198-
# the latest tag is most likely with the largest number. Thus list the tags in reverse order makes more sense
199-
sorted_tags = sorted(tags, reverse=True)
200-
latest_tag = questionary.select(
182+
if is_correct_tag:
183+
return latest_tag
184+
185+
tags = get_tag_names()
186+
if not tags:
187+
out.error("No Existing Tag. Set tag to v0.0.1")
188+
return "0.0.1"
189+
190+
latest_tag = str(
191+
questionary.select(
201192
"Please choose the latest tag: ",
202-
choices=sorted_tags,
193+
# The latest tag is most likely with the largest number.
194+
# Thus, listing the tags in reverse order makes more sense.
195+
choices=sorted(tags, reverse=True),
203196
style=self.cz.style,
204197
).unsafe_ask()
198+
)
205199

206-
if not latest_tag:
207-
raise NoAnswersError("Tag is required!")
200+
if not latest_tag:
201+
raise NoAnswersError("Tag is required!")
208202
return latest_tag
209203

210204
def _ask_tag_format(self, latest_tag: str) -> str:

0 commit comments

Comments
 (0)