Skip to content

Commit

Permalink
refactor: Use format strings
Browse files Browse the repository at this point in the history
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
  • Loading branch information
grahamhar and Lee-W committed Apr 27, 2024
1 parent c19cd1d commit d5dcf4d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions commitizen/changelog_formats/asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def parse_version_from_title(self, line: str) -> str | None:
return None

if partial_matches.get("prerelease"):
partial_version += f"-{partial_matches['prerelease']}"
partial_version = f"{partial_version}-{partial_matches['prerelease']}"
if partial_matches.get("devrelease"):
partial_version += f"{partial_matches['devrelease']}"
partial_version = f"{partial_version}{partial_matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
Expand Down
4 changes: 2 additions & 2 deletions commitizen/changelog_formats/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def parse_version_from_title(self, line: str) -> str | None:
return None

if matches.get("prerelease"):
partial_version += f"-{matches['prerelease']}"
partial_version = f"{partial_version}-{matches['prerelease']}"
if matches.get("devrelease"):
partial_version += f"{matches['devrelease']}"
partial_version = f"{partial_version}{matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
Expand Down
8 changes: 6 additions & 2 deletions commitizen/changelog_formats/restructuredtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
)
if matches.get("prerelease"):
partial_version += f"-{matches['prerelease']}"
partial_version = (
f"{partial_version}-{matches['prerelease']}"
)
if matches.get("devrelease"):
partial_version += f"{matches['devrelease']}"
partial_version = (
f"{partial_version}{matches['devrelease']}"
)
meta.latest_version = partial_version
meta.latest_version_position = index
break
Expand Down
17 changes: 10 additions & 7 deletions commitizen/changelog_formats/textile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ def parse_version_from_title(self, line: str) -> str | None:
if "version" in m.groupdict():
return m.group("version")
matches = m.groupdict()
try:
partial_version = (
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
)
except KeyError:
if not all(
[
version_segment in matches
for version_segment in ("major", "minor", "patch")
]
):
return None

partial_version = f"{matches['major']}.{matches['minor']}.{matches['patch']}"

if matches.get("prerelease"):
partial_version += f"-{matches['prerelease']}"
partial_version = f"{partial_version}-{matches['prerelease']}"
if matches.get("devrelease"):
partial_version += f"{matches['devrelease']}"
partial_version = f"{partial_version}{matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
Expand Down
4 changes: 3 additions & 1 deletion commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ class Settings(TypedDict, total=False):
bump_message = "bump: version $current_version → $new_version"


def get_tag_regexes(version_regex: str) -> dict[str | Any, str | Any]:
def get_tag_regexes(
version_regex: str,
) -> dict[str, str]:
return {
"$version": version_regex,
"$major": r"(?P<major>\d+)",
Expand Down

0 comments on commit d5dcf4d

Please sign in to comment.