Skip to content

Commit ce58711

Browse files
authored
Merge branch 'master' into feature/author-and-sha1
2 parents 40f1f2d + 0e93206 commit ce58711

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ repos:
4646
exclude: "poetry.lock"
4747

4848
- repo: https://github.com/commitizen-tools/commitizen
49-
rev: v3.18.0 # automatically updated by Commitizen
49+
rev: v3.18.1 # automatically updated by Commitizen
5050
hooks:
5151
- id: commitizen
5252
- id: commitizen-branch

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11

2+
## v3.18.1 (2024-03-11)
3+
4+
### Fix
5+
6+
- **changelog**: changelog hook was not called on dry run
7+
28
## v3.18.0 (2024-03-07)
39

410
### Feat

commitizen/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.18.0"
1+
__version__ = "3.18.1"

commitizen/commands/changelog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ def write_changelog(
132132

133133
if changelog_hook:
134134
changelog_out = changelog_hook(changelog_out, partial_changelog)
135+
136+
if self.dry_run:
137+
out.write(changelog_out)
138+
raise DryRunExit()
139+
135140
changelog_file.write(changelog_out)
136141

137142
def export_template(self):
@@ -216,10 +221,6 @@ def __call__(self):
216221
)
217222
changelog_out = changelog_out.lstrip("\n")
218223

219-
if self.dry_run:
220-
out.write(changelog_out)
221-
raise DryRunExit()
222-
223224
lines = []
224225
if self.incremental and os.path.isfile(self.file_name):
225226
with open(self.file_name, encoding=self.encoding) as changelog_file:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.commitizen]
2-
version = "3.18.0"
2+
version = "3.18.1"
33
tag_format = "v$version"
44
version_files = [
55
"pyproject.toml:version",
@@ -9,7 +9,7 @@ version_files = [
99

1010
[tool.poetry]
1111
name = "commitizen"
12-
version = "3.18.0"
12+
version = "3.18.1"
1313
description = "Python commitizen client tool"
1414
authors = ["Santiago Fraire <santiwilly@gmail.com>"]
1515
license = "MIT"

tests/commands/test_changelog_command.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from commitizen import __file__ as commitizen_init
1313
from commitizen import cli, git
1414
from commitizen.commands.changelog import Changelog
15+
from commitizen.config.base_config import BaseConfig
1516
from commitizen.cz.base import BaseCommitizen
1617
from commitizen.exceptions import (
1718
DryRunExit,
@@ -275,20 +276,24 @@ def test_changelog_incremental_keep_a_changelog_sample(
275276

276277

277278
@pytest.mark.usefixtures("tmp_commitizen_project")
278-
def test_changelog_hook(mocker: MockFixture, config):
279+
@pytest.mark.parametrize("dry_run", [True, False])
280+
def test_changelog_hook(mocker: MockFixture, config: BaseConfig, dry_run: bool):
279281
changelog_hook_mock = mocker.Mock()
280282
changelog_hook_mock.return_value = "cool changelog hook"
281283

282284
create_file_and_commit("feat: new file")
283285
create_file_and_commit("refactor: is in changelog")
284286
create_file_and_commit("Merge into master")
285287

286-
config.settings["change_type_order"] = ["Refactor", "Feat"]
288+
config.settings["change_type_order"] = ["Refactor", "Feat"] # type: ignore[typeddict-unknown-key]
287289
changelog = Changelog(
288-
config, {"unreleased_version": None, "incremental": True, "dry_run": False}
290+
config, {"unreleased_version": None, "incremental": True, "dry_run": dry_run}
289291
)
290292
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
291-
changelog()
293+
try:
294+
changelog()
295+
except DryRunExit:
296+
pass
292297
full_changelog = (
293298
"## Unreleased\n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
294299
)

0 commit comments

Comments
 (0)