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 3d65861

Browse files
grahamharLee-W
authored andcommitted
refactor: Use format strings
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
1 parent e8fa7a2 commit 3d65861

File tree

9 files changed

+45
-39
lines changed

9 files changed

+45
-39
lines changed

‎commitizen/changelog_formats/asciidoc.py‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 6 additions & 2 deletions
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‎

Lines changed: 10 additions & 7 deletions
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‎

Lines changed: 3 additions & 1 deletion
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‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,20 +418,14 @@ The variables must be preceded by a `$` sign and optionally can be wrapped in `{
418418

419419
Supported variables:
420420

421-
| Variable | Description |
422-
|-----------------|---------------------------------------------|
423-
| `$version` | full generated version |
424-
| `$major` | MAJOR increment |
425-
| `$minor` | MINOR increment |
426-
| `$patch` | PATCH increment |
427-
| `$prerelease` | Prerelease (alpha, beta, release candidate) |
428-
| `$devrelease` | Development release |
429-
| `${version}` | full generated version |
430-
| `${major}` | MAJOR increment |
431-
| `${minor}` | MINOR increment |
432-
| `${patch}` | PATCH increment |
433-
| `${prerelease}` | Prerelease (alpha, beta, release candidate) |
434-
| `${devrelease}` | Development release |
421+
| Variable | Description |
422+
|--------------------------------|---------------------------------------------|
423+
| `$version`, `${version}` | full generated version |
424+
| `$major`, `${major}` | MAJOR increment |
425+
| `$minor`, `${minor}` | MINOR increment |
426+
| `$patch`, `${patch}` | PATCH increment |
427+
| `$prerelease`, `${prerelease}` | Prerelease (alpha, beta, release candidate) |
428+
| `$devrelease`, ${devrelease}` | Development release |
435429

436430
---
437431

‎docs/tutorials/monorepo_guidance.md‎

Lines changed: 11 additions & 10 deletions
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‎

Lines changed: 2 additions & 0 deletions
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)

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