Skip to content

Add ability to create changelog on bump #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(self, config: BaseConfig, arguments: dict):
},
}
self.cz = factory.commiter_factory(self.config)
self.changelog = arguments["changelog"]
self.changelog = arguments["changelog"] or self.config.settings.get(
"update_changelog_on_bump"
)
self.no_verify = arguments["no_verify"]
self.check_consistency = arguments["check_consistency"]

Expand Down
1 change: 1 addition & 0 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"changelog_file": "CHANGELOG.md",
"changelog_incremental": False,
"changelog_start_rev": None,
"update_changelog_on_bump": False,
}

MAJOR = "MAJOR"
Expand Down
13 changes: 13 additions & 0 deletions docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ Some examples
bump_message = "release $current_version → $new_version [skip-ci]"
```

---

### `update_changelog_on_bump`

When set to `true` the changelog is always updated incrementally when running `cz bump`, so the user does not have to provide the `--changelog` flag every time.

defaults to: `false`

```toml
[tool.commitizen]
update_changelog_on_bump = true
```

## Custom bump

Read the [customizing section](./customization.md).
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from commitizen import defaults
Expand All @@ -9,3 +11,13 @@ def config():
_config = BaseConfig()
_config.settings.update({"name": defaults.name})
return _config


@pytest.fixture()
def changelog_path() -> str:
return os.path.join(os.getcwd(), "CHANGELOG.md")


@pytest.fixture()
def config_path() -> str:
return os.path.join(os.getcwd(), "pyproject.toml")
33 changes: 33 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,36 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):

# restore pop stashed
git.tag = stashed_git_tag


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_with_changelog_arg(mocker, changelog_path):
create_file_and_commit("feat(user): new file")
testargs = ["cz", "bump", "--yes", "--changelog"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True

with open(changelog_path, "r") as f:
out = f.read()
assert out.startswith("#")
assert "0.2.0" in out


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_with_changelog_config(mocker, changelog_path, config_path):
create_file_and_commit("feat(user): new file")
with open(config_path, "a") as fp:
fp.write("update_changelog_on_bump = true\n")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)
cli.main()
tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True

with open(changelog_path, "r") as f:
out = f.read()
assert out.startswith("#")
assert "0.2.0" in out
11 changes: 0 additions & 11 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
from datetime import date

Expand All @@ -15,16 +14,6 @@
from tests.utils import create_file_and_commit


@pytest.fixture()
def changelog_path() -> str:
return os.path.join(os.getcwd(), "CHANGELOG.md")


@pytest.fixture()
def config_path() -> str:
return os.path.join(os.getcwd(), "pyproject.toml")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_changelog_on_empty_project(mocker):
testargs = ["cz", "changelog", "--dry-run"]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"changelog_file": "CHANGELOG.md",
"changelog_incremental": False,
"changelog_start_rev": None,
"update_changelog_on_bump": False,
}

_new_settings = {
Expand All @@ -46,6 +47,7 @@
"changelog_file": "CHANGELOG.md",
"changelog_incremental": False,
"changelog_start_rev": None,
"update_changelog_on_bump": False,
}

_read_settings = {
Expand Down