Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from EdgyEdgemond/fix/53
Browse files Browse the repository at this point in the history
Fix/53: Only run post_process if release notes were processed.
  • Loading branch information
EdgyEdgemond authored Feb 23, 2024
2 parents b01abb4 + a8ec477 commit 38f276e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
11 changes: 7 additions & 4 deletions changelog_gen/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def _gen(cfg: config.Config, version_tag: str | None = None, *, dry_run: bool =

typer.echo(w)

_finalise(w, e, version_tag, extension, cfg, dry_run=dry_run)
processed = _finalise(w, e, version_tag, extension, cfg, dry_run=dry_run)

post_process = cfg.post_process
if post_process:
if post_process and processed:
unique_issues = e.unique_issues(sections)
per_issue_post_process(post_process, sorted(unique_issues), version_tag, dry_run=dry_run)

Expand All @@ -181,15 +181,15 @@ def _finalise( # noqa: PLR0913
cfg: config.Config,
*,
dry_run: bool,
) -> None:
) -> bool:
if dry_run or typer.confirm(
f"Write CHANGELOG for suggested version {version_tag}",
):
writer.write()
extractor.clean()

if dry_run or not cfg.commit:
return
return False

Git.add_path(f"CHANGELOG.{extension.value}")
# TODO(edgy): Dont add release notes if using commit messages...
Expand All @@ -198,3 +198,6 @@ def _finalise( # noqa: PLR0913

if cfg.release:
BumpVersion.release(version_tag)
return True

return False
1 change: 1 addition & 0 deletions release_notes/53.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only run post_process commands, if changes were actually executed.
28 changes: 17 additions & 11 deletions tests/cli/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def post_process_setup(git_repo):
tag = true
[changelog_gen]
commit = true
post_process =
url=https://my-api/{issue_ref}/release
auth_env=MY_API_AUTH
Expand Down Expand Up @@ -579,17 +580,22 @@ def test_generate_dry_run(
result = gen_cli_runner.invoke(["--dry-run"])

assert result.exit_code == 0
assert post_process_mock.call_args_list == [
mock.call(
PostProcessConfig(
url="https://my-api/{issue_ref}/release",
auth_env="MY_API_AUTH",
),
["1", "2", "3", "4"],
"0.1.0",
dry_run=True,
),
]
assert post_process_mock.call_count == 0

@pytest.mark.usefixtures("git_repo", "_release_notes", "changelog", "post_process_setup")
def test_generate_decline_changes(
self,
gen_cli_runner,
monkeypatch,
):
monkeypatch.setattr(typer, "confirm", mock.MagicMock(return_value=False))
post_process_mock = mock.MagicMock()
monkeypatch.setattr(command, "per_issue_post_process", post_process_mock)

result = gen_cli_runner.invoke([])

assert result.exit_code == 0
assert post_process_mock.call_count == 0


@freeze_time("2022-04-14T16:45:03")
Expand Down

0 comments on commit 38f276e

Please sign in to comment.