Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 78b1fb1

Browse files
bearomorphismLee-W
authored andcommitted
refactor(Init): remove unnecessary methods from ProjectInfo and refactor _ask_tag
1 parent 1b39ae4 commit 78b1fb1

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

‎commitizen/commands/init.py‎

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ def is_npm_package(self) -> bool:
111111
def is_php_composer(self) -> bool:
112112
return os.path.isfile("composer.json")
113113

114-
@property
115-
def latest_tag(self) -> str | None:
116-
return get_latest_tag_name()
117-
118-
def tags(self) -> list | None:
119-
"""Not a property, only use if necessary"""
120-
if self.latest_tag is None:
121-
return None
122-
return get_tag_names()
123-
124114
@property
125115
def is_pre_commit_installed(self) -> bool:
126116
return bool(shutil.which("pre-commit"))
@@ -231,31 +221,32 @@ def _ask_name(self) -> str:
231221
return name
232222

233223
def _ask_tag(self) -> str:
234-
latest_tag = self.project_info.latest_tag
224+
latest_tag = get_latest_tag_name()
235225
if not latest_tag:
236226
out.error("No Existing Tag. Set tag to v0.0.1")
237227
return "0.0.1"
238228

239-
is_correct_tag= questionary.confirm(
229+
if questionary.confirm(
240230
f"Is {latest_tag} the latest tag?", style=self.cz.style, default=False
231+
).unsafe_ask():
232+
return latest_tag
233+
234+
existing_tags = get_tag_names()
235+
if not existing_tags:
236+
out.error("No Existing Tag. Set tag to v0.0.1")
237+
return "0.0.1"
238+
239+
answer: str = questionary.select(
240+
"Please choose the latest tag: ",
241+
# The latest tag is most likely with the largest number.
242+
# Thus, listing the existing_tags in reverse order makes more sense.
243+
choices=sorted(existing_tags, reverse=True),
244+
style=self.cz.style,
241245
).unsafe_ask()
242-
if not is_correct_tag:
243-
tags = self.project_info.tags()
244-
if not tags:
245-
out.error("No Existing Tag. Set tag to v0.0.1")
246-
return "0.0.1"
247-
248-
# the latest tag is most likely with the largest number. Thus list the tags in reverse order makes more sense
249-
sorted_tags = sorted(tags, reverse=True)
250-
latest_tag = questionary.select(
251-
"Please choose the latest tag: ",
252-
choices=sorted_tags,
253-
style=self.cz.style,
254-
).unsafe_ask()
255-
256-
if not latest_tag:
257-
raise NoAnswersError("Tag is required!")
258-
return latest_tag
246+
247+
if not answer:
248+
raise NoAnswersError("Tag is required!")
249+
return answer
259250

260251
def _ask_tag_format(self, latest_tag: str) -> str:
261252
if latest_tag.startswith("v"):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /