Skip to content

Commit 7400023

Browse files
grahamharLee-W
andcommitted
refactor: Use format strings
Co-authored-by: Wei Lee <[email protected]>
1 parent 9bdeba2 commit 7400023

File tree

9 files changed

+45
-39
lines changed

9 files changed

+45
-39
lines changed

commitizen/changelog_formats/asciidoc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def parse_version_from_title(self, line: str) -> str | None:
2727
return None
2828

2929
if partial_matches.get("prerelease"):
30-
partial_version += f"-{partial_matches['prerelease']}"
30+
partial_version = f"{partial_version}-{partial_matches['prerelease']}"
3131
if partial_matches.get("devrelease"):
32-
partial_version += f"{partial_matches['devrelease']}"
32+
partial_version = f"{partial_version}{partial_matches['devrelease']}"
3333
return partial_version
3434

3535
def parse_title_level(self, line: str) -> int | None:

commitizen/changelog_formats/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from commitizen.changelog import Metadata
1010
from commitizen.config.base_config import BaseConfig
11-
from commitizen.version_schemes import get_version_scheme
1211
from commitizen.defaults import get_tag_regexes
12+
from commitizen.version_schemes import get_version_scheme
1313

1414
from . import ChangelogFormat
1515

commitizen/changelog_formats/markdown.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def parse_version_from_title(self, line: str) -> str | None:
3030
return None
3131

3232
if matches.get("prerelease"):
33-
partial_version += f"-{matches['prerelease']}"
33+
partial_version = f"{partial_version}-{matches['prerelease']}"
3434
if matches.get("devrelease"):
35-
partial_version += f"{matches['devrelease']}"
35+
partial_version = f"{partial_version}{matches['devrelease']}"
3636
return partial_version
3737

3838
def parse_title_level(self, line: str) -> int | None:

commitizen/changelog_formats/restructuredtext.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
7777
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
7878
)
7979
if matches.get("prerelease"):
80-
partial_version += f"-{matches['prerelease']}"
80+
partial_version = (
81+
f"{partial_version}-{matches['prerelease']}"
82+
)
8183
if matches.get("devrelease"):
82-
partial_version += f"{matches['devrelease']}"
84+
partial_version = (
85+
f"{partial_version}{matches['devrelease']}"
86+
)
8387
meta.latest_version = partial_version
8488
meta.latest_version_position = index
8589
break

commitizen/changelog_formats/textile.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ def parse_version_from_title(self, line: str) -> str | None:
1919
if "version" in m.groupdict():
2020
return m.group("version")
2121
matches = m.groupdict()
22-
try:
23-
partial_version = (
24-
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
25-
)
26-
except KeyError:
22+
if not all(
23+
[
24+
version_segment in matches
25+
for version_segment in ("major", "minor", "patch")
26+
]
27+
):
2728
return None
2829

30+
partial_version = f"{matches['major']}.{matches['minor']}.{matches['patch']}"
31+
2932
if matches.get("prerelease"):
30-
partial_version += f"-{matches['prerelease']}"
33+
partial_version = f"{partial_version}-{matches['prerelease']}"
3134
if matches.get("devrelease"):
32-
partial_version += f"{matches['devrelease']}"
35+
partial_version = f"{partial_version}{matches['devrelease']}"
3336
return partial_version
3437

3538
def parse_title_level(self, line: str) -> int | None:

commitizen/defaults.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ class Settings(TypedDict, total=False):
134134
bump_message = "bump: version $current_version → $new_version"
135135

136136

137-
def get_tag_regexes(version_regex: str) -> dict[str | Any, str | Any]:
137+
def get_tag_regexes(
138+
version_regex: str,
139+
) -> dict[str, str]:
138140
return {
139141
"$version": version_regex,
140142
"$major": r"(?P<major>\d+)",

docs/commands/bump.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -385,20 +385,14 @@ The variables must be preceded by a `$` sign and optionally can be wrapped in `{
385385

386386
Supported variables:
387387

388-
| Variable | Description |
389-
|-----------------|---------------------------------------------|
390-
| `$version` | full generated version |
391-
| `$major` | MAJOR increment |
392-
| `$minor` | MINOR increment |
393-
| `$patch` | PATCH increment |
394-
| `$prerelease` | Prerelease (alpha, beta, release candidate) |
395-
| `$devrelease` | Development release |
396-
| `${version}` | full generated version |
397-
| `${major}` | MAJOR increment |
398-
| `${minor}` | MINOR increment |
399-
| `${patch}` | PATCH increment |
400-
| `${prerelease}` | Prerelease (alpha, beta, release candidate) |
401-
| `${devrelease}` | Development release |
388+
| Variable | Description |
389+
|--------------------------------|---------------------------------------------|
390+
| `$version`, `${version}` | full generated version |
391+
| `$major`, `${major}` | MAJOR increment |
392+
| `$minor`, `${minor}` | MINOR increment |
393+
| `$patch`, `${patch}` | PATCH increment |
394+
| `$prerelease`, `${prerelease}` | Prerelease (alpha, beta, release candidate) |
395+
| `$devrelease`, ${devrelease}` | Development release |
402396

403397
---
404398

docs/tutorials/monorepo_guidance.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# Configuring commitizen in a monorepo
22

3-
This tutorial assumes the monorepo layout is designed with multiple components that can be released independently of each other,
4-
some suggested layouts:
3+
This tutorial assumes the monorepo layout is designed with multiple components that can be released independently of each
4+
other, it also assumes that conventional commits with scopes are in use. Some suggested layouts:
55

66
```
7-
library-a
8-
.cz.toml
9-
library-b
10-
.cz.toml
7+
.
8+
├── library-b
9+
│   └── .cz.toml
10+
└── library-z
11+
└── .cz.toml
1112
```
1213

1314
```
1415
src
15-
library-b
16-
.cz.toml
17-
library-z
18-
.cz.toml
16+
├── library-b
17+
│   └── .cz.toml
18+
└── library-z
19+
└── .cz.toml
1920
```
2021

2122
Each component will have its own changelog, commits will need to use scopes so only relevant commits are included in the

tests/commands/test_changelog_command.py

+2
Original file line numberDiff line numberDiff line change
@@ -1597,9 +1597,11 @@ def test_changelog_only_tag_matching_tag_format_included_suffix(
15971597
git.tag("random0.2.0")
15981598
testargs = ["cz", "bump", "--changelog", "--yes"]
15991599
mocker.patch.object(sys, "argv", testargs)
1600+
# bump to 0.2.0custom
16001601
cli.main()
16011602
wait_for_tag()
16021603
create_file_and_commit("feat: another new file")
1604+
# bump to 0.3.0custom
16031605
cli.main()
16041606
wait_for_tag()
16051607
with open(changelog_path) as f:

0 commit comments

Comments
 (0)