diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cce816a51e..364bb60c34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: exclude: "poetry.lock" - repo: https://github.com/commitizen-tools/commitizen - rev: v3.7.1 # automatically updated by Commitizen + rev: v3.8.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a09a591c..59157a0394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +## v3.8.0 (2023-09-05) + +### Feat + +- **defaults.py**: add always_signoff config option for commits + +## 3.7.1 (2023-09-04) + ## v3.7.1 (2023-09-04) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 975f69142a..32a781905a 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "3.7.1" +__version__ = "3.8.0" diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 67a7797b4e..913526f893 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -89,7 +89,9 @@ def __call__(self): if dry_run: raise DryRunExit() - signoff: bool = self.arguments.get("signoff") + signoff: bool = ( + self.arguments.get("signoff") or self.config.settings["always_signoff"] + ) if signoff: c = git.commit(m, "-s") diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 37024e9be5..a243ebda3c 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -56,6 +56,7 @@ class Settings(TypedDict, total=False): post_bump_hooks: list[str] | None prerelease_offset: int encoding: str + always_signoff: bool name: str = "cz_conventional_commits" @@ -96,6 +97,7 @@ class Settings(TypedDict, total=False): "post_bump_hooks": [], "prerelease_offset": 0, "encoding": encoding, + "always_signoff": False, } MAJOR = "MAJOR" diff --git a/docs/commit.md b/docs/commit.md index 2d50b111ca..ab6038946c 100644 --- a/docs/commit.md +++ b/docs/commit.md @@ -12,5 +12,20 @@ write the message to a file and not modify files and create a commit. A possible case for this is to [automatically prepare a commit message](./tutorials/auto_prepare_commit_message.md). !!! note - To maintain platform compatibility, the `commit` command disable ANSI escaping in its output. - In particular pre-commit hooks coloring will be deactivated as discussed in [commitizen-tools/commitizen#417](https://github.com/commitizen-tools/commitizen/issues/417). + To maintain platform compatibility, the `commit` command disables ANSI escaping in its output. + In particular, pre-commit hooks coloring will be deactivated as discussed in [commitizen-tools/commitizen#417](https://github.com/commitizen-tools/commitizen/issues/417). + +## Configuration + +### `always_signoff` + +When set to `true`, each commit message created by `cz commit` will be signed off. + +Defaults to: `false`. + +In your `pyproject.toml` or `.cz.toml`: + +```toml +[tool.commitizen] +always_signoff = true +``` diff --git a/poetry.lock b/poetry.lock index 50b20182db..4bbb977395 100644 --- a/poetry.lock +++ b/poetry.lock @@ -975,13 +975,13 @@ extra = ["pygments (>=2.12)"] [[package]] name = "pytest" -version = "7.4.0" +version = "7.4.1" description = "pytest: simple powerful testing with Python" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.4.0-py3-none-any.whl", hash = "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32"}, - {file = "pytest-7.4.0.tar.gz", hash = "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"}, + {file = "pytest-7.4.1-py3-none-any.whl", hash = "sha256:460c9a59b14e27c602eb5ece2e47bec99dc5fc5f6513cf924a7d03a578991b1f"}, + {file = "pytest-7.4.1.tar.gz", hash = "sha256:2f2301e797521b23e4d2585a0a3d7b5e50fdddaaf7e7d6773ea26ddb17c213ab"}, ] [package.dependencies] @@ -1062,13 +1062,13 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] [[package]] name = "pytest-regressions" -version = "2.4.2" +version = "2.4.3" description = "Easy to use fixtures to write regression tests." optional = false python-versions = ">=3.6" files = [ - {file = "pytest-regressions-2.4.2.tar.gz", hash = "sha256:eab89e7ba4aa339bdfe07b31047e8e6a70b1e7846e74a8bbfc31a588d01e7303"}, - {file = "pytest_regressions-2.4.2-py3-none-any.whl", hash = "sha256:b47f92c39d5dd2faa90716ee74c584d705c08e14f435a947f67706c4e5b8ef9a"}, + {file = "pytest-regressions-2.4.3.tar.gz", hash = "sha256:7238036bbd17c62944bff55d73edb4993eea3f5dbb835c332ec7bc0ddeb027ed"}, + {file = "pytest_regressions-2.4.3-py3-none-any.whl", hash = "sha256:a0fd84e45d2c3b43d2b36157045ebca8b85185d3dc7b014a62b2954a05d8e07d"}, ] [package.dependencies] diff --git a/pyproject.toml b/pyproject.toml index 3101d845a4..40f53129d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "3.7.1" +version = "3.8.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -9,7 +9,7 @@ version_files = [ [tool.poetry] name = "commitizen" -version = "3.7.1" +version = "3.8.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index b45ac3a552..29840bb6a1 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -2,6 +2,7 @@ import pytest from pytest_mock import MockFixture +from unittest.mock import ANY from commitizen import cmd, commands from commitizen.cz.exceptions import CzException @@ -172,6 +173,31 @@ def test_commit_command_with_signoff_option(config, mocker: MockFixture): success_mock = mocker.patch("commitizen.out.success") commands.Commit(config, {"signoff": True})() + + commit_mock.assert_called_once_with(ANY, "-s") + success_mock.assert_called_once() + + +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) + success_mock = mocker.patch("commitizen.out.success") + + config.settings["always_signoff"] = True + commands.Commit(config, {})() + + commit_mock.assert_called_once_with(ANY, "-s") success_mock.assert_called_once() diff --git a/tests/test_conf.py b/tests/test_conf.py index 7061d30146..9406ff53f2 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -63,6 +63,7 @@ "post_bump_hooks": ["scripts/slack_notification.sh"], "prerelease_offset": 0, "encoding": "utf-8", + "always_signoff": False, } _new_settings = { @@ -87,6 +88,7 @@ "post_bump_hooks": ["scripts/slack_notification.sh"], "prerelease_offset": 0, "encoding": "utf-8", + "always_signoff": False, } _read_settings = {