From 79b31566ab1e66560856ae1e813f702264aba06b Mon Sep 17 00:00:00 2001 From: Bryan Dady Date: Fri, 10 Sep 2021 23:36:10 -0600 Subject: [PATCH 0001/1498] Address typos and layout Resolve some minor typos and line up long line wrap point --- docs/tutorials/writing_commits.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/tutorials/writing_commits.md b/docs/tutorials/writing_commits.md index cf6b6bda11..4cf377a8c1 100644 --- a/docs/tutorials/writing_commits.md +++ b/docs/tutorials/writing_commits.md @@ -1,20 +1,21 @@ -For this project to work well in your pipeline, a commit convention -must be followed. +For this project to work well in your pipeline, a commit convention must be followed. -By default commitizen uses the known [conventional commits][conventional_commits], but you can create -your own following the docs information over [customization][customization]. +By default commitizen uses the known [conventional commits][conventional_commits], but +you can create your own following the docs information over at +[customization][customization]. ## Conventional commits If you are using [conventional commits][conventional_commits], the most important -thing to know is that you must begin your commits with at least one of these tags: `fix`, `feat`. And if you introduce a breaking change, then, you must +thing to know is that you must begin your commits with at least one of these tags: +`fix`, `feat`. And if you introduce a breaking change, then, you must add to your commit body the following `BREAKING CHANGE`. Using these 3 keywords will allow the proper identification of the semantic version. Of course, there are other keywords, but I'll leave it to the reader to explore them. ## Writing commits -Not to the important part, when writing commits, it's important to think about: +Now to the important part, when writing commits, it's important to think about: - Your future self - Your colleagues @@ -27,8 +28,10 @@ understand what happened. - **Keep the message short**: Makes the list of commits more readable (~50 chars). - **Talk imperative**: Follow this rule: `If applied, this commit will ` - **Think about the CHANGELOG**: Your commits will probably end up in the changelog - so try writing for it, but also keep in mind that you can skip sending commits to the CHANGELOG by using different keywords (like `build`). -- **Use a commit per new feature**: if you introduce multiple things related to the same commit, squash them. This is useful for auto-generating CHANGELOG. + so try writing for it, but also keep in mind that you can skip sending commits to the + CHANGELOG by using different keywords (like `build`). +- **Use a commit per new feature**: if you introduce multiple things related to the same + commit, squash them. This is useful for auto-generating CHANGELOG. | Do's | Don'ts | | ---- | ------ | From e92e07f348a37056215a55c6ce686999d69f931b Mon Sep 17 00:00:00 2001 From: Xavier Moreno Date: Sat, 11 Sep 2021 17:36:33 +0200 Subject: [PATCH 0002/1498] fix(commit): correct the stage checker before commiting related to #418 --- commitizen/git.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index 2904d6cb05..080c5a6cb9 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -155,9 +155,8 @@ def find_git_project_root() -> Optional[Path]: def is_staging_clean() -> bool: """Check if staing is clean.""" - c = cmd.run("git diff --no-ext-diff --name-only") - c_cached = cmd.run("git diff --no-ext-diff --cached --name-only") - return not (bool(c.out) or bool(c_cached.out)) + c = cmd.run("git diff --no-ext-diff --cached --name-only") + return not bool(c.out) def is_git_project() -> bool: From a2d6312ee174635c980b2bec6af3d82b5709ae7c Mon Sep 17 00:00:00 2001 From: Xavier Moreno Date: Sun, 12 Sep 2021 12:56:38 +0200 Subject: [PATCH 0003/1498] test(git): extend test for is_staging_clean --- commitizen/git.py | 2 +- tests/test_git.py | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index 080c5a6cb9..b196f15115 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -154,7 +154,7 @@ def find_git_project_root() -> Optional[Path]: def is_staging_clean() -> bool: - """Check if staing is clean.""" + """Check if staging is clean.""" c = cmd.run("git diff --no-ext-diff --cached --name-only") return not bool(c.out) diff --git a/tests/test_git.py b/tests/test_git.py index dc8023b956..c764a6d65a 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -70,7 +70,7 @@ def test_get_commits_author_and_email(): create_file_and_commit("fix: username exception") commit = git.get_commits()[0] - assert commit.author is not "" + assert commit.author != "" assert "@" in commit.author_email @@ -176,12 +176,30 @@ def test_get_latest_tag_name(tmp_commitizen_project): assert tag_name == "1.0" -def test_is_staging_clean(tmp_commitizen_project): +def test_is_staging_clean_when_adding_file(tmp_commitizen_project): + with tmp_commitizen_project.as_cwd(): + assert git.is_staging_clean() is True + + cmd.run("touch test_file") + + assert git.is_staging_clean() is True + + cmd.run("git add test_file") + + assert git.is_staging_clean() is False + + +def test_is_staging_clean_when_updating_file(tmp_commitizen_project): with tmp_commitizen_project.as_cwd(): assert git.is_staging_clean() is True cmd.run("touch test_file") cmd.run("git add test_file") + cmd.run("git commit -m 'add test_file'") cmd.run("echo 'test' > test_file") + assert git.is_staging_clean() is True + + cmd.run("git add test_file") + assert git.is_staging_clean() is False From 4309813974b6be72a246d47fc77f4c7f8ef64be1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 12 Sep 2021 14:11:07 +0000 Subject: [PATCH 0004/1498] =?UTF-8?q?bump:=20version=202.18.0=20=E2=86=92?= =?UTF-8?q?=202.18.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b383bac3..a7d0b96567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.18.1 (2021-09-12) + +### Fix + +- **commit**: correct the stage checker before commiting + ## v2.18.0 (2021-08-13) ### Refactor diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 6ebac24f89..68a0e5125c 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.18.0" +__version__ = "2.18.1" diff --git a/pyproject.toml b/pyproject.toml index c72e717fdd..77b882f622 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.18.0" +version = "2.18.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.18.0" +version = "2.18.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 9924180b6f92c558d4f58b5472ae1712057b166d Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Wed, 15 Sep 2021 14:26:01 +0200 Subject: [PATCH 0005/1498] doc: inverse major and minor In the example, the major an minor keyword were set in a strange order. I changed it to stay consistent with PEP --- docs/bump.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/bump.md b/docs/bump.md index bf3b207cd6..38e4f5272b 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -199,7 +199,7 @@ In your `pyproject.toml` or `.cz.toml` ```toml [tool.commitizen] -tag_format = "v$minor.$major.$patch$prerelease" +tag_format = "v$major.$minor.$patch$prerelease" ``` The variables must be preceded by a `$` sign. From ca0e4bcd0a2b3d6dbf9beeb9334c823b4e5cd9fc Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 26 Sep 2021 16:09:01 +0800 Subject: [PATCH 0006/1498] fix(cli): handle argparse different behavior after python 3.9 argparse raises TypeError when non exist command is provided on Python < 3.9 but raise SystemExit with exit code == 2 on Python 3.9 this error does not break anything obviously from the user perspective, but will break our existing test 429 --- commitizen/cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index a5c336f9fd..2fb482094b 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -286,8 +286,13 @@ def main(): # This is for the command required constraint in 2.0 try: args = parser.parse_args() - except TypeError: - raise NoCommandFoundError() + except (TypeError, SystemExit) as e: + # https://github.com/commitizen-tools/commitizen/issues/429 + # argparse raises TypeError when non exist command is provided on Python < 3.9 + # but raise SystemExit with exit code == 2 on Python 3.9 + if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2): + raise NoCommandFoundError() + raise e if args.name: conf.update({"name": args.name}) From ca3145269ff635aba507af56103a416361f7f87d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 27 Sep 2021 06:41:05 +0000 Subject: [PATCH 0007/1498] =?UTF-8?q?bump:=20version=202.18.1=20=E2=86=92?= =?UTF-8?q?=202.18.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d0b96567..2af38096af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.18.2 (2021-09-27) + +### Fix + +- **cli**: handle argparse different behavior after python 3.9 + ## v2.18.1 (2021-09-12) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 68a0e5125c..855930a227 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.18.1" +__version__ = "2.18.2" diff --git a/pyproject.toml b/pyproject.toml index 77b882f622..2639e487c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.18.1" +version = "2.18.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.18.1" +version = "2.18.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 609cacdb1580d540d26e3486ac59a858a1546fbc Mon Sep 17 00:00:00 2001 From: Sarthak Sharma Date: Mon, 27 Sep 2021 13:38:19 +0530 Subject: [PATCH 0008/1498] feat: utility for showing system information command to show system info output for bug reports Issue #426 --- .github/ISSUE_TEMPLATE/bug_report.md | 9 +++++- commitizen/cli.py | 6 ++++ commitizen/commands/version.py | 11 ++++++- tests/commands/test_version_command.py | 42 ++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index bfd26c9265..73d632fd13 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -28,11 +28,18 @@ If applicable, add screenshots to help explain your problem. ## Environment - +Add output of the following command to include the following - commitizen version: - python version: - operating system: +```bash +cz version --report +``` + diff --git a/commitizen/cli.py b/commitizen/cli.py index 2fb482094b..e1bad367e7 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -227,6 +227,12 @@ ), "func": commands.Version, "arguments": [ + { + "name": ["-r", "--report"], + "help": "get system information for reporting bugs", + "action": "store_true", + "exclusive_group": "group1", + }, { "name": ["-p", "--project"], "help": "get the version of the current project", diff --git a/commitizen/commands/version.py b/commitizen/commands/version.py index 143a0c7351..dc47e7aa0c 100644 --- a/commitizen/commands/version.py +++ b/commitizen/commands/version.py @@ -1,3 +1,6 @@ +import platform +import sys + from commitizen import out from commitizen.__version__ import __version__ from commitizen.config import BaseConfig @@ -9,9 +12,15 @@ class Version: def __init__(self, config: BaseConfig, *args): self.config: BaseConfig = config self.parameter = args[0] + self.operating_system = platform.system() + self.python_version = sys.version def __call__(self): - if self.parameter.get("project"): + if self.parameter.get("report"): + out.write(f"Commitizen Version: {__version__}") + out.write(f"Python Version: {self.python_version}") + out.write(f"Operating System: {self.operating_system}") + elif self.parameter.get("project"): version = self.config.settings["version"] if version: out.write(f"{version}") diff --git a/tests/commands/test_version_command.py b/tests/commands/test_version_command.py index 527c0b53f1..7e6ec3c851 100644 --- a/tests/commands/test_version_command.py +++ b/tests/commands/test_version_command.py @@ -1,42 +1,72 @@ +import platform +import sys + from commitizen import commands from commitizen.__version__ import __version__ def test_version_for_showing_project_version(config, capsys): # No version exist - commands.Version(config, {"project": True, "commitizen": False, "verbose": False})() + commands.Version( + config, + {"report": False, "project": True, "commitizen": False, "verbose": False}, + )() captured = capsys.readouterr() assert "No project information in this project." in captured.err config.settings["version"] = "v0.0.1" - commands.Version(config, {"project": True, "commitizen": False, "verbose": False})() + commands.Version( + config, + {"report": False, "project": True, "commitizen": False, "verbose": False}, + )() captured = capsys.readouterr() assert "v0.0.1" in captured.out def test_version_for_showing_commitizen_version(config, capsys): - commands.Version(config, {"project": False, "commitizen": True, "verbose": False})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": True, "verbose": False}, + )() captured = capsys.readouterr() assert f"{__version__}" in captured.out # default showing commitizen version commands.Version( - config, {"project": False, "commitizen": False, "verbose": False} + config, + {"report": False, "project": False, "commitizen": False, "verbose": False}, )() captured = capsys.readouterr() assert f"{__version__}" in captured.out def test_version_for_showing_both_versions(config, capsys): - commands.Version(config, {"project": False, "commitizen": False, "verbose": True})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": False, "verbose": True}, + )() captured = capsys.readouterr() assert f"Installed Commitizen Version: {__version__}" in captured.out assert "No project information in this project." in captured.err config.settings["version"] = "v0.0.1" - commands.Version(config, {"project": False, "commitizen": False, "verbose": True})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": False, "verbose": True}, + )() captured = capsys.readouterr() expected_out = ( f"Installed Commitizen Version: {__version__}\n" f"Project Version: v0.0.1" ) assert expected_out in captured.out + + +def test_version_for_showing_commitizen_system_info(config, capsys): + commands.Version( + config, + {"report": True, "project": False, "commitizen": False, "verbose": False}, + )() + captured = capsys.readouterr() + assert f"Commitizen Version: {__version__}" in captured.out + assert f"Python Version: {sys.version}" in captured.out + assert f"Operating System: {platform.system()}" in captured.out From 976d5d24cc66e24c9c5c9ba871f6b9567ab6c9b5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 27 Sep 2021 14:43:10 +0000 Subject: [PATCH 0009/1498] =?UTF-8?q?bump:=20version=202.18.2=20=E2=86=92?= =?UTF-8?q?=202.19.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af38096af..42630e4043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.19.0 (2021-09-27) + +### Feat + +- utility for showing system information + ## v2.18.2 (2021-09-27) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 855930a227..326b86ff29 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.18.2" +__version__ = "2.19.0" diff --git a/pyproject.toml b/pyproject.toml index 2639e487c8..c3a8a820cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.18.2" +version = "2.19.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.18.2" +version = "2.19.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 7b7b0c97a3371ea105833b5862592a45d02d6d51 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Wed, 29 Sep 2021 18:37:54 +0200 Subject: [PATCH 0010/1498] feat: add signoff parameter to commit command command to sign off the commit, equivalent to git commit -s --- commitizen/cli.py | 5 +++++ commitizen/commands/commit.py | 7 ++++++- tests/commands/test_commit_command.py | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index e1bad367e7..215d8faf82 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -49,6 +49,11 @@ "action": "store_true", "help": "show output to stdout, no commit, no modified files", }, + { + "name": "--signoff", + "action": "store_true", + "help": "Sign off the commit", + }, ], }, { diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index bad47dd572..a4c0301732 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -78,7 +78,12 @@ def __call__(self): if dry_run: raise DryRunExit() - c = git.commit(m) + signoff: bool = self.arguments.get("signoff") + + if signoff: + c = git.commit(m, "-s") + else: + c = git.commit(m) if c.return_code != 0: out.error(c.err) diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 7d56f08752..8544833c8f 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -107,6 +107,26 @@ def test_commit_command_with_dry_run_option(config, mocker): commit_cmd() +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_with_signoff_option(config, mocker): + 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", "", "", "", 0) + success_mock = mocker.patch("commitizen.out.success") + + commands.Commit(config, {"signoff": True})() + success_mock.assert_called_once() + + def test_commit_when_nothing_to_commit(config, mocker): is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean") is_staging_clean_mock.return_value = True From 7d2c3c2323b6670552d79f0e49ab5fe4666fbce2 Mon Sep 17 00:00:00 2001 From: peter_wu Date: Mon, 4 Oct 2021 11:04:30 +0800 Subject: [PATCH 0011/1498] build: bump packaging to 22 to allow 21.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c3a8a820cd..a0a119da14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ questionary = "^1.4.0" decli = "^0.5.2" colorama = "^0.4.1" termcolor = "^1.1" -packaging = ">=19,<21" +packaging = ">=19,<22" tomlkit = ">=0.5.3,<1.0.0" jinja2 = ">=2.10.3" pyyaml = ">=3.08" From 5e220401f510f394129b5d2f11c6a987229c92de Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Wed, 6 Oct 2021 20:10:37 +0200 Subject: [PATCH 0012/1498] feat(cli.py): add shortcut for signoff command add -s shortcut for the --signoff command --- commitizen/cli.py | 2 +- docs/README.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 215d8faf82..d582a27a18 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -50,7 +50,7 @@ "help": "show output to stdout, no commit, no modified files", }, { - "name": "--signoff", + "name": ["-s", "--signoff"], "action": "store_true", "help": "Sign off the commit", }, diff --git a/docs/README.md b/docs/README.md index f8482f4a69..f7c3127a9e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -86,6 +86,20 @@ or the shortcut cz c ``` +#### Sign off the commit + +Run in the terminal + +```bash +cz commit --signoff +``` + +or the shortcut + +```bash +cz commit -s +``` + ### Integrating with Pre-commit Commitizen can lint your commit message for you with `cz check`. You can integrate this in your [pre-commit](https://pre-commit.com/) config with: From 5a764bf172d6431e6192678a58dd2b8f7ab8daf6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 6 Oct 2021 18:36:38 +0000 Subject: [PATCH 0013/1498] =?UTF-8?q?bump:=20version=202.19.0=20=E2=86=92?= =?UTF-8?q?=202.20.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42630e4043..ac409aef82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## v2.20.0 (2021-10-06) + +### Feat + +- **cli.py**: add shortcut for signoff command +- add signoff parameter to commit command + ## v2.19.0 (2021-09-27) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 326b86ff29..3ea83e0a69 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.19.0" +__version__ = "2.20.0" diff --git a/pyproject.toml b/pyproject.toml index a0a119da14..d1d0e37a47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.19.0" +version = "2.20.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.19.0" +version = "2.20.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 87281ff6c9b609fa27050c772c391ad475adaf2c Mon Sep 17 00:00:00 2001 From: bogay Date: Sun, 26 Sep 2021 15:59:23 +0800 Subject: [PATCH 0014/1498] docs: move all FAQs to docs/faq.md So now we have a single place to view all the FAQs. --- docs/README.md | 16 ++-------------- docs/faq.md | 7 +++++++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/docs/README.md b/docs/README.md index f7c3127a9e..2411d9f744 100644 --- a/docs/README.md +++ b/docs/README.md @@ -189,23 +189,11 @@ See [Third-Party Commitizen Templates](third-party-commitizen.md). ## FAQ -### Why are `revert` and `chore` valid types in the check pattern of cz conventional_commits but not types we can select? - -`revert` and `chore` are added to the "pattern" in `cz check` in order to prevent backward errors, but officially they are not part of conventional commits, we are using the latest [types from Angular](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type) (they used to but were removed). -However, you can create a customized `cz` with those extra types. (See [Customization](https://commitizen-tools.github.io/commitizen/customization)) - -See more discussion in issue [#142](https://github.com/commitizen-tools/commitizen/issues/142) and [#36](https://github.com/commitizen-tools/commitizen/issues/36) - -### How to handle revert commits? - -```sh -git revert --no-commit -git commit -m "revert: foo bar" -``` +See [FAQ - commitizen](https://commitizen-tools.github.io/commitizen/faq/). ## Contributing -See [Contributing](contributing.md) +See [Contributing](contributing.md). [conventional_commits]: https://www.conventionalcommits.org [semver]: https://semver.org/ diff --git a/docs/faq.md b/docs/faq.md index c0e22cefde..4267ecf782 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -73,3 +73,10 @@ If you are using conventional commits in your git history, then you could swap o Regarding the name, [cz-js][cz-js] came first, they used the word commitizen first. When this project was created originally, the creator read "be a good commitizen", and thought it was just a cool word that made sense, and this would be a package that helps you be a good "commit citizen". [cz-js]: https://github.com/commitizen/cz-cli + +### How to handle revert commits? + +```sh +git revert --no-commit +git commit -m "revert: foo bar" +``` From 0949575b5f6d2b29dcc79afeae58a8bd7f71616b Mon Sep 17 00:00:00 2001 From: bogay Date: Sun, 26 Sep 2021 16:15:21 +0800 Subject: [PATCH 0015/1498] docs(faq): add WinError 995 description to FAQ --- docs/faq.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index 4267ecf782..8b4914f1c5 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -74,9 +74,15 @@ Regarding the name, [cz-js][cz-js] came first, they used the word commitizen fir [cz-js]: https://github.com/commitizen/cz-cli -### How to handle revert commits? +## How to handle revert commits? ```sh git revert --no-commit git commit -m "revert: foo bar" ``` + +## I got `Exception [WinError 995] The I/O operation ...` error + +This error is cause by a python bug on windows and it should be fixed in some newer version. (e.g. 3.8.7) So if you encounter this error. Upgrade python version may solve this. + +More discussion can be found in issue [#318](https://github.com/commitizen-tools/commitizen/issues/318). From dd8e75ae0f84c837cfd2b17e0eca03961152a5ab Mon Sep 17 00:00:00 2001 From: bogay Date: Mon, 27 Sep 2021 00:27:21 +0800 Subject: [PATCH 0016/1498] docs(faq): reword FAQ about WinError 995 Provide the accurate versions that should solve this issue. --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index 8b4914f1c5..dac83b229f 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -83,6 +83,6 @@ git commit -m "revert: foo bar" ## I got `Exception [WinError 995] The I/O operation ...` error -This error is cause by a python bug on windows and it should be fixed in some newer version. (e.g. 3.8.7) So if you encounter this error. Upgrade python version may solve this. +This error was caused by a Python bug on Windows. It's been fixed by [this PR](https://github.com/python/cpython/pull/22017), and according to Python's changelog, [3.8.6rc1](https://docs.python.org/3.8/whatsnew/changelog.html#python-3-8-6-release-candidate-1) and [3.9.0rc2](https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-0-release-candidate-2) should be the accurate versions first contain this fix. In conclusion, upgrade your Python version might solve this issue. More discussion can be found in issue [#318](https://github.com/commitizen-tools/commitizen/issues/318). From 9e6ac64a49b36e5bb7fab91c3d82f163d9edf467 Mon Sep 17 00:00:00 2001 From: bogay Date: Tue, 28 Sep 2021 16:33:07 +0800 Subject: [PATCH 0017/1498] docs: replace htperlinks' URL with filename According to mkdoc documentation, link to another page in the same documentation can directly use file path. mkdoc documentation: https://www.mkdocs.org/user-guide/writing-your-docs/#linking-to-pages --- docs/README.md | 4 ++-- docs/config.md | 10 +++++----- docs/customization.md | 4 ++-- docs/faq.md | 2 +- docs/tutorials/gitlab_ci.md | 2 +- docs/tutorials/writing_commits.md | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2411d9f744..d85c54d553 100644 --- a/docs/README.md +++ b/docs/README.md @@ -120,7 +120,7 @@ After the configuration is added, you'll need to run pre-commit install --hook-type commit-msg ``` -Read more about the `check` command [here](https://commitizen-tools.github.io/commitizen/check/). +Read more about the `check` command [here](check.md). ### Help @@ -189,7 +189,7 @@ See [Third-Party Commitizen Templates](third-party-commitizen.md). ## FAQ -See [FAQ - commitizen](https://commitizen-tools.github.io/commitizen/faq/). +See [FAQ](faq.md). ## Contributing diff --git a/docs/config.md b/docs/config.md index eee90e1dcc..d8af476e7f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -134,9 +134,9 @@ commitizen: | `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more](customization) | | `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more](shortcuts) | -[version_files]: https://commitizen-tools.github.io/commitizen/bump/#version_files -[tag_format]: https://commitizen-tools.github.io/commitizen/bump/#tag_format -[bump_message]: https://commitizen-tools.github.io/commitizen/bump/#bump_message +[version_files]: bump.md#version_files +[tag_format]: bump.md#tag_format +[bump_message]: bump.md#bump_message [additional-features]: https://github.com/tmbo/questionary#additional-features -[customization]: https://commitizen-tools.github.io/commitizen/customization/ -[shortcuts]: https://commitizen-tools.github.io/commitizen/customization/#shortcut-keys +[customization]: customization.md +[shortcuts]: customization.md#shortcut-keys diff --git a/docs/customization.md b/docs/customization.md index b96c459e41..74ac0707b6 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -167,10 +167,10 @@ commitizen: #### Shortcut keys -When the [`use_shortcuts`](https://commitizen-tools.github.io/commitizen/config/#settings) config option is enabled, commitizen can show and use keyboard shortcuts to select items from lists directly. +When the [`use_shortcuts`](config.md#settings) config option is enabled, commitizen can show and use keyboard shortcuts to select items from lists directly. For example, when using the `cz_conventional_commits` commitizen template, shortcut keys are shown when selecting the commit type. Unless otherwise defined, keyboard shortcuts will be numbered automatically. To specify keyboard shortcuts for your custom choices, provide the shortcut using the `key` parameter in dictionary form for each choice you would like to customize. - + ## 2. Customize through customizing a class The basic steps are: diff --git a/docs/faq.md b/docs/faq.md index dac83b229f..7e1450e33c 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -30,7 +30,7 @@ version_files = [ ## Why are `revert` and `chore` valid types in the check pattern of cz conventional_commits but not types we can select? `revert` and `chore` are added to the "pattern" in `cz check` in order to prevent backward errors, but officially they are not part of conventional commits, we are using the latest [types from Angular](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type) (they used to but were removed). -However, you can create a customized `cz` with those extra types. (See [Customization](https://commitizen-tools.github.io/commitizen/customization/) +However, you can create a customized `cz` with those extra types. (See [Customization](customization.md) See more discussion in issue [#142](https://github.com/commitizen-tools/commitizen/issues/142) and [#36](https://github.com/commitizen-tools/commitizen/issues/36) diff --git a/docs/tutorials/gitlab_ci.md b/docs/tutorials/gitlab_ci.md index 9be03d1966..2859db7318 100644 --- a/docs/tutorials/gitlab_ci.md +++ b/docs/tutorials/gitlab_ci.md @@ -10,7 +10,7 @@ _Goal_: Bump a new version every time that a change occurs on the `master` branc 2. A developer creates a merge request (MR) against `master` branch 3. When the `MR` is merged into master, the 2 stages of the CI are executed 4. For simplification, we store the software version in a file called `VERSION`. You can use any file that you want as `commitizen` supports it. -5. The commit message executed automatically by the `CI` must include `[skip-ci]` in the message; otherwise, the process will generate a loop. You can define the message structure in [commitizen](https://commitizen-tools.github.io/commitizen/bump/) as well. +5. The commit message executed automatically by the `CI` must include `[skip-ci]` in the message; otherwise, the process will generate a loop. You can define the message structure in [commitizen](../bump.md) as well. ### Gitlab Configuration diff --git a/docs/tutorials/writing_commits.md b/docs/tutorials/writing_commits.md index 4cf377a8c1..4bc20f9773 100644 --- a/docs/tutorials/writing_commits.md +++ b/docs/tutorials/writing_commits.md @@ -38,5 +38,5 @@ understand what happened. | `fix(commands): bump error when no user provided` | `fix: stuff` | | `feat: add new commit command` | `feat: commit command introduced` | -[customization]: https://commitizen-tools.github.io/commitizen/customization/ +[customization]: customization.md [conventional_commits]: https://www.conventionalcommits.org From ed1148857b9c98f15b0738d0ad7637a93ad95e47 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 6 Oct 2021 22:56:35 +0800 Subject: [PATCH 0018/1498] style(github-template): remove trailing space --- .github/ISSUE_TEMPLATE/bug_report.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 73d632fd13..944a95723e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -42,4 +42,3 @@ Add output of the following command to include the following ```bash cz version --report ``` - From e9eb2623341bb7e47c1050fd032e0015d150880d Mon Sep 17 00:00:00 2001 From: bogay Date: Thu, 7 Oct 2021 15:24:29 +0800 Subject: [PATCH 0019/1498] docs: fix missing link --- docs/tutorials/writing_commits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/writing_commits.md b/docs/tutorials/writing_commits.md index 4bc20f9773..dbeee66db8 100644 --- a/docs/tutorials/writing_commits.md +++ b/docs/tutorials/writing_commits.md @@ -38,5 +38,5 @@ understand what happened. | `fix(commands): bump error when no user provided` | `fix: stuff` | | `feat: add new commit command` | `feat: commit command introduced` | -[customization]: customization.md +[customization]: ../customization.md [conventional_commits]: https://www.conventionalcommits.org From 7e8d795ed459b6ee363f7eb8e608f8d9c94bb46b Mon Sep 17 00:00:00 2001 From: bogay Date: Thu, 7 Oct 2021 15:28:43 +0800 Subject: [PATCH 0020/1498] docs(contributing): add instruction to verify documentation change --- docs/contributing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/contributing.md b/docs/contributing.md index b106edc73c..0dcd5c5bff 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -18,6 +18,7 @@ If you're a first-time contributor, you can check the issues with [good first is 7. Use [commitizen](https://github.com/commitizen-tools/commitizen) to do git commit. We follow [conventional commmits][conventional-commmits] 8. Run `./scripts/format` and `./scripts/test` to ensure you follow the coding style and the tests pass. 9. Update `README.md`. Do **not** update the `CHANGELOG.md`, it will be automatically created after merging to `master`. -10. Send a [pull request](https://github.com/commitizen-tools/commitizen/pulls) 🙏 +10. If your changes are about documentation. Run `poetry run mkdocs serve` to serve documentation locally and check whether there is any warning or error. +11. Send a [pull request](https://github.com/commitizen-tools/commitizen/pulls) 🙏 [conventional-commmits]: https://www.conventionalcommits.org/ From 0d407d74943b17ac2f76ec2d3b010917326b935a Mon Sep 17 00:00:00 2001 From: bogay Date: Thu, 7 Oct 2021 15:32:59 +0800 Subject: [PATCH 0021/1498] docs(readme): remove sections only contains one link --- docs/README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index d85c54d553..3bb2db5588 100644 --- a/docs/README.md +++ b/docs/README.md @@ -183,18 +183,6 @@ eval "$(register-python-argcomplete cz)" For further information on activation, please visit the [argcomplete website](https://kislyuk.github.io/argcomplete/). -## Third-Party Commitizen Templates - -See [Third-Party Commitizen Templates](third-party-commitizen.md). - -## FAQ - -See [FAQ](faq.md). - -## Contributing - -See [Contributing](contributing.md). - [conventional_commits]: https://www.conventionalcommits.org [semver]: https://semver.org/ [keepchangelog]: https://keepachangelog.com/ From 1ea05accd5c655e15eea9d4be54710ef6832aabb Mon Sep 17 00:00:00 2001 From: bogay Date: Thu, 7 Oct 2021 16:08:26 +0800 Subject: [PATCH 0022/1498] docs(config): fix broken links These reference-style links should in `[link][id]` format instead of `[link](id)`. --- docs/config.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/config.md b/docs/config.md index d8af476e7f..342219fef2 100644 --- a/docs/config.md +++ b/docs/config.md @@ -126,13 +126,13 @@ commitizen: | ---------------- | ------ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | | `version` | `str` | `None` | Current version. Example: "0.1.2" | -| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more](version_files) | -| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more](tag_format) | -| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more](bump_message) | +| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | +| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | +| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | | `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | -| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)](additional-features) | -| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more](customization) | -| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more](shortcuts) | +| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] | +| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] | +| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] | [version_files]: bump.md#version_files [tag_format]: bump.md#tag_format From 71aabe8c675a84cff0587a2f620a85dbecc6f82f Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 9 Oct 2021 15:03:19 +0800 Subject: [PATCH 0023/1498] ci(github-actions): set force to true for Homebrew bump formula --- .github/workflows/homebrewpublish.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/homebrewpublish.yaml b/.github/workflows/homebrewpublish.yaml index 817d881794..2ff28078b0 100644 --- a/.github/workflows/homebrewpublish.yaml +++ b/.github/workflows/homebrewpublish.yaml @@ -29,3 +29,4 @@ jobs: token: ${{secrets.PERSONAL_ACCESS_TOKEN}} formula: commitizen tag: v${{ env.project_version }} + force: true From 4613dc25b26d762b8adfcc718bfec441b5b3f249 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:27:15 +0800 Subject: [PATCH 0024/1498] ci(github-actions): add back 3.7 runner to pythonpackage --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 82078d4b93..b718ea84c5 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -6,7 +6,7 @@ jobs: python-check: strategy: matrix: - python-version: [3.6, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8, 3.9] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: From b5c66e121e5e7c0840884c1c41bffe1964538f20 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:33:12 +0800 Subject: [PATCH 0025/1498] ci(github-actions): upgrade setup-python to v2 --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index b718ea84c5..51fb46832d 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -14,7 +14,7 @@ jobs: with: fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 732133e31dfcfd5517c0b91ea01ad2a7eb9ad8ce Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:11:25 +0800 Subject: [PATCH 0026/1498] build(poetry): update black version for python 3.9 and upgrade least support python version to python 3.6.2 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d1d0e37a47..a8a7da5782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ classifiers = [ ] [tool.poetry.dependencies] -python = "^3.6.1" +python = "^3.6.2" questionary = "^1.4.0" decli = "^0.5.2" colorama = "^0.4.1" @@ -57,7 +57,7 @@ argcomplete = "^1.12.1" [tool.poetry.dev-dependencies] ipython = "^7.2" -black = "^19.3b0" +black = "^21.12b0" pytest = "^5.0" flake8 = "^3.6" pytest-cov = "^2.6" From 65645e05df7cc404831546a7289406e2b9f76e11 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:39:29 +0800 Subject: [PATCH 0027/1498] style: format the code through the latest black --- tests/commands/test_check_command.py | 6 +++++- tests/test_bump_find_version.py | 18 +++++++++++------- tests/test_cli.py | 5 ++++- tests/test_cz_conventional_commits.py | 15 ++++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index ac545e3a6a..7377a8a388 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -125,7 +125,11 @@ def test_check_conventional_commit_succeeds(mocker, capsys): @pytest.mark.parametrize( - "commit_msg", ("feat!(lang): removed polish language", "no conventional commit",), + "commit_msg", + ( + "feat!(lang): removed polish language", + "no conventional commit", + ), ) def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir): with pytest.raises(InvalidCommitMessageError): diff --git a/tests/test_bump_find_version.py b/tests/test_bump_find_version.py index 1436d9bd1e..2899dfcf97 100644 --- a/tests/test_bump_find_version.py +++ b/tests/test_bump_find_version.py @@ -82,16 +82,20 @@ def test_generate_version(test_input, expected): @pytest.mark.parametrize( - "test_input,expected", itertools.chain(local_versions), + "test_input,expected", + itertools.chain(local_versions), ) def test_generate_version_local(test_input, expected): current_version = test_input[0] increment = test_input[1] prerelease = test_input[2] is_local_version = True - assert generate_version( - current_version, - increment=increment, - prerelease=prerelease, - is_local_version=is_local_version, - ) == Version(expected) + assert ( + generate_version( + current_version, + increment=increment, + prerelease=prerelease, + is_local_version=is_local_version, + ) + == Version(expected) + ) diff --git a/tests/test_cli.py b/tests/test_cli.py index 2b73bbd5cf..44f182b0d5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -73,7 +73,10 @@ def test_commitizen_excepthook(capsys): def test_commitizen_debug_excepthook(capsys): with pytest.raises(SystemExit) as excinfo: cli.commitizen_excepthook( - NotAGitProjectError, NotAGitProjectError(), "", debug=True, + NotAGitProjectError, + NotAGitProjectError(), + "", + debug=True, ) assert excinfo.type == SystemExit diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index b84144e94c..27445cd57c 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -144,9 +144,18 @@ def test_info(config): @pytest.mark.parametrize( ("commit_message", "expected_message"), [ - ("test(test_scope): this is test msg", "this is test msg",), - ("test(test_scope)!: this is test msg", "this is test msg",), - ("test!(test_scope): this is test msg", "",), + ( + "test(test_scope): this is test msg", + "this is test msg", + ), + ( + "test(test_scope)!: this is test msg", + "this is test msg", + ), + ( + "test!(test_scope): this is test msg", + "", + ), ], ) def test_process_commit(commit_message, expected_message, config): From f94ab4a7993be2004efac41e2cd58023d5354914 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 6 Jun 2020 15:29:18 +0800 Subject: [PATCH 0028/1498] refactor(defaults): move bump_map, bump_pattern, commit_parser from defaults to ConventionalCommitsCz These defaults are not defaults for other cz --- commitizen/bump.py | 13 ++--------- commitizen/changelog.py | 2 +- .../conventional_commits.py | 18 +++++++++++---- tests/commands/conftest.py | 2 +- tests/test_bump_find_increment.py | 7 +++++- tests/test_changelog.py | 23 +++++++++++-------- tests/test_cz_base.py | 2 +- tests/test_cz_conventional_commits.py | 2 +- tests/test_cz_jira.py | 2 +- tests/test_factory.py | 2 +- 10 files changed, 41 insertions(+), 32 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index 9312491044..f3319fc1cc 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -6,22 +6,13 @@ from packaging.version import Version -from commitizen.defaults import ( - MAJOR, - MINOR, - PATCH, - bump_map, - bump_message, - bump_pattern, -) +from commitizen.defaults import MAJOR, MINOR, PATCH, bump_message from commitizen.exceptions import CurrentVersionNotFoundError from commitizen.git import GitCommit def find_increment( - commits: List[GitCommit], - regex: str = bump_pattern, - increments_map: Union[dict, OrderedDict] = bump_map, + commits: List[GitCommit], regex: str, increments_map: Union[dict, OrderedDict] ) -> Optional[str]: if isinstance(increments_map, dict): diff --git a/commitizen/changelog.py b/commitizen/changelog.py index 7bb9007cdc..d854219a28 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -69,7 +69,7 @@ def generate_tree_from_commits( commits: List[GitCommit], tags: List[GitTag], commit_parser: str, - changelog_pattern: str = defaults.bump_pattern, + changelog_pattern: str, unreleased_version: Optional[str] = None, change_type_map: Optional[Dict[str, str]] = None, changelog_message_builder_hook: Optional[Callable] = None, diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 61f7b7f94b..f9890d46ba 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -1,5 +1,6 @@ import os import re +from collections import OrderedDict from typing import Any, Dict, List from commitizen import defaults @@ -28,10 +29,19 @@ def parse_subject(text): class ConventionalCommitsCz(BaseCommitizen): - bump_pattern = defaults.bump_pattern - bump_map = defaults.bump_map - commit_parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?" + bump_map = OrderedDict( + ( + (r"^.+!$", defaults.MAJOR), + (r"^BREAKING[\-\ ]CHANGE", defaults.MAJOR), + (r"^feat", defaults.MINOR), + (r"^fix", defaults.PATCH), + (r"^refactor", defaults.PATCH), + (r"^perf", defaults.PATCH), + ) + ) + commit_parser = r"^(?Pfeat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P[^()\r\n]*)\)|\()?(?P!)?:\s(?P.*)?" # noqa + version_parser = defaults.version_parser change_type_map = { "feat": "Feat", "fix": "Fix", diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index faae727918..46e9500365 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -9,7 +9,7 @@ @pytest.fixture() def config(): _config = BaseConfig() - _config.settings.update({"name": defaults.name}) + _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) return _config diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 1f98694a2b..826490a3ba 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -5,6 +5,7 @@ import pytest from commitizen import bump +from commitizen.cz import ConventionalCommitsCz from commitizen.git import GitCommit NONE_INCREMENT_CC = ["docs(README): motivation", "ci: added travis"] @@ -72,7 +73,11 @@ ) def test_find_increment(messages, expected_type): commits = [GitCommit(rev="test", title=message) for message in messages] - increment_type = bump.find_increment(commits) + increment_type = bump.find_increment( + commits, + regex=ConventionalCommitsCz.bump_pattern, + increments_map=ConventionalCommitsCz.bump_map, + ) assert increment_type == expected_type diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 055e4fc916..da05eaf2b7 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1,6 +1,9 @@ import pytest from commitizen import changelog, defaults, git +from commitizen.cz.conventional_commits.conventional_commits import ( + ConventionalCommitsCz, +) from commitizen.exceptions import InvalidConfigurationError COMMITS_DATA = [ @@ -841,8 +844,8 @@ def test_order_changelog_tree_raises(): def test_render_changelog(gitcommits, tags, changelog_content): - parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + parser = ConventionalCommitsCz.commit_parser + changelog_pattern = ConventionalCommitsCz.bump_pattern tree = changelog.generate_tree_from_commits( gitcommits, tags, parser, changelog_pattern ) @@ -852,8 +855,8 @@ def test_render_changelog(gitcommits, tags, changelog_content): def test_render_changelog_unreleased(gitcommits): some_commits = gitcommits[:7] - parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + parser = ConventionalCommitsCz.commit_parser + changelog_pattern = ConventionalCommitsCz.bump_pattern tree = changelog.generate_tree_from_commits( some_commits, [], parser, changelog_pattern ) @@ -867,8 +870,8 @@ def test_render_changelog_tag_and_unreleased(gitcommits, tags): tag for tag in tags if tag.rev == "56c8a8da84e42b526bcbe130bd194306f7c7e813" ] - parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + parser = ConventionalCommitsCz.commit_parser + changelog_pattern = ConventionalCommitsCz.bump_pattern tree = changelog.generate_tree_from_commits( some_commits, single_tag, parser, changelog_pattern ) @@ -881,8 +884,8 @@ def test_render_changelog_tag_and_unreleased(gitcommits, tags): def test_render_changelog_with_change_type(gitcommits, tags): new_title = ":some-emoji: feature" change_type_map = {"feat": new_title} - parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + parser = ConventionalCommitsCz.commit_parser + changelog_pattern = ConventionalCommitsCz.bump_pattern tree = changelog.generate_tree_from_commits( gitcommits, tags, parser, changelog_pattern, change_type_map=change_type_map ) @@ -897,8 +900,8 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit) -> dict ] = f"{message['message']} [link](github.com/232323232) {commit.author} {commit.author_email}" return message - parser = defaults.commit_parser - changelog_pattern = defaults.bump_pattern + parser = ConventionalCommitsCz.commit_parser + changelog_pattern = ConventionalCommitsCz.bump_pattern tree = changelog.generate_tree_from_commits( gitcommits, tags, diff --git a/tests/test_cz_base.py b/tests/test_cz_base.py index 04cc7d9e83..80450d4476 100644 --- a/tests/test_cz_base.py +++ b/tests/test_cz_base.py @@ -8,7 +8,7 @@ @pytest.fixture() def config(): _config = BaseConfig() - _config.settings.update({"name": defaults.name}) + _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) return _config diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 27445cd57c..82a123b8a2 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -23,7 +23,7 @@ @pytest.fixture() def config(): _config = BaseConfig() - _config._settings["name"] = defaults.name + _config._settings["name"] = defaults.DEFAULT_SETTINGS["name"] return _config diff --git a/tests/test_cz_jira.py b/tests/test_cz_jira.py index b725a46fa9..0060613961 100644 --- a/tests/test_cz_jira.py +++ b/tests/test_cz_jira.py @@ -8,7 +8,7 @@ @pytest.fixture() def config(): _config = BaseConfig() - _config.settings.update({"name": defaults.name}) + _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) return _config diff --git a/tests/test_factory.py b/tests/test_factory.py index 1a2eb7178d..5fbd2deebb 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -7,7 +7,7 @@ def test_factory(): config = BaseConfig() - config.settings.update({"name": defaults.name}) + config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) r = factory.commiter_factory(config) assert isinstance(r, BaseCommitizen) From 88cf8bb3c1ce5cf1f9aaaaf24c8cfee4d5c1aa11 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 6 Jun 2020 15:33:31 +0800 Subject: [PATCH 0029/1498] test: move default config to top level conftest.py --- tests/conftest.py | 17 ++++++++++++++++- tests/test_cz_base.py | 9 --------- tests/test_cz_conventional_commits.py | 9 --------- tests/test_cz_jira.py | 11 ----------- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f293d5631b..aec79c2db3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,9 @@ +import os + import pytest -from commitizen import cmd +from commitizen import cmd, defaults +from commitizen.config import BaseConfig @pytest.fixture(scope="function") @@ -18,3 +21,15 @@ def tmp_commitizen_project(tmp_git_project): tmp_commitizen_cfg_file.write("[tool.commitizen]\n" 'version="0.1.0"\n') yield tmp_git_project + + +@pytest.fixture() +def config(): + _config = BaseConfig() + _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) + return _config + + +@pytest.fixture() +def config_path() -> str: + return os.path.join(os.getcwd(), "pyproject.toml") diff --git a/tests/test_cz_base.py b/tests/test_cz_base.py index 80450d4476..891ee01167 100644 --- a/tests/test_cz_base.py +++ b/tests/test_cz_base.py @@ -1,17 +1,8 @@ import pytest -from commitizen import defaults -from commitizen.config import BaseConfig from commitizen.cz.base import BaseCommitizen -@pytest.fixture() -def config(): - _config = BaseConfig() - _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) - return _config - - class DummyCz(BaseCommitizen): def questions(self): return [{"type": "input", "name": "commit", "message": "Initial commit:\n"}] diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 82a123b8a2..04d0522174 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -1,7 +1,5 @@ import pytest -from commitizen import defaults -from commitizen.config import BaseConfig from commitizen.cz.conventional_commits.conventional_commits import ( ConventionalCommitsCz, parse_scope, @@ -20,13 +18,6 @@ invalid_subjects = ["", " ", ".", " .", "", None] -@pytest.fixture() -def config(): - _config = BaseConfig() - _config._settings["name"] = defaults.DEFAULT_SETTINGS["name"] - return _config - - def test_parse_scope_valid_values(): for valid_scope in valid_scopes: assert valid_scope == parse_scope(valid_scope) diff --git a/tests/test_cz_jira.py b/tests/test_cz_jira.py index 0060613961..03055c14b1 100644 --- a/tests/test_cz_jira.py +++ b/tests/test_cz_jira.py @@ -1,17 +1,6 @@ -import pytest - -from commitizen import defaults -from commitizen.config import BaseConfig from commitizen.cz.jira import JiraSmartCz -@pytest.fixture() -def config(): - _config = BaseConfig() - _config.settings.update({"name": defaults.DEFAULT_SETTINGS["name"]}) - return _config - - def test_questions(config): cz = JiraSmartCz(config) questions = cz.questions() From 59ce084a55179c1bbb83301863327bc660ecf06c Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 24 Dec 2020 20:47:50 +0800 Subject: [PATCH 0030/1498] style(mypy): disable disallow_untyped_decorators for tests --- setup.cfg | 15 ++++++++------- tests/test_changelog.py | 6 +++--- tests/test_changelog_parser.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/setup.cfg b/setup.cfg index d4e21ad5b3..e85ca41fff 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,19 +4,20 @@ norecursedirs = .* build dist CVS _darcs {arch} *.egg venv env virtualenv [mypy] -files = commitizen, tests +files = commitizen ignore_missing_imports = true # disallow_untyped_calls = True # disallow_untyped_defs = True # disallow_incomplete_defs = True -disallow_untyped_decorators = True +disallow_untyped_decorators = true # disallow_any_generics = True -disallow_subclassing_any = True +disallow_subclassing_any = true # warn_return_any = True -warn_redundant_casts = True -warn_unused_ignores = True -warn_unused_configs = True - +warn_redundant_casts = true +warn_unused_ignores = true +warn_unused_configs = true +[mypy-tests.*] +disallow_untyped_decorators = false [flake8] ignore = diff --git a/tests/test_changelog.py b/tests/test_changelog.py index da05eaf2b7..b3071ed5fc 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -472,7 +472,7 @@ ] -@pytest.fixture # type: ignore +@pytest.fixture def gitcommits() -> list: commits = [ git.GitCommit( @@ -487,13 +487,13 @@ def gitcommits() -> list: return commits -@pytest.fixture # type: ignore +@pytest.fixture def tags() -> list: tags = [git.GitTag(*tag) for tag in TAGS] return tags -@pytest.fixture # type: ignore +@pytest.fixture def changelog_content() -> str: changelog_path = "tests/CHANGELOG_FOR_TEST.md" with open(changelog_path, "r") as f: diff --git a/tests/test_changelog_parser.py b/tests/test_changelog_parser.py index 438b2f766d..ae6df53912 100644 --- a/tests/test_changelog_parser.py +++ b/tests/test_changelog_parser.py @@ -25,7 +25,7 @@ """ -@pytest.fixture # type: ignore +@pytest.fixture def changelog_content() -> str: changelog_path = "tests/CHANGELOG_FOR_TEST.md" with open(changelog_path, "r") as f: From 8bd5d71166580a6b6cbce63575af6ac434e9dffa Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 25 Dec 2020 17:55:30 +0800 Subject: [PATCH 0031/1498] style(mypy): add return type to all functions --- commitizen/bump.py | 4 ++-- commitizen/config/base_config.py | 6 +++--- commitizen/config/json_config.py | 2 +- commitizen/config/toml_config.py | 2 +- commitizen/config/yaml_config.py | 2 +- commitizen/defaults.py | 19 +++++++++++++++++-- commitizen/git.py | 4 ++-- commitizen/out.py | 10 +++++----- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index f3319fc1cc..6c09e2f16d 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -132,7 +132,7 @@ def generate_version( def update_version_in_files( current_version: str, new_version: str, files: List[str], *, check_consistency=False -): +) -> None: """Change old version to the new one in every file given. Note that this version is not the tag formatted one. @@ -196,7 +196,7 @@ def _version_to_regex(version: str): return re.compile(f"{clean_regex}") -def create_tag(version: Union[Version, str], tag_format: Optional[str] = None): +def create_tag(version: Union[Version, str], tag_format: Optional[str] = None) -> str: """The tag and the software version might be different. That's why this function exists. diff --git a/commitizen/config/base_config.py b/commitizen/config/base_config.py index 76cd1706e1..2c6e3cf21b 100644 --- a/commitizen/config/base_config.py +++ b/commitizen/config/base_config.py @@ -25,11 +25,11 @@ def set_key(self, key, value): """ raise NotImplementedError() - def update(self, data: dict): + def update(self, data: dict) -> None: self._settings.update(data) - def add_path(self, path: Union[str, Path]): + def add_path(self, path: Union[str, Path]) -> None: self._path = Path(path) - def _parse_setting(self, data: Union[bytes, str]) -> dict: + def _parse_setting(self, data: Union[bytes, str]) -> None: raise NotImplementedError() diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index 445f2aac5f..a40a8ceb20 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -30,7 +30,7 @@ def set_key(self, key, value): json.dump(parser, f, indent=2) return self - def _parse_setting(self, data: Union[bytes, str]): + def _parse_setting(self, data: Union[bytes, str]) -> None: """We expect to have a section in .cz.json looking like ``` diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index b5b7f7b2a1..c2a90cec9f 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -41,7 +41,7 @@ def set_key(self, key, value): f.write(parser.as_string().encode("utf-8")) return self - def _parse_setting(self, data: Union[bytes, str]): + def _parse_setting(self, data: Union[bytes, str]) -> None: """We expect to have a section in pyproject looking like ``` diff --git a/commitizen/config/yaml_config.py b/commitizen/config/yaml_config.py index 5d199c1929..1d44e64f3b 100644 --- a/commitizen/config/yaml_config.py +++ b/commitizen/config/yaml_config.py @@ -17,7 +17,7 @@ def init_empty_config_content(self): with open(self.path, "a") as json_file: yaml.dump({"commitizen": {}}, json_file) - def _parse_setting(self, data: Union[bytes, str]): + def _parse_setting(self, data: Union[bytes, str]) -> None: """We expect to have a section in cz.yaml looking like ``` diff --git a/commitizen/defaults.py b/commitizen/defaults.py index e460bbd6f7..5557a3fdc4 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,5 +1,20 @@ from collections import OrderedDict -from typing import Any, Dict, List +from typing import List, Optional, TypedDict + + +# Type +class Settings(TypedDict): + name: str + version: Optional[str] + version_files: List[str] + tag_format: Optional[str] + bump_message: Optional[str] + changelog_file: str + changelog_incremental: bool + changelog_start_rev: Optional[str] + update_changelog_on_bump: bool + use_shortcuts: bool + name: str = "cz_conventional_commits" config_files: List[str] = [ @@ -11,7 +26,7 @@ "cz.yaml", ] -DEFAULT_SETTINGS: Dict[str, Any] = { +DEFAULT_SETTINGS: Settings = { "name": "cz_conventional_commits", "version": None, "version_files": [], diff --git a/commitizen/git.py b/commitizen/git.py index b196f15115..03bb780c1b 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -54,12 +54,12 @@ def from_line(cls, line: str, inner_delimiter: str) -> "GitTag": return cls(name=name, rev=obj, date=date) -def tag(tag: str, annotated: bool = False): +def tag(tag: str, annotated: bool = False) -> cmd.Command: c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}") return c -def commit(message: str, args: str = ""): +def commit(message: str, args: str = "") -> cmd.Command: f = NamedTemporaryFile("wb", delete=False) f.write(message.encode("utf-8")) f.close() diff --git a/commitizen/out.py b/commitizen/out.py index 7ac5ba420b..a25f0f2e32 100644 --- a/commitizen/out.py +++ b/commitizen/out.py @@ -3,27 +3,27 @@ from termcolor import colored -def write(value: str, *args): +def write(value: str, *args) -> None: """Intended to be used when value is multiline.""" print(value, *args) -def line(value: str, *args, **kwargs): +def line(value: str, *args, **kwargs) -> None: """Wrapper in case I want to do something different later.""" print(value, *args, **kwargs) -def error(value: str): +def error(value: str) -> None: message = colored(value, "red") line(message, file=sys.stderr) -def success(value: str): +def success(value: str) -> None: message = colored(value, "green") line(message) -def info(value: str): +def info(value: str) -> None: message = colored(value, "blue") line(message) From cd72fd1302e511cfae87239ea243f433de91c342 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 27 Nov 2021 11:51:48 +0800 Subject: [PATCH 0032/1498] refactor(defaults): add Settings typeddict --- commitizen/config/base_config.py | 10 +++++----- commitizen/defaults.py | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/commitizen/config/base_config.py b/commitizen/config/base_config.py index 2c6e3cf21b..8935c4875d 100644 --- a/commitizen/config/base_config.py +++ b/commitizen/config/base_config.py @@ -1,16 +1,16 @@ from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Optional, Union -from commitizen.defaults import DEFAULT_SETTINGS +from commitizen.defaults import DEFAULT_SETTINGS, Settings class BaseConfig: def __init__(self): - self._settings: Dict[str, Any] = DEFAULT_SETTINGS.copy() + self._settings: Settings = DEFAULT_SETTINGS.copy() self._path: Optional[Path] = None @property - def settings(self) -> Dict[str, Any]: + def settings(self) -> Settings: return self._settings @property @@ -25,7 +25,7 @@ def set_key(self, key, value): """ raise NotImplementedError() - def update(self, data: dict) -> None: + def update(self, data: Settings) -> None: self._settings.update(data) def add_path(self, path: Union[str, Path]) -> None: diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 5557a3fdc4..f3dd319c6e 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,9 +1,9 @@ from collections import OrderedDict -from typing import List, Optional, TypedDict +from typing import Any, List, Optional, Tuple, TypedDict # Type -class Settings(TypedDict): +class Settings(TypedDict, total=False): name: str version: Optional[str] version_files: List[str] @@ -14,6 +14,8 @@ class Settings(TypedDict): changelog_start_rev: Optional[str] update_changelog_on_bump: bool use_shortcuts: bool + style: Optional[List[Tuple[str, str]]] + customize: Any name: str = "cz_conventional_commits" From b06b034764908e3e69e5fdf0812f5000954f5c16 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 09:20:47 +0800 Subject: [PATCH 0033/1498] refactor(config): add CzSettings and Questions TypedDict --- commitizen/commands/init.py | 4 +- commitizen/cz/base.py | 5 ++- .../conventional_commits.py | 6 +-- commitizen/cz/customize/customize.py | 9 +++-- commitizen/cz/jira/jira.py | 4 +- commitizen/defaults.py | 40 ++++++++++++++++--- commitizen/git.py | 2 +- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index d4a4180aa3..d290612949 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -49,7 +49,7 @@ def __call__(self): out.line(f"Config file {self.config.path} already exists") def _ask_config_path(self) -> str: - name = questionary.select( + name: str = questionary.select( "Please choose a supported config file: (default: pyproject.toml)", choices=config_files, default="pyproject.toml", @@ -58,7 +58,7 @@ def _ask_config_path(self) -> str: return name def _ask_name(self) -> str: - name = questionary.select( + name: str = questionary.select( "Please choose a cz (commit rule): (default: cz_conventional_commits)", choices=list(registry.keys()), default="cz_conventional_commits", diff --git a/commitizen/cz/base.py b/commitizen/cz/base.py index 734852c868..a5abe35f16 100644 --- a/commitizen/cz/base.py +++ b/commitizen/cz/base.py @@ -5,11 +5,12 @@ from commitizen import git from commitizen.config.base_config import BaseConfig +from commitizen.defaults import Questions class BaseCommitizen(metaclass=ABCMeta): bump_pattern: Optional[str] = None - bump_map: Optional[dict] = None + bump_map: Optional[Dict[str, str]] = None default_style_config: List[Tuple[str, str]] = [ ("qmark", "fg:#ff9d00 bold"), ("question", "bold"), @@ -45,7 +46,7 @@ def __init__(self, config: BaseConfig): self.config.settings.update({"style": BaseCommitizen.default_style_config}) @abstractmethod - def questions(self) -> list: + def questions(self) -> Questions: """Questions regarding the commit message.""" @abstractmethod diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index f9890d46ba..47ce0d16c8 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -1,11 +1,11 @@ import os import re from collections import OrderedDict -from typing import Any, Dict, List from commitizen import defaults from commitizen.cz.base import BaseCommitizen from commitizen.cz.utils import multiple_line_breaker, required_validator +from commitizen.defaults import Questions __all__ = ["ConventionalCommitsCz"] @@ -49,8 +49,8 @@ class ConventionalCommitsCz(BaseCommitizen): "perf": "Perf", } - def questions(self) -> List[Dict[str, Any]]: - questions: List[Dict[str, Any]] = [ + def questions(self) -> Questions: + questions: Questions = [ { "type": "list", "name": "prefix", diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index acf205d06e..7a6f03a825 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -3,11 +3,12 @@ except ImportError: from string import Template # type: ignore -from typing import Any, Dict, List, Optional +from typing import Optional from commitizen import defaults from commitizen.config import BaseConfig from commitizen.cz.base import BaseCommitizen +from commitizen.defaults import Questions from commitizen.exceptions import MissingCzCustomizeConfigError __all__ = ["CustomizeCommitsCz"] @@ -37,11 +38,11 @@ def __init__(self, config: BaseConfig): if custom_change_type_order: self.change_type_order = custom_change_type_order - def questions(self) -> List[Dict[str, Any]]: - return self.custom_settings.get("questions") + def questions(self) -> Questions: + return self.custom_settings.get("questions", [{}]) def message(self, answers: dict) -> str: - message_template = Template(self.custom_settings.get("message_template")) + message_template = Template(self.custom_settings.get("message_template", "")) if getattr(Template, "substitute", None): return message_template.substitute(**answers) # type: ignore else: diff --git a/commitizen/cz/jira/jira.py b/commitizen/cz/jira/jira.py index 46c5965c46..bd3cd3c7ee 100644 --- a/commitizen/cz/jira/jira.py +++ b/commitizen/cz/jira/jira.py @@ -1,13 +1,13 @@ import os -from typing import Any, Dict, List from commitizen.cz.base import BaseCommitizen +from commitizen.defaults import Questions __all__ = ["JiraSmartCz"] class JiraSmartCz(BaseCommitizen): - def questions(self) -> List[Dict[str, Any]]: + def questions(self) -> Questions: questions = [ { "type": "input", diff --git a/commitizen/defaults.py b/commitizen/defaults.py index f3dd319c6e..f508f6b9a7 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,8 +1,35 @@ -from collections import OrderedDict -from typing import Any, List, Optional, Tuple, TypedDict - +import collections +import pathlib +from typing import ( + Any, + Iterable, + List, + MutableMapping, + Optional, + OrderedDict, + Tuple, + TypedDict, + Union, +) # Type +Questions = Iterable[MutableMapping[str, Any]] + + +class CzSettings(TypedDict, total=False): + bump_pattern: str + bump_map: OrderedDict[str, str] + change_type_order: List[str] + + questions: Questions + example: Optional[str] + schema_pattern: Optional[str] + schema: Optional[str] + info_path: Union[str, pathlib.Path] + info: str + message_template: str + + class Settings(TypedDict, total=False): name: str version: Optional[str] @@ -15,7 +42,7 @@ class Settings(TypedDict, total=False): update_changelog_on_bump: bool use_shortcuts: bool style: Optional[List[Tuple[str, str]]] - customize: Any + customize: CzSettings name: str = "cz_conventional_commits" @@ -46,7 +73,7 @@ class Settings(TypedDict, total=False): PATCH = "PATCH" bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?" -bump_map = OrderedDict( +bump_map = collections.OrderedDict( ( (r"^.+!$", MAJOR), (r"^BREAKING[\-\ ]CHANGE", MAJOR), @@ -56,9 +83,10 @@ class Settings(TypedDict, total=False): (r"^perf", PATCH), ) ) +change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"] + bump_message = "bump: version $current_version → $new_version" -change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"] commit_parser = r"^(?Pfeat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P[^()\r\n]*)\)|\()?(?P!)?:\s(?P.*)?" # noqa version_parser = r"(?P([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)" diff --git a/commitizen/git.py b/commitizen/git.py index 03bb780c1b..4e60b68793 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -14,7 +14,7 @@ class GitObject: def __eq__(self, other) -> bool: if not hasattr(other, "rev"): return False - return self.rev == other.rev + return self.rev == other.rev # type: ignore class GitCommit(GitObject): From 6c4f99260dbff8789266867e9305048be0fe5890 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 09:32:53 +0800 Subject: [PATCH 0034/1498] style(mypy): enforce warn_return_any check --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e85ca41fff..0c3a421421 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ ignore_missing_imports = true disallow_untyped_decorators = true # disallow_any_generics = True disallow_subclassing_any = true -# warn_return_any = True +warn_return_any = True warn_redundant_casts = true warn_unused_ignores = true warn_unused_configs = true From 7f5d435c10083808cb3e53d80658f590619c8363 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 09:43:19 +0800 Subject: [PATCH 0035/1498] fix: import TypedDict from type_extensions for backward compatibility --- commitizen/defaults.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index f508f6b9a7..e4429216be 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -8,10 +8,11 @@ Optional, OrderedDict, Tuple, - TypedDict, Union, ) +from typing_extensions import TypedDict + # Type Questions = Iterable[MutableMapping[str, Any]] From 3dc0bf6bf06f70f06029f447ff551f918dd72cc3 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:03:29 +0800 Subject: [PATCH 0036/1498] style(defaults): annoate OrderedDict through 'OrderedDict' for 3.6 compatibility --- commitizen/defaults.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index e4429216be..3fa7c5256d 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,15 +1,6 @@ -import collections import pathlib -from typing import ( - Any, - Iterable, - List, - MutableMapping, - Optional, - OrderedDict, - Tuple, - Union, -) +from collections import OrderedDict +from typing import Any, Iterable, List, MutableMapping, Optional, Tuple, Union from typing_extensions import TypedDict @@ -19,7 +10,7 @@ class CzSettings(TypedDict, total=False): bump_pattern: str - bump_map: OrderedDict[str, str] + bump_map: "OrderedDict[str, str]" change_type_order: List[str] questions: Questions @@ -74,7 +65,7 @@ class Settings(TypedDict, total=False): PATCH = "PATCH" bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?" -bump_map = collections.OrderedDict( +bump_map = OrderedDict( ( (r"^.+!$", MAJOR), (r"^BREAKING[\-\ ]CHANGE", MAJOR), From e51dac51d53810827cd2741d7ac9127b663e2890 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 10:21:22 +0800 Subject: [PATCH 0037/1498] refactor(conventional_commits): remove duplicate patterns and import from defaults --- .../conventional_commits/conventional_commits.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 47ce0d16c8..248df0f319 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -1,6 +1,5 @@ import os import re -from collections import OrderedDict from commitizen import defaults from commitizen.cz.base import BaseCommitizen @@ -29,18 +28,9 @@ def parse_subject(text): class ConventionalCommitsCz(BaseCommitizen): - bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?" - bump_map = OrderedDict( - ( - (r"^.+!$", defaults.MAJOR), - (r"^BREAKING[\-\ ]CHANGE", defaults.MAJOR), - (r"^feat", defaults.MINOR), - (r"^fix", defaults.PATCH), - (r"^refactor", defaults.PATCH), - (r"^perf", defaults.PATCH), - ) - ) - commit_parser = r"^(?Pfeat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P[^()\r\n]*)\)|\()?(?P!)?:\s(?P.*)?" # noqa + bump_pattern = defaults.bump_pattern + bump_map = defaults.bump_map + commit_parser = defaults.commit_parser version_parser = defaults.version_parser change_type_map = { "feat": "Feat", From f8e09acb974c81d7dcce82d7ab059543a859beed Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 23:14:06 +0800 Subject: [PATCH 0038/1498] docs(customization): update question type to Questions (from commitizen.defaults) --- docs/customization.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/customization.md b/docs/customization.md index 74ac0707b6..f9cae2a10a 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -140,7 +140,7 @@ commitizen: | Parameter | Type | Default | Description | | ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `questions` | `dict` | `None` | Questions regarding the commit message. Detailed below. | +| `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is definied in `commitizen.defaults`. | | `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2][jinja2] formatting specification, and all the variables in this template should be defined in `name` in `questions` | | `example` | `str` | `None` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. | | `schema` | `str` | `None` | (OPTIONAL) Show the schema used. Used by `cz schema`. | @@ -152,6 +152,7 @@ commitizen: | `change_type_order` | `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]` | [jinja2]: https://jinja.palletsprojects.com/en/2.10.x/ + #### Detailed `questions` content | Parameter | Type | Default | Description | @@ -162,7 +163,6 @@ commitizen: | `choices` | `list` | `None` | (OPTIONAL) The choices when `type = list`. Either use a list of values or a list of dictionaries with `name` and `value` keys. Keyboard shortcuts can be defined via `key`. See examples above. | | `default` | `Any` | `None` | (OPTIONAL) The default value for this question. | | `filter` | `str` | `None` | (Optional) Validator for user's answer. **(Work in Progress)** | - [different-question-types]: https://github.com/tmbo/questionary#different-question-types #### Shortcut keys @@ -194,15 +194,15 @@ See [commitizen_cz_template](https://github.com/commitizen-tools/commitizen_cz_t Create a file starting with `cz_`, for example `cz_jira.py`. This prefix is used to detect the plug-in. Same method [flask uses] -Inherit from `BaseCommitizen`, and you must define `questions` and -`message`. The others are optional. +Inherit from `BaseCommitizen`, and you must define `questions` and `message`. The others are optional. ```python from commitizen.cz.base import BaseCommitizen +from commitizen.defaults import Questions class JiraCz(BaseCommitizen): - - def questions(self) -> list: + # Questions = Iterable[MutableMapping[str, Any]] + def questions(self) -> Questions: """Questions regarding the commit message.""" questions = [ { From 9cc0a82ef1975861e071a9981aab9e279c7334c7 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 8 Dec 2021 23:43:45 +0800 Subject: [PATCH 0039/1498] docs(customization): detailed what a Questoin expect --- docs/customization.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/customization.md b/docs/customization.md index f9cae2a10a..58303e4f14 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -140,7 +140,7 @@ commitizen: | Parameter | Type | Default | Description | | ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is definied in `commitizen.defaults`. | +| `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is definied in `commitizen.defaults`. It expects a list of dictionaries. | | `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2][jinja2] formatting specification, and all the variables in this template should be defined in `name` in `questions` | | `example` | `str` | `None` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. | | `schema` | `str` | `None` | (OPTIONAL) Show the schema used. Used by `cz schema`. | @@ -202,6 +202,7 @@ from commitizen.defaults import Questions class JiraCz(BaseCommitizen): # Questions = Iterable[MutableMapping[str, Any]] + # It expect a list with dictionaries. def questions(self) -> Questions: """Questions regarding the commit message.""" questions = [ From 2f160dc317279510831322565a60aaacca76702a Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 9 Dec 2021 08:53:35 +0800 Subject: [PATCH 0040/1498] docs(customization): fix typo --- docs/customization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/customization.md b/docs/customization.md index 58303e4f14..2c69e037b4 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -202,7 +202,7 @@ from commitizen.defaults import Questions class JiraCz(BaseCommitizen): # Questions = Iterable[MutableMapping[str, Any]] - # It expect a list with dictionaries. + # It expects a list with dictionaries. def questions(self) -> Questions: """Questions regarding the commit message.""" questions = [ From bd7e866ed09c83475a2fdd107b4f92046329eb7c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 14 Dec 2021 01:32:10 +0000 Subject: [PATCH 0041/1498] =?UTF-8?q?bump:=20version=202.20.0=20=E2=86=92?= =?UTF-8?q?=202.20.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 13 +++++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac409aef82..57f1c3c2d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,17 @@ +## v2.20.1 (2021-12-14) + +### Refactor + +- **conventional_commits**: remove duplicate patterns and import from defaults +- **config**: add CzSettings and Questions TypedDict +- **defaults**: add Settings typeddict +- **defaults**: move bump_map, bump_pattern, commit_parser from defaults to ConventionalCommitsCz + +### Fix + +- import TypedDict from type_extensions for backward compatibility + ## v2.20.0 (2021-10-06) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 3ea83e0a69..7843237ad4 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.0" +__version__ = "2.20.1" diff --git a/pyproject.toml b/pyproject.toml index a8a7da5782..bcc8fc7c2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.0" +version = "2.20.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.0" +version = "2.20.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 505a271e12e2e02fb11a9c58a0064542de185069 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 14 Dec 2021 10:25:48 +0800 Subject: [PATCH 0042/1498] fix(poetry): add typing-exteions to dev --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index bcc8fc7c2a..4497324dfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ pytest-regressions = "^2.2.0" pytest-freezegun = "^0.4.2" types-PyYAML = "^5.4.3" types-termcolor = "^0.1.1" +typing-extensions = "^4.0.1" [tool.poetry.scripts] cz = "commitizen.cli:main" From 48f9b7eb1fca4ae485d6f892b041eb5b767b41b2 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 14 Dec 2021 10:35:29 +0800 Subject: [PATCH 0043/1498] build(poetry): move typing-extension to prod dep and group dev deps --- pyproject.toml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4497324dfd..7cf357f307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,27 +54,31 @@ tomlkit = ">=0.5.3,<1.0.0" jinja2 = ">=2.10.3" pyyaml = ">=3.08" argcomplete = "^1.12.1" +typing-extensions = "^4.0.1" [tool.poetry.dev-dependencies] ipython = "^7.2" -black = "^21.12b0" +# test pytest = "^5.0" -flake8 = "^3.6" pytest-cov = "^2.6" pytest-mock = "^2.0" codecov = "^2.0" -mypy = "0.910" -mkdocs = "^1.0" -mkdocs-material = "^4.1" -isort = "^5.7.0" freezegun = "^0.3.15" -pydocstyle = "^5.0.2" -pre-commit = "^2.6.0" pytest-regressions = "^2.2.0" pytest-freezegun = "^0.4.2" +# code formatter +black = "^21.12b0" +isort = "^5.7.0" +# linter +flake8 = "^3.6" +pre-commit = "^2.6.0" +mypy = "0.910" types-PyYAML = "^5.4.3" types-termcolor = "^0.1.1" -typing-extensions = "^4.0.1" +# documentation +mkdocs = "^1.0" +mkdocs-material = "^4.1" +pydocstyle = "^5.0.2" [tool.poetry.scripts] cz = "commitizen.cli:main" From 6ddd68de55bee3481c0edb3cb344c8f90dd53074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Tue, 14 Dec 2021 08:04:58 +0100 Subject: [PATCH 0044/1498] =?UTF-8?q?bump:=20version=202.20.1=20=E2=86=92?= =?UTF-8?q?=202.20.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f1c3c2d4..88d416e14a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.20.2 (2021-12-14) + +### Fix + +- **poetry**: add typing-exteions to dev + ## v2.20.1 (2021-12-14) ### Refactor diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 7843237ad4..5ad8e50957 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.1" +__version__ = "2.20.2" diff --git a/pyproject.toml b/pyproject.toml index 7cf357f307..6b976d47af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.1" +version = "2.20.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.1" +version = "2.20.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 1216a9e866e9200843c1cf7ca582ccdf9b8ba3fc Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Tue, 14 Dec 2021 10:46:37 -0500 Subject: [PATCH 0045/1498] build: use poetry_core to build instead of poetry --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6b976d47af..a859776a52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,5 +116,5 @@ known_first_party = ["commitizen", "tests"] ] [build-system] -requires = ["poetry>=0.12"] -build-backend = "poetry.masonry.api" +requires = ["poetry_core>=1.0.0"] +build-backend = "poetry.core.masonry.api" From 9ccabe58bafe494098598a73e9e9c44782db22e9 Mon Sep 17 00:00:00 2001 From: yuukidach Date: Thu, 16 Dec 2021 00:59:50 +0800 Subject: [PATCH 0046/1498] fix(check): filter out comment messege when checking fix #455 --- commitizen/commands/check.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 33fd08a7d0..9fcca39e4f 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -81,15 +81,23 @@ def _get_commits(self): # Get commit message from file (--commit-msg-file) if self.commit_msg_file: with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: - commit_title = commit_file.readline() - commit_body = commit_file.read() + msg = commit_file.read() + msg = self._filter_comments(msg) + msg = msg.lstrip("\n") + commit_title = msg.split("\n")[0] + commit_body = "\n".join(msg.split("\n")[1:]) return [git.GitCommit(rev="", title=commit_title, body=commit_body)] elif self.commit_msg: + self.commit_msg = self._filter_comments(self.commit_msg) return [git.GitCommit(rev="", title="", body=self.commit_msg)] # Get commit messages from git log (--rev-range) return git.get_commits(end=self.rev_range) + def _filter_comments(self, msg: str) -> str: + lines = [line for line in msg.split('\n') if not line.startswith('#')] + return "\n".join(lines) + @staticmethod def validate_commit_message(commit_msg: str, pattern: str) -> bool: if commit_msg.startswith("Merge") or commit_msg.startswith("Revert"): From 87e23270fe2aa2a786ba66d23896f108629696cb Mon Sep 17 00:00:00 2001 From: yuukidach Date: Thu, 16 Dec 2021 01:41:40 +0800 Subject: [PATCH 0047/1498] test(check): add test of checking commit message with comment in it --- commitizen/commands/check.py | 2 +- tests/commands/test_check_command.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 9fcca39e4f..3c06c97647 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -95,7 +95,7 @@ def _get_commits(self): return git.get_commits(end=self.rev_range) def _filter_comments(self, msg: str) -> str: - lines = [line for line in msg.split('\n') if not line.startswith('#')] + lines = [line for line in msg.split("\n") if not line.startswith("#")] return "\n".join(lines) @staticmethod diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index 7377a8a388..26db697b50 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -275,3 +275,23 @@ def test_check_command_with_pipe_message_and_failed(mocker): with pytest.raises(InvalidCommitMessageError) as excinfo: cli.main() assert "commit validation: failed!" in str(excinfo.value) + + +def test_check_command_with_comment_in_messege_file(mocker, capsys): + testargs = ["cz", "check", "--commit-msg-file", "some_file"] + mocker.patch.object(sys, "argv", testargs) + mocker.patch( + "commitizen.commands.check.open", + mocker.mock_open( + read_data="# : (If applied, this commit will...) \n" + "# |<---- Try to Limit to a Max of 50 char ---->|\n" + "ci: add commitizen pre-commit hook\n" + "\n" + "# Explain why this change is being made\n" + "# |<---- Try To Limit Each Line to a Max Of 72 Char ---->|\n" + "This pre-commit hook will check our commits automatically." + ), + ) + cli.main() + out, _ = capsys.readouterr() + assert "Commit validation: successful!" in out From b46e403ee36034c9b74d86dfa039d60f9d7123c8 Mon Sep 17 00:00:00 2001 From: yuukidach Date: Sat, 18 Dec 2021 14:06:38 +0800 Subject: [PATCH 0048/1498] docs(check): add a notice that comment in git message will be ignored --- docs/check.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/check.md b/docs/check.md index 9150f608de..e1f0344e16 100644 --- a/docs/check.md +++ b/docs/check.md @@ -1,8 +1,9 @@ # Check ## About -This feature checks whether the commit message follows the given committing rules. -If you want to setup an automatic check before every git commit, please refer to +This feature checks whether the commit message follows the given committing rules. And comment in git message will be ignored. + +If you want to setup an automatic check before every git commit, please refer to [Automatically check message before commit](auto_check.md). ## Usage From 7c7881f7635af4022b169870b067b278563e7bf5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 20 Dec 2021 00:01:51 +0000 Subject: [PATCH 0049/1498] =?UTF-8?q?bump:=20version=202.20.2=20=E2=86=92?= =?UTF-8?q?=202.20.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88d416e14a..533433521e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.20.3 (2021-12-20) + +### Fix + +- **check**: filter out comment messege when checking + ## v2.20.2 (2021-12-14) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 5ad8e50957..c6710ef750 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.2" +__version__ = "2.20.3" diff --git a/pyproject.toml b/pyproject.toml index 6b976d47af..372d40b56e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.2" +version = "2.20.3" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.2" +version = "2.20.3" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From f8da3f50fb3e4d097367ebe9240f88339cfa9872 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Tue, 14 Dec 2021 11:49:54 -0500 Subject: [PATCH 0050/1498] test: bump pytest version to support Python 3.10 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 646da07854..219e669d1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ typing-extensions = "^4.0.1" [tool.poetry.dev-dependencies] ipython = "^7.2" # test -pytest = "^5.0" +pytest = "^6.2.5" pytest-cov = "^2.6" pytest-mock = "^2.0" codecov = "^2.0" From d5e782d80b6cb743f48740dc43cb0b53e76d75ee Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Wed, 22 Dec 2021 13:02:18 -0500 Subject: [PATCH 0051/1498] test(conftest.py): remove 'type: ignore' that is unneeded with updated pytest --- tests/commands/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index 46e9500365..3447b97422 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -13,11 +13,11 @@ def config(): return _config -@pytest.fixture() # type: ignore +@pytest.fixture() def changelog_path() -> str: return os.path.join(os.getcwd(), "CHANGELOG.md") -@pytest.fixture() # type: ignore +@pytest.fixture() def config_path() -> str: return os.path.join(os.getcwd(), "pyproject.toml") From 1f37002709d3f2fb351a3bcfe432c300402d16c0 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Tue, 14 Dec 2021 11:35:02 -0500 Subject: [PATCH 0052/1498] ci: test on Python 3.10 --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 51fb46832d..90ccbaaa30 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -6,7 +6,7 @@ jobs: python-check: strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: From 308de9c91bdf779028af11dd0dbf9efb71ce1e23 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 5 Jan 2022 14:24:54 +0100 Subject: [PATCH 0053/1498] docs: Fix exit code for NoCommitsFoundError The source code indicates that the correct exit code is 3. See https://github.com/commitizen-tools/commitizen/blob/master/commitizen/exceptions.py#L10 --- docs/exit_codes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/exit_codes.md b/docs/exit_codes.md index cae66b8bab..28f8f64198 100644 --- a/docs/exit_codes.md +++ b/docs/exit_codes.md @@ -10,7 +10,7 @@ These exit codes can be found in `commitizen/exceptions.py::ExitCode`. | DryRunExit | 0 | Exit due to passing `--dry-run` option | | NoCommitizenFoundException | 1 | Using a cz (e.g., `cz_jira`) that cannot be found in your system | | NotAGitProjectError | 2 | Not in a git project | -| NoCommitsFoundError | 4 | No commit found | +| NoCommitsFoundError | 3 | No commit found | | NoVersionSpecifiedError | 4 | Version can not be found in configuration file | | NoPatternMapError | 5 | bump / changelog pattern or map can not be found in configuration file | | BumpCommitFailedError | 6 | Commit error when bumping version | From 323c72ec2e285dd0bf119a190b818076407de6e0 Mon Sep 17 00:00:00 2001 From: Chris Murray Date: Fri, 14 Jan 2022 19:18:11 +0000 Subject: [PATCH 0054/1498] docs: removing customization file contradiction Customising via the configuration file is clearly possible when using yaml files since you show an example for this. This PR updates the doc to remove the warning that states this is not possible. Given that yaml was the only missing file type in the original warning it seems safe to remove it completely. --- docs/customization.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/customization.md b/docs/customization.md index 2c69e037b4..f39c9bcc11 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -3,8 +3,6 @@ We have two different ways to do so. ## 1. Customize in configuration file -**This is only supported when configuring through `toml` or `json` (e.g., `pyproject.toml`, `.cz.toml`, `.cz.json`, and `cz.json`)** - The basic steps are: 1. Define your custom committing or bumping rules in the configuration file. From dac6de03fe30cb4d76a5504b481c7beef881031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Sun, 16 Jan 2022 19:13:45 +0100 Subject: [PATCH 0055/1498] fix(bump): raise non zero error code when there's no elegible commit to bump --- commitizen/commands/bump.py | 5 ++++- commitizen/exceptions.py | 4 ++-- tests/commands/test_bump_command.py | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 4f2a0d3981..70dcad263f 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -170,7 +170,10 @@ def __call__(self): # noqa: C901 out.write(information) if increment is None and new_tag_version == current_tag_version: - raise NoneIncrementExit() + raise NoneIncrementExit( + "[NO_COMMITS_TO_BUMP]\n" + "The commits found are not elegible to be bumped" + ) # Do not perform operations over files or git. if dry_run: diff --git a/commitizen/exceptions.py b/commitizen/exceptions.py index 8293688715..218534c730 100644 --- a/commitizen/exceptions.py +++ b/commitizen/exceptions.py @@ -54,8 +54,8 @@ class DryRunExit(ExpectedExit): pass -class NoneIncrementExit(ExpectedExit): - pass +class NoneIncrementExit(CommitizenException): + exit_code = ExitCode.NO_COMMITS_FOUND class NoCommitizenFoundException(CommitizenException): diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 8508c66eee..b5c7b6b122 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -8,8 +8,10 @@ from commitizen import cli, cmd, git from commitizen.exceptions import ( BumpTagFailedError, + CommitizenException, CurrentVersionNotFoundError, DryRunExit, + ExitCode, ExpectedExit, NoCommitsFoundError, NoneIncrementExit, @@ -327,7 +329,7 @@ def test_none_increment_exit_should_be_a_class(): def test_none_increment_exit_should_be_expected_exit_subclass(): - assert issubclass(NoneIncrementExit, ExpectedExit) + assert issubclass(NoneIncrementExit, CommitizenException) def test_none_increment_exit_should_exist_in_bump(): @@ -339,7 +341,9 @@ def test_none_increment_exit_is_exception(): @pytest.mark.usefixtures("tmp_commitizen_project") -def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project): +def test_none_increment_should_not_call_git_tag_and_error_code_is_not_zero( + mocker, tmp_commitizen_project +): create_file_and_commit("test(test_get_all_droplets): fix bad comparison test") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) @@ -350,8 +354,12 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project): git.tag = MagicMock(return_value=dummy_value) with pytest.raises(NoneIncrementExit): - cli.main() - git.tag.assert_not_called() + try: + cli.main() + except NoneIncrementExit as e: + git.tag.assert_not_called() + assert e.exit_code == ExitCode.NO_COMMITS_FOUND + raise e # restore pop stashed git.tag = stashed_git_tag From 834159d4cafe09d273171da3dc3409ad0940d20c Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Mon, 17 Jan 2022 18:44:11 +0800 Subject: [PATCH 0056/1498] docs(external_links): add freecode camp tutorial --- docs/external_links.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/external_links.md b/docs/external_links.md index 69ad952c66..c9857e2fb4 100644 --- a/docs/external_links.md +++ b/docs/external_links.md @@ -12,5 +12,6 @@ - [Python Table Manners - Commitizen: 規格化 commit message](https://lee-w.github.io/posts/tech/2020/03/python-table-manners-commitizen/) (Written in Traditional Mandarin) - [Automating semantic release with commitizen](https://woile.dev/posts/automating-semver-releases-with-commitizen/) (English) +- [How to Write Better Git Commit Messages – A Step-By-Step Guide](https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/?utm_source=tldrnewsletter) (English) [automatizando]: https://youtu.be/t3aE2M8UPBo From 297ff789d691e55fba9edd6c5f4cd70df9d1e57e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 17 Jan 2022 10:44:23 +0000 Subject: [PATCH 0057/1498] =?UTF-8?q?bump:=20version=202.20.3=20=E2=86=92?= =?UTF-8?q?=202.20.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533433521e..2fd4fd2647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## v2.20.4 (2022-01-17) + +### Fix + +- **bump**: raise non zero error code when there's no elegible commit to bump +- **bump**: raise non zero error code when there's no elegible commit to bump + ## v2.20.3 (2021-12-20) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index c6710ef750..b843b67a42 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.3" +__version__ = "2.20.4" diff --git a/pyproject.toml b/pyproject.toml index 219e669d1b..bf29b88b65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.3" +version = "2.20.4" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.3" +version = "2.20.4" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 9f0e326b5e9bbeef14949a0aeb52004a81147583 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Mon, 17 Jan 2022 12:40:08 -0500 Subject: [PATCH 0058/1498] docs: add Why not CalVer to FAQ --- docs/faq.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 7e1450e33c..8e4287d8df 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -86,3 +86,28 @@ git commit -m "revert: foo bar" This error was caused by a Python bug on Windows. It's been fixed by [this PR](https://github.com/python/cpython/pull/22017), and according to Python's changelog, [3.8.6rc1](https://docs.python.org/3.8/whatsnew/changelog.html#python-3-8-6-release-candidate-1) and [3.9.0rc2](https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-0-release-candidate-2) should be the accurate versions first contain this fix. In conclusion, upgrade your Python version might solve this issue. More discussion can be found in issue [#318](https://github.com/commitizen-tools/commitizen/issues/318). + +## Why does commitizen not support CalVer? + +`commitizen` could support CalVer alongside SemVer, but in practice implementing CalVer +creates numerous edge cases that are difficult to maintain (#385) and more generally +mixing the two version schemes may not be a good idea. If CalVer or other custom +versioning scheme is needed, `commitizen` could still be used to standardize commits +and create changelogs, but a separate package should be used for version increments. + +Mixing CalVer and SemVer is generally not recommended because each versioning scheme +serves a different purposes. Diverging from either specification can be confusing to +users and cause errors when third party tools that don't expect the non-standard format. + +In the future, `commitizen` may support some implementation of CalVer, but at the time +of writing, there are no plans to implement the feature (#173). + +If you would like to learn more about both schemes, there are plenty of good resources: + +- [Announcing CalVer](https://sedimental.org/calver.html) +- [API Versioning from Stripe](https://stripe.com/blog/api-versioning) +- [Discussion about pip's use of CalVer](https://github.com/pypa/pip/issues/5645#issuecomment-407192448) +- [Git Version Numbering](https://code.erpenbeck.io/git/2021/12/16/git-version-numbering/) +- [SemVer vs. CalVer and Why I Use Both](https://mikestaszel.com/2021/04/03/semver-vs-calver-and-why-i-use-both/) (but not at the same time) +- [Semver Will Not Save You](https://hynek.me/articles/semver-will-not-save-you/) +- [Why I Don't Like SemVer](https://snarky.ca/why-i-dont-like-semver/) From 71d2d58c76c71551d4dba97bd432eb7786f45c86 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Mon, 17 Jan 2022 12:43:21 -0500 Subject: [PATCH 0059/1498] docs: fix links to Github --- docs/faq.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 8e4287d8df..eb1c98068b 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -90,17 +90,17 @@ More discussion can be found in issue [#318](https://github.com/commitizen-tools ## Why does commitizen not support CalVer? `commitizen` could support CalVer alongside SemVer, but in practice implementing CalVer -creates numerous edge cases that are difficult to maintain (#385) and more generally +creates numerous edge cases that are difficult to maintain ([#385]) and more generally mixing the two version schemes may not be a good idea. If CalVer or other custom versioning scheme is needed, `commitizen` could still be used to standardize commits and create changelogs, but a separate package should be used for version increments. Mixing CalVer and SemVer is generally not recommended because each versioning scheme serves a different purposes. Diverging from either specification can be confusing to -users and cause errors when third party tools that don't expect the non-standard format. +users and cause errors with third party tools that don't expect the non-standard format. In the future, `commitizen` may support some implementation of CalVer, but at the time -of writing, there are no plans to implement the feature (#173). +of writing, there are no plans to implement the feature ([#173]). If you would like to learn more about both schemes, there are plenty of good resources: @@ -111,3 +111,6 @@ If you would like to learn more about both schemes, there are plenty of good res - [SemVer vs. CalVer and Why I Use Both](https://mikestaszel.com/2021/04/03/semver-vs-calver-and-why-i-use-both/) (but not at the same time) - [Semver Will Not Save You](https://hynek.me/articles/semver-will-not-save-you/) - [Why I Don't Like SemVer](https://snarky.ca/why-i-dont-like-semver/) + +[#173]: https://github.com/commitizen-tools/commitizen/issues/173 +[#385]: https://github.com/commitizen-tools/commitizen/pull/385 From 258f7c9d5bd09cccfb31b5b71523977ac1c4d64b Mon Sep 17 00:00:00 2001 From: Ae-Mc Date: Wed, 26 Jan 2022 20:56:56 +0300 Subject: [PATCH 0060/1498] docs(config.md,customization.md): Fix indentation (replace tabs (\t) with four spaces) --- docs/config.md | 4 ++-- docs/customization.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/config.md b/docs/config.md index 342219fef2..cc278e3865 100644 --- a/docs/config.md +++ b/docs/config.md @@ -38,8 +38,8 @@ JSON might be a more common configuration format for non-python projects, so Com "name": "cz_conventional_commits", "version": "0.1.0", "version_files": [ - "src/__version__.py", - "pyproject.toml:version" + "src/__version__.py", + "pyproject.toml:version" ], "style": [ [ diff --git a/docs/customization.md b/docs/customization.md index f39c9bcc11..b165638e7c 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -50,7 +50,7 @@ The equivalent example for a json config file: ```json { "commitizen": { - "name": "cz_customize", + "name": "cz_customize", "customize": { "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}", "example": "feature: this feature enable customize through config file", @@ -64,7 +64,7 @@ The equivalent example for a json config file: "hotfix": "PATCH" }, "change_type_order": ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"], - "info_path": "cz_customize_info.txt", + "info_path": "cz_customize_info.txt", "info": "This is customized info", "questions": [ { From 05aac7433d0334518b994167422c8f664bcb84d3 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 28 Jan 2022 17:03:11 +0100 Subject: [PATCH 0061/1498] fix: Ignore packages that are not plugins When a package starting with a plugin name is found, but it is not a plugin, it becomes safely ignored. --- commitizen/cz/__init__.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index a14ea95edf..b681c858f0 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -1,21 +1,30 @@ import importlib +import logging import pkgutil -from typing import Dict, Type +from typing import Dict, Type from commitizen.cz.base import BaseCommitizen from commitizen.cz.conventional_commits import ConventionalCommitsCz from commitizen.cz.customize import CustomizeCommitsCz from commitizen.cz.jira import JiraSmartCz +logger = logging.getLogger(__name__) + +def discover_plugins(): + plugins = {} + for finder, name, ispkg in pkgutil.iter_modules(): + try: + if name.startswith("cz_"): + plugins[name] = importlib.import_module(name).discover_this + except AttributeError as e: + logger.warning(e.args[0]) + continue + return plugins + registry: Dict[str, Type[BaseCommitizen]] = { "cz_conventional_commits": ConventionalCommitsCz, "cz_jira": JiraSmartCz, "cz_customize": CustomizeCommitsCz, } -plugins = { - name: importlib.import_module(name).discover_this # type: ignore - for finder, name, ispkg in pkgutil.iter_modules() - if name.startswith("cz_") -} -registry.update(plugins) +registry.update(discover_plugins()) From 04989381bcf76cb0285fb5060d3c61ea0955532f Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 28 Jan 2022 17:33:35 +0100 Subject: [PATCH 0062/1498] style: format code --- commitizen/cz/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index b681c858f0..f17f0a7815 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -1,8 +1,8 @@ import importlib import logging import pkgutil - from typing import Dict, Type + from commitizen.cz.base import BaseCommitizen from commitizen.cz.conventional_commits import ConventionalCommitsCz from commitizen.cz.customize import CustomizeCommitsCz @@ -10,6 +10,7 @@ logger = logging.getLogger(__name__) + def discover_plugins(): plugins = {} for finder, name, ispkg in pkgutil.iter_modules(): @@ -21,6 +22,7 @@ def discover_plugins(): continue return plugins + registry: Dict[str, Type[BaseCommitizen]] = { "cz_conventional_commits": ConventionalCommitsCz, "cz_jira": JiraSmartCz, From fe5e08930379fd0fdc7f4f28f0901a01224104b1 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 28 Jan 2022 18:33:43 +0100 Subject: [PATCH 0063/1498] test: Checking that warnings are risen --- commitizen/cz/__init__.py | 20 ++++++++++++++------ tests/test_factory.py | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index f17f0a7815..1699649d3e 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -1,24 +1,32 @@ import importlib -import logging import pkgutil -from typing import Dict, Type +import warnings +from pathlib import Path +from typing import Dict, Iterable, Type from commitizen.cz.base import BaseCommitizen from commitizen.cz.conventional_commits import ConventionalCommitsCz from commitizen.cz.customize import CustomizeCommitsCz from commitizen.cz.jira import JiraSmartCz -logger = logging.getLogger(__name__) +def discover_plugins(path: Iterable[Path] = None) -> Dict[str, Type[BaseCommitizen]]: + """Discover commitizen plugins on the path -def discover_plugins(): + Args: + path (Path, optional): If provided, 'path' should be either None or a list of paths to look for + modules in. If path is None, all top-level modules on sys.path.. Defaults to None. + + Returns: + Dict[str, Type[BaseCommitizen]]: Registry with found plugins + """ plugins = {} - for finder, name, ispkg in pkgutil.iter_modules(): + for finder, name, ispkg in pkgutil.iter_modules(path): try: if name.startswith("cz_"): plugins[name] = importlib.import_module(name).discover_this except AttributeError as e: - logger.warning(e.args[0]) + warnings.warn(UserWarning(e.args[0])) continue return plugins diff --git a/tests/test_factory.py b/tests/test_factory.py index 5fbd2deebb..a78fe65a6e 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -1,7 +1,10 @@ +import sys + import pytest from commitizen import BaseCommitizen, defaults, factory from commitizen.config import BaseConfig +from commitizen.cz import discover_plugins from commitizen.exceptions import NoCommitizenFoundException @@ -19,3 +22,27 @@ def test_factory_fails(): factory.commiter_factory(config) assert "The committer has not been found in the system." in str(excinfo) + + +@pytest.mark.parametrize( + "module_content, plugin_name, expected_plugins", + [ + ("", "cz_no_plugin", {}), + ], +) +def test_discover_plugins(module_content, plugin_name, expected_plugins, tmp_path): + no_plugin_folder = tmp_path / plugin_name + no_plugin_folder.mkdir() + init_file = no_plugin_folder / "__init__.py" + init_file.write_text(module_content) + + sys.path.append(tmp_path.as_posix()) + with pytest.warns(UserWarning) as record: + discovered_plugins = discover_plugins([tmp_path]) + sys.path.pop() + + assert ( + record[0].message.args[0] + == f"module '{plugin_name}' has no attribute 'discover_this'" + ) + assert expected_plugins == discovered_plugins From 16b37ee4ae492a3c8d2752b2fb38a5ca9caa9e99 Mon Sep 17 00:00:00 2001 From: manolo Date: Sat, 29 Jan 2022 08:17:07 +0100 Subject: [PATCH 0064/1498] refactor: iter_modules only accepts str --- commitizen/cz/__init__.py | 3 +-- tests/test_factory.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index 1699649d3e..f141e1c256 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -1,7 +1,6 @@ import importlib import pkgutil import warnings -from pathlib import Path from typing import Dict, Iterable, Type from commitizen.cz.base import BaseCommitizen @@ -10,7 +9,7 @@ from commitizen.cz.jira import JiraSmartCz -def discover_plugins(path: Iterable[Path] = None) -> Dict[str, Type[BaseCommitizen]]: +def discover_plugins(path: Iterable[str] = None) -> Dict[str, Type[BaseCommitizen]]: """Discover commitizen plugins on the path Args: diff --git a/tests/test_factory.py b/tests/test_factory.py index a78fe65a6e..a8e56f51d6 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -38,7 +38,7 @@ def test_discover_plugins(module_content, plugin_name, expected_plugins, tmp_pat sys.path.append(tmp_path.as_posix()) with pytest.warns(UserWarning) as record: - discovered_plugins = discover_plugins([tmp_path]) + discovered_plugins = discover_plugins([tmp_path.as_posix()]) sys.path.pop() assert ( From e6f1dc379c7749c81057ee14affdaf4dd8d1206b Mon Sep 17 00:00:00 2001 From: manolo Date: Sun, 30 Jan 2022 14:41:56 +0100 Subject: [PATCH 0065/1498] build: Ignore type checking --- commitizen/cz/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index f141e1c256..05e54673fb 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -23,7 +23,7 @@ def discover_plugins(path: Iterable[str] = None) -> Dict[str, Type[BaseCommitize for finder, name, ispkg in pkgutil.iter_modules(path): try: if name.startswith("cz_"): - plugins[name] = importlib.import_module(name).discover_this + plugins[name] = importlib.import_module(name).discover_this # type: ignore except AttributeError as e: warnings.warn(UserWarning(e.args[0])) continue From 27b4c54772ca81d7d6fd776e4a57edfb0de30d9b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 7 Feb 2022 07:51:25 +0000 Subject: [PATCH 0066/1498] =?UTF-8?q?bump:=20version=202.20.4=20=E2=86=92?= =?UTF-8?q?=202.20.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 11 +++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fd4fd2647..990084edd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ +## v2.20.5 (2022-02-07) + +### Refactor + +- iter_modules only accepts str + +### Fix + +- Ignore packages that are not plugins +- Ignore packages that are not plugins + ## v2.20.4 (2022-01-17) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index b843b67a42..3498ba56bb 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.4" +__version__ = "2.20.5" diff --git a/pyproject.toml b/pyproject.toml index bf29b88b65..5f2e05b816 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.4" +version = "2.20.5" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.4" +version = "2.20.5" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From bc9be40cf304ba6935442a55a57cf7c8abbcd7c2 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Thu, 17 Feb 2022 04:13:35 +0100 Subject: [PATCH 0067/1498] feat: skip merge messages that start with Pull request Bitbucket add as default message when a pull request is merged, the message commit that starts with "Pull request". cz check fails with this kind of messages. Signed-off-by: Angelo Mantellini --- commitizen/commands/check.py | 6 +++++- commitizen/config/toml_config.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 3c06c97647..a32613e77f 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -100,6 +100,10 @@ def _filter_comments(self, msg: str) -> str: @staticmethod def validate_commit_message(commit_msg: str, pattern: str) -> bool: - if commit_msg.startswith("Merge") or commit_msg.startswith("Revert"): + if ( + commit_msg.startswith("Merge") + or commit_msg.startswith("Revert") + or commit_msg.startswith("Pull request") + ): return True return bool(re.match(pattern, commit_msg)) diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index c2a90cec9f..0d09c90796 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -49,7 +49,7 @@ def _parse_setting(self, data: Union[bytes, str]) -> None: name = "cz_conventional_commits" ``` """ - doc = parse(data) # type: ignore + doc = parse(data) try: self.settings.update(doc["tool"]["commitizen"]) # type: ignore except exceptions.NonExistentKey: From b3689c29f7e7847f53b3c3d33d41c641927f0b77 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Feb 2022 08:28:03 +0000 Subject: [PATCH 0068/1498] =?UTF-8?q?bump:=20version=202.20.5=20=E2=86=92?= =?UTF-8?q?=202.21.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 990084edd9..6f62c23dc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## v2.21.0 (2022-02-17) + +### Feat + +- skip merge messages that start with Pull request +- skip merge messages that start with Pull request + ## v2.20.5 (2022-02-07) ### Refactor diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 3498ba56bb..2a9dde58d7 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.20.5" +__version__ = "2.21.0" diff --git a/pyproject.toml b/pyproject.toml index 5f2e05b816..06962c03dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.20.5" +version = "2.21.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.20.5" +version = "2.21.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From ae326f633c7f27d6b8f88b2295f6b101492670f3 Mon Sep 17 00:00:00 2001 From: Edwin Yllanes Date: Mon, 21 Feb 2022 17:13:52 +0000 Subject: [PATCH 0069/1498] refactor: Switch to issue forms --- .github/ISSUE_TEMPLATE/bug_report.md | 44 --------------- .github/ISSUE_TEMPLATE/bug_report.yml | 63 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 6 +++ .github/ISSUE_TEMPLATE/documentation.md | 19 ------- .github/ISSUE_TEMPLATE/documentation.yml | 29 ++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 19 ------- .github/ISSUE_TEMPLATE/feature_request.yml | 31 +++++++++++ 7 files changed, 129 insertions(+), 82 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/documentation.md create mode 100644 .github/ISSUE_TEMPLATE/documentation.yml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 944a95723e..0000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -name: 🛠 Bug report -about: Create a report to help us improve -title: "Good bug title tells us about precise symptom, not about the root cause." -labels: "bug" -assignees: "" ---- - -## Description - - -## Steps to reproduce - - -## Current behavior - - -## Desired behavior - - -## Environment - -Add output of the following command to include the following -- commitizen version: -- python version: -- operating system: -```bash -cz version --report -``` diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000..aa36389abc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,63 @@ +name: 🛠 Bug report +description: Create a report to help us improve +title: Good bug title tells us about precise symptom, not about the root cause. +labels: [bug] +body: + - type: textarea + id: description + attributes: + label: Description + description: | + A clear and concise description of what the bug is + validations: + required: true + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to reproduce + description: Steps to reproduce the behavior + placeholder: | + 1. Run ... + 2. ... + 3. ... + validations: + required: true + - type: textarea + id: current-behavior + attributes: + label: Current behavior + description: What happens actually so you think this is a bug. + validations: + required: true + - type: textarea + id: desired-behavior + attributes: + label: Desired behavior + description: | + A clear and concise description of what you expected to happen. + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots + description: | + If applicable, add screenshots to help explain your problem. + validations: + required: true + - type: textarea + id: environment + attributes: + label: Environment + description: | + For older commitizen versions, please include the output of the following commands manually + placeholder: | + - commitizen version: `cz version` + - python version: `python --version` + - operating system: `python3 -c "import platform; print(platform.system())"` + + ```bash + cz version --report + ``` + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000..884fe1663a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,6 @@ +# Configuration: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository + +blank_issues_enabled: false +contact_links: + - name: Security Contact + about: Please report security vulnerabilities to santiwilly@gmail.com diff --git a/.github/ISSUE_TEMPLATE/documentation.md b/.github/ISSUE_TEMPLATE/documentation.md deleted file mode 100644 index f96cfff7bc..0000000000 --- a/.github/ISSUE_TEMPLATE/documentation.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: 📖 Documentation -about: Suggest an improvement for the documentation of this project -title: "Content to be added or fixed" -labels: "documentation" -assignees: "" ---- - -## Type - -* [ ] Content inaccurate -* [ ] Content missing -* [ ] Typo - -## URL - - -## Description - diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000000..7a74333053 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,29 @@ +name: 📖 Documentation +description: Suggest an improvement for the documentation of this project +title: Content to be added or fixed +labels: [documentation] +body: + - type: checkboxes + id: typo + attributes: + label: Type + options: + - label: Content inaccurate + - label: Content missing + - label: Typo + - type: input + id: url + attributes: + label: URL + placeholder: | + URL to the code we did not clearly describe or the document page where the content is inaccurate + validations: + required: true + - type: textarea + id: description + attributes: + label: Description + description: | + A clear and concise description of what content should be added or fixed + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index b9d48126a4..0000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: 🚀 Feature request -about: Suggest an idea for this project -title: "" -labels: "feature" -assignees: "" ---- - -## Description - - -## Possible Solution - - -## Additional context - - -## Related Issue - diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000000..7d67eb18af --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,31 @@ +name: 🚀 Feature request +description: Suggest an idea for this project +title: "" +labels: [feature] +body: + - type: textarea + id: description + attributes: + label: Description + description: | + A clear and concise description for us to know your idea. + validations: + required: true + - type: textarea + id: possible-solution + attributes: + label: Possible Solution + description: | + A clear and concise description of what you want to happen. + - type: textarea + id: additional-context + attributes: + label: Additional context + description: | + Add any other context or screenshots about the feature request here. + - type: textarea + id: related-issue + attributes: + label: Additional context + description: | + If applicable, add link to existing issue also help us know better. From bece93b759be9f8ce986206d60bf9941393e4a11 Mon Sep 17 00:00:00 2001 From: Edwin Yllanes Date: Mon, 21 Feb 2022 17:23:51 +0000 Subject: [PATCH 0070/1498] refactor: Switch to issue forms --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index aa36389abc..69031d736d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -43,8 +43,6 @@ body: label: Screenshots description: | If applicable, add screenshots to help explain your problem. - validations: - required: true - type: textarea id: environment attributes: From 49789df6d20489531db0c79f346e3eb0f853404c Mon Sep 17 00:00:00 2001 From: Edwin Yllanes Date: Mon, 21 Feb 2022 17:27:34 +0000 Subject: [PATCH 0071/1498] refactor: Switch to issue forms --- .github/ISSUE_TEMPLATE/documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml index 7a74333053..51d378b747 100644 --- a/.github/ISSUE_TEMPLATE/documentation.yml +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -4,7 +4,7 @@ title: Content to be added or fixed labels: [documentation] body: - type: checkboxes - id: typo + id: type attributes: label: Type options: From 33b53e64728c269a9c5750c2dc1eb9daa734b3ec Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 22 Feb 2022 13:53:50 +0000 Subject: [PATCH 0072/1498] =?UTF-8?q?bump:=20version=202.21.0=20=E2=86=92?= =?UTF-8?q?=202.21.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f62c23dc2..fab89fcff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +## v2.21.1 (2022-02-22) + +### Refactor + +- Switch to issue forms +- Switch to issue forms +- Switch to issue forms + ## v2.21.0 (2022-02-17) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 2a9dde58d7..e615ea2b7e 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.21.0" +__version__ = "2.21.1" diff --git a/pyproject.toml b/pyproject.toml index 06962c03dc..fb412786af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.21.0" +version = "2.21.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.21.0" +version = "2.21.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 031f7c753e1b929ac30097609c323f121e8dc87b Mon Sep 17 00:00:00 2001 From: Edwin Yllanes Date: Sun, 13 Feb 2022 22:12:22 +0000 Subject: [PATCH 0073/1498] docs(faq.md): close parentheses --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index eb1c98068b..959511ceab 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -30,7 +30,7 @@ version_files = [ ## Why are `revert` and `chore` valid types in the check pattern of cz conventional_commits but not types we can select? `revert` and `chore` are added to the "pattern" in `cz check` in order to prevent backward errors, but officially they are not part of conventional commits, we are using the latest [types from Angular](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type) (they used to but were removed). -However, you can create a customized `cz` with those extra types. (See [Customization](customization.md) +However, you can create a customized `cz` with those extra types. (See [Customization](customization.md)) See more discussion in issue [#142](https://github.com/commitizen-tools/commitizen/issues/142) and [#36](https://github.com/commitizen-tools/commitizen/issues/36) From cd5579043dfabcfd4baee274c56296fe58d7e110 Mon Sep 17 00:00:00 2001 From: Edwin Yllanes Date: Sun, 13 Feb 2022 22:22:15 +0000 Subject: [PATCH 0074/1498] fix: remove type ignore --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index 959511ceab..7c076f0a62 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -30,7 +30,7 @@ version_files = [ ## Why are `revert` and `chore` valid types in the check pattern of cz conventional_commits but not types we can select? `revert` and `chore` are added to the "pattern" in `cz check` in order to prevent backward errors, but officially they are not part of conventional commits, we are using the latest [types from Angular](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type) (they used to but were removed). -However, you can create a customized `cz` with those extra types. (See [Customization](customization.md)) +However, you can create a customized `cz` with those extra types. (See [Customization](customization.md)). See more discussion in issue [#142](https://github.com/commitizen-tools/commitizen/issues/142) and [#36](https://github.com/commitizen-tools/commitizen/issues/36) From 6efad39c93ca236faf67a8e2c81f676326b8a169 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 22 Feb 2022 13:58:08 +0000 Subject: [PATCH 0075/1498] =?UTF-8?q?bump:=20version=202.21.1=20=E2=86=92?= =?UTF-8?q?=202.21.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fab89fcff6..472d1e4e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.21.2 (2022-02-22) + +### Fix + +- remove type ignore + ## v2.21.1 (2022-02-22) ### Refactor diff --git a/commitizen/__version__.py b/commitizen/__version__.py index e615ea2b7e..6bd9995c3e 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.21.1" +__version__ = "2.21.2" diff --git a/pyproject.toml b/pyproject.toml index fb412786af..e02720ca5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.21.1" +version = "2.21.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.21.1" +version = "2.21.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From e94eae96f3b2d122da81de8b03efa581704bffad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Thu, 8 Jul 2021 21:11:44 +0200 Subject: [PATCH 0076/1498] feat(changelog): add support for single version and version range Closes #399 #225 --- commitizen/bump.py | 2 +- commitizen/changelog.py | 71 ++++- commitizen/cli.py | 6 + commitizen/commands/changelog.py | 63 +++- commitizen/cz/__init__.py | 2 +- commitizen/exceptions.py | 5 + pyproject.toml | 2 +- tests/commands/test_changelog_command.py | 291 +++++++++++++++++- ...angelog_from_rev_first_version_from_arg.md | 5 + ...angelog_from_rev_latest_version_dry_run.md | 7 + ...ngelog_from_rev_latest_version_from_arg.md | 6 + ...angelog_from_rev_version_range_from_arg.md | 12 + ...m_rev_version_range_including_first_tag.md | 12 + ...rom_rev_version_with_big_range_from_arg.md | 24 ++ tests/test_changelog.py | 15 + 15 files changed, 502 insertions(+), 21 deletions(-) create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_first_version_from_arg.md create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_dry_run.md create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_from_arg.md create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_version_range_from_arg.md create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_version_range_including_first_tag.md create mode 100644 tests/commands/test_changelog_command/test_changelog_from_rev_version_with_big_range_from_arg.md diff --git a/commitizen/bump.py b/commitizen/bump.py index 6c09e2f16d..d519c8e385 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -21,7 +21,7 @@ def find_increment( # Most important cases are major and minor. # Everything else will be considered patch. select_pattern = re.compile(regex) - increment = None + increment: Optional[str] = None for commit in commits: for message in commit.message.split("\n"): diff --git a/commitizen/changelog.py b/commitizen/changelog.py index d854219a28..273879b9ab 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -29,7 +29,7 @@ import re from collections import OrderedDict, defaultdict from datetime import date -from typing import Callable, Dict, Iterable, List, Optional +from typing import Callable, Dict, Iterable, List, Optional, Tuple from jinja2 import Environment, PackageLoader @@ -281,3 +281,72 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List: if not isinstance(latest_version_position, int): output_lines.append(new_content) return output_lines + + +def get_smart_tag_range( + tags: List[GitTag], start: str, end: Optional[str] = None +) -> List[GitTag]: + """Smart because it finds the N+1 tag. + + This is because we need to find until the next tag + """ + accumulator = [] + keep = False + if not end: + end = start + for index, tag in enumerate(tags): + if tag.name == start: + keep = True + if keep: + accumulator.append(tag) + if tag.name == end: + keep = False + try: + accumulator.append(tags[index + 1]) + except IndexError: + pass + break + return accumulator + + +def get_start_and_end_rev( + tags: List[GitTag], version: str, tag_format: str, create_tag: Callable +) -> Tuple[Optional[str], Optional[str]]: + """Find the tags for the given version. + + `version` may come in different formats: + - `0.1.0..0.4.0`: as a range + - `0.3.0`: as a single version + """ + start: Optional[str] = None + end: Optional[str] = None + + try: + start, end = version.split("..") + except ValueError: + end = version + + end_tag = create_tag(end, tag_format=tag_format) + + start_tag = None + if start: + start_tag = create_tag(start, tag_format=tag_format) + + tags_range = get_smart_tag_range(tags, start=end_tag, end=start_tag) + if len(tags_range) == 0: + return None, None + + start_rev: Optional[str] = tags_range[-1].name + end_rev = end_tag + + # check if it's the first tag created + # and it's also being requested as part of the range + if start_rev == tags[-1].name and start_rev == start_tag: + return None, end_rev + + # when they are the same, and it's also the + # first tag crated + if start_rev == end_rev: + return None, end_rev + + return start_rev, end_rev diff --git a/commitizen/cli.py b/commitizen/cli.py index d582a27a18..839e6cf5d7 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -188,6 +188,12 @@ "useful if the changelog has been manually modified" ), }, + { + "name": "rev_range", + "type": str, + "nargs": "?", + "help": "generates changelog for the given version (e.g: 1.5.3) or version range (e.g: 1.5.3..1.7.9)", + }, { "name": "--start-rev", "default": None, diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 535632dfc0..4cb0dd8211 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -3,7 +3,7 @@ from operator import itemgetter from typing import Callable, Dict, List, Optional -from commitizen import changelog, factory, git, out +from commitizen import bump, changelog, factory, git, out from commitizen.config import BaseConfig from commitizen.exceptions import ( DryRunExit, @@ -11,6 +11,7 @@ NoPatternMapError, NoRevisionError, NotAGitProjectError, + NotAllowed, ) from commitizen.git import GitTag @@ -46,6 +47,10 @@ def __init__(self, config: BaseConfig, args): self.change_type_order = ( self.config.settings.get("change_type_order") or self.cz.change_type_order ) + self.rev_range = args.get("rev_range") + self.tag_format = args.get("tag_format") or self.config.settings.get( + "tag_format" + ) def _find_incremental_rev(self, latest_version: str, tags: List[GitTag]) -> str: """Try to find the 'start_rev'. @@ -73,6 +78,30 @@ def _find_incremental_rev(self, latest_version: str, tags: List[GitTag]) -> str: start_rev = tag.name return start_rev + def write_changelog( + self, changelog_out: str, lines: List[str], changelog_meta: Dict + ): + if not isinstance(self.file_name, str): + raise NotAllowed( + "Changelog file name is broken.\n" + "Check the flag `--file-name` in the terminal " + f"or the setting `changelog_file` in {self.config.path}" + ) + + changelog_hook: Optional[Callable] = self.cz.changelog_hook + with open(self.file_name, "w") as changelog_file: + partial_changelog: Optional[str] = None + if self.incremental: + new_lines = changelog.incremental_build( + changelog_out, lines, changelog_meta + ) + changelog_out = "".join(new_lines) + partial_changelog = changelog_out + + if changelog_hook: + changelog_out = changelog_hook(changelog_out, partial_changelog) + changelog_file.write(changelog_out) + def __call__(self): commit_parser = self.cz.commit_parser changelog_pattern = self.cz.changelog_pattern @@ -83,23 +112,38 @@ def __call__(self): changelog_message_builder_hook: Optional[ Callable ] = self.cz.changelog_message_builder_hook - changelog_hook: Optional[Callable] = self.cz.changelog_hook + if not changelog_pattern or not commit_parser: raise NoPatternMapError( f"'{self.config.settings['name']}' rule does not support changelog" ) + if self.incremental and self.rev_range: + raise NotAllowed("--incremental cannot be combined with a rev_range") + tags = git.get_tags() if not tags: tags = [] + end_rev = "HEAD" + if self.incremental: changelog_meta = changelog.get_metadata(self.file_name) latest_version = changelog_meta.get("latest_version") if latest_version: start_rev = self._find_incremental_rev(latest_version, tags) - commits = git.get_commits(start=start_rev, args="--author-date-order") + if self.rev_range and self.tag_format: + start_rev, end_rev = changelog.get_start_and_end_rev( + tags, + version=self.rev_range, + tag_format=self.tag_format, + create_tag=bump.create_tag, + ) + + commits = git.get_commits( + start=start_rev, end=end_rev, args="--author-date-order" + ) if not commits: raise NoCommitsFoundError("No commits found") @@ -126,15 +170,4 @@ def __call__(self): with open(self.file_name, "r") as changelog_file: lines = changelog_file.readlines() - with open(self.file_name, "w") as changelog_file: - partial_changelog: Optional[str] = None - if self.incremental: - new_lines = changelog.incremental_build( - changelog_out, lines, changelog_meta - ) - changelog_out = "".join(new_lines) - partial_changelog = changelog_out - - if changelog_hook: - changelog_out = changelog_hook(changelog_out, partial_changelog) - changelog_file.write(changelog_out) + self.write_changelog(changelog_out, lines, changelog_meta) diff --git a/commitizen/cz/__init__.py b/commitizen/cz/__init__.py index 05e54673fb..f141e1c256 100644 --- a/commitizen/cz/__init__.py +++ b/commitizen/cz/__init__.py @@ -23,7 +23,7 @@ def discover_plugins(path: Iterable[str] = None) -> Dict[str, Type[BaseCommitize for finder, name, ispkg in pkgutil.iter_modules(path): try: if name.startswith("cz_"): - plugins[name] = importlib.import_module(name).discover_this # type: ignore + plugins[name] = importlib.import_module(name).discover_this except AttributeError as e: warnings.warn(UserWarning(e.args[0])) continue diff --git a/commitizen/exceptions.py b/commitizen/exceptions.py index 218534c730..9ae97ee1b0 100644 --- a/commitizen/exceptions.py +++ b/commitizen/exceptions.py @@ -24,6 +24,7 @@ class ExitCode(enum.IntEnum): CURRENT_VERSION_NOT_FOUND = 17 INVALID_COMMAND_ARGUMENT = 18 INVALID_CONFIGURATION = 19 + NOT_ALLOWED = 20 class CommitizenException(Exception): @@ -142,3 +143,7 @@ class InvalidCommandArgumentError(CommitizenException): class InvalidConfigurationError(CommitizenException): exit_code = ExitCode.INVALID_CONFIGURATION + + +class NotAllowed(CommitizenException): + exit_code = ExitCode.NOT_ALLOWED diff --git a/pyproject.toml b/pyproject.toml index e02720ca5a..cb1a206d9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ isort = "^5.7.0" # linter flake8 = "^3.6" pre-commit = "^2.6.0" -mypy = "0.910" +mypy = "^0.931" types-PyYAML = "^5.4.3" types-termcolor = "^0.1.1" # documentation diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 02e0e74644..acbb361279 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -10,6 +10,7 @@ NoCommitsFoundError, NoRevisionError, NotAGitProjectError, + NotAllowed, ) from tests.utils import create_file_and_commit @@ -279,7 +280,7 @@ def test_changelog_multiple_incremental_do_not_add_new_lines( mocker.patch.object(sys, "argv", testargs) cli.main() - create_file_and_commit("fix: mama gotta work") + create_file_and_commit("fix: no more explosions") testargs = ["cz", "changelog", "--incremental"] mocker.patch.object(sys, "argv", testargs) @@ -486,7 +487,7 @@ def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2021-06-11") def test_changelog_incremental_with_release_candidate_version( - mocker, capsys, changelog_path, file_regression, test_input + mocker, changelog_path, file_regression, test_input ): """Fix #357""" with open(changelog_path, "w") as f: @@ -514,3 +515,289 @@ def test_changelog_incremental_with_release_candidate_version( out = f.read() file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_path): + + with open(config_path, "a") as f: + f.write("changelog_file = true\n") + + create_file_and_commit("feat: add new output") + + testargs = ["cz", "changelog"] + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(NotAllowed): + cli.main() + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_first_version_from_arg( + mocker, config_path, changelog_path, file_regression +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.2.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_latest_version_from_arg( + mocker, config_path, changelog_path, file_regression +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.3.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_single_version_not_found( + mocker, config_path, changelog_path +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.8.0"] # it shouldn't exist + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(NoCommitsFoundError) as excinfo: + cli.main() + + assert "No commits found" in str(excinfo) + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_range_version_not_found(mocker, config_path): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.5.0..0.8.0"] # it shouldn't exist + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(NoCommitsFoundError) as excinfo: + cli.main() + + assert "No commits found" in str(excinfo) + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_version_range_including_first_tag( + mocker, config_path, changelog_path, file_regression +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.2.0..0.3.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + with open(changelog_path, "r") as f: + out = f.read() + + print(out) + file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_version_range_from_arg( + mocker, config_path, changelog_path, file_regression +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: getting ready for this") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.3.0..0.4.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_version_with_big_range_from_arg( + mocker, config_path, changelog_path, file_regression +): + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] # 0.3.0 + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: getting ready for this") + + testargs = ["cz", "bump", "--yes"] # 0.4.0 + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("fix: small error") + + testargs = ["cz", "bump", "--yes"] # 0.4.1 + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: new shinny feature") + + testargs = ["cz", "bump", "--yes"] # 0.5.0 + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: amazing different shinny feature") + + testargs = ["cz", "bump", "--yes"] # 0.6.0 + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "changelog", "0.3.0..0.5.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_latest_version_dry_run( + mocker, capsys, config_path, changelog_path, file_regression +): + + with open(config_path, "a") as f: + f.write('tag_format = "$version"\n') + + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + capsys.readouterr() + + testargs = ["cz", "changelog", "0.3.0", "--dry-run"] + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(DryRunExit): + cli.main() + + out, _ = capsys.readouterr() + + file_regression.check(out, extension=".md") diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_first_version_from_arg.md b/tests/commands/test_changelog_command/test_changelog_from_rev_first_version_from_arg.md new file mode 100644 index 0000000000..3519498ac2 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_first_version_from_arg.md @@ -0,0 +1,5 @@ +## 0.2.0 (2022-02-13) + +### Feat + +- new file diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_dry_run.md b/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_dry_run.md new file mode 100644 index 0000000000..e6531e6b3c --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_dry_run.md @@ -0,0 +1,7 @@ +## 0.3.0 (2022-02-13) + +### Feat + +- another feature +- after 0.2.0 + diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_from_arg.md b/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_from_arg.md new file mode 100644 index 0000000000..91880643eb --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_latest_version_from_arg.md @@ -0,0 +1,6 @@ +## 0.3.0 (2022-02-13) + +### Feat + +- another feature +- after 0.2.0 diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_from_arg.md b/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_from_arg.md new file mode 100644 index 0000000000..0c483c740a --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_from_arg.md @@ -0,0 +1,12 @@ +## 0.4.0 (2022-02-13) + +### Feat + +- getting ready for this + +## 0.3.0 (2022-02-13) + +### Feat + +- another feature +- after 0.2.0 diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_including_first_tag.md b/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_including_first_tag.md new file mode 100644 index 0000000000..44bffb319d --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_version_range_including_first_tag.md @@ -0,0 +1,12 @@ +## 0.3.0 (2022-02-13) + +### Feat + +- another feature +- after 0.2.0 + +## 0.2.0 (2022-02-13) + +### Feat + +- new file diff --git a/tests/commands/test_changelog_command/test_changelog_from_rev_version_with_big_range_from_arg.md b/tests/commands/test_changelog_command/test_changelog_from_rev_version_with_big_range_from_arg.md new file mode 100644 index 0000000000..376424db3e --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_from_rev_version_with_big_range_from_arg.md @@ -0,0 +1,24 @@ +## 0.5.0 (2022-02-13) + +### Feat + +- new shinny feature + +## 0.4.1 (2022-02-13) + +### Fix + +- small error + +## 0.4.0 (2022-02-13) + +### Feat + +- getting ready for this + +## 0.3.0 (2022-02-13) + +### Feat + +- another feature +- after 0.2.0 diff --git a/tests/test_changelog.py b/tests/test_changelog.py index b3071ed5fc..e68a3abdcf 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -912,3 +912,18 @@ def changelog_message_builder_hook(message: dict, commit: git.GitCommit) -> dict result = changelog.render_changelog(tree) assert "[link](github.com/232323232) Commitizen author@cz.dev" in result + + +def test_get_smart_tag_range_returns_an_extra_for_a_range(tags): + start, end = ( + tags[0], + tags[2], + ) # len here is 3, but we expect one more tag as designed + res = changelog.get_smart_tag_range(tags, start.name, end.name) + assert 4 == len(res) + + +def test_get_smart_tag_range_returns_an_extra_for_a_single_tag(tags): + start = tags[0] # len here is 1, but we expect one more tag as designed + res = changelog.get_smart_tag_range(tags, start.name) + assert 2 == len(res) From d54209df0b06b461bef71a904f9bc4c34b3cf99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Sun, 13 Feb 2022 15:04:03 +0100 Subject: [PATCH 0077/1498] docs: add changelog rev_range and update bump and config --- docs/changelog.md | 35 ++++++++++++++++++++++++----------- docs/config.md | 27 ++++++++++++++++----------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index f5dd5fd5e3..6f92bb21cd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,9 +6,11 @@ This command will generate a changelog following the committing rules establishe ```bash $ cz changelog --help -usage: cz changelog [-h] [--dry-run] [--file-name FILE_NAME] - [--unreleased-version UNRELEASED_VERSION] [--incremental] - [--start-rev START_REV] +usage: cz changelog [-h] [--dry-run] [--file-name FILE_NAME] [--unreleased-version UNRELEASED_VERSION] [--incremental] [--start-rev START_REV] + [rev_range] + +positional arguments: + rev_range generates changelog for the given version (e.g: 1.5.3) or version range (e.g: 1.5.3..1.7.9) optional arguments: -h, --help show this help message and exit @@ -16,17 +18,16 @@ optional arguments: --file-name FILE_NAME file name of changelog (default: 'CHANGELOG.md') --unreleased-version UNRELEASED_VERSION - set the value for the new version (use the tag value), - instead of using unreleased - --incremental generates changelog from last created version, useful - if the changelog has been manually modified + set the value for the new version (use the tag value), instead of using unreleased + --incremental generates changelog from last created version, useful if the changelog has been manually modified --start-rev START_REV - start rev of the changelog.If not set, it will - generate changelog from the start + start rev of the changelog.If not set, it will generate changelog from the start ``` ### Examples +#### Generate full changelog + ```bash cz changelog ``` @@ -35,6 +36,18 @@ cz changelog cz ch ``` +#### Get the changelog for the given version + +```bash +cz changelog 0.3.0 +``` + +#### Get the changelog for the given version range + +```bash +cz changelog 0.3.0..0.4.0 +``` + ## Constrains changelog generation is constrained only to **markdown** files. @@ -66,7 +79,7 @@ and the following variables are expected: | `change_type` | The group where the commit belongs to, this is optional. Example: fix | `commit regex` | | `message`\* | Information extracted from the commit message | `commit regex` | | `scope` | Contextual information. Should be parsed using the regex from the message, it will be **bold** | `commit regex` | -| `breaking` | Whether is a breaking change or not | `commit regex` | +| `breaking` | Whether is a breaking change or not | `commit regex` | - **required**: is the only one required to be parsed by the regex @@ -74,7 +87,7 @@ and the following variables are expected: ### `unreleased_version` -There is usually an egg and chicken situation when automatically +There is usually a chicken and egg situation when automatically bumping the version and creating the changelog. If you bump the version first, you have no changelog, you have to create it later, and it won't be included in diff --git a/docs/config.md b/docs/config.md index cc278e3865..a7bb5d217d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -122,17 +122,21 @@ commitizen: ## Settings -| Variable | Type | Default | Description | -| ---------------- | ------ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | -| `version` | `str` | `None` | Current version. Example: "0.1.2" | -| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | -| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | -| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | -| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | -| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] | -| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] | -| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] | +| Variable | Type | Default | Description | +| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | +| `version` | `str` | `None` | Current version. Example: "0.1.2" | +| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | +| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | +| `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | +| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | +| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | +| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | +| `changelog_incremental` | `bool` | `false` | Update changelog with the missing versions. This is good if you don't want to replace previous versions in the file. Note: when doing `cz bump --changelog` this is automatically set to `true` | +| `changelog_start_rev` | `str` | `None` | Start from a given git rev to generate the changelog | +| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] | +| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] | +| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] | [version_files]: bump.md#version_files [tag_format]: bump.md#tag_format @@ -140,3 +144,4 @@ commitizen: [additional-features]: https://github.com/tmbo/questionary#additional-features [customization]: customization.md [shortcuts]: customization.md#shortcut-keys +[annotated-tags-vs-lightweight]: https://stackoverflow.com/a/11514139/2047185 From c5e65ccd006892990bea9c23cc3bf193c9b77523 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 25 Feb 2022 12:47:06 +0100 Subject: [PATCH 0078/1498] refactor(git): use date as a function in GitTag to easily patch --- commitizen/changelog.py | 1 - commitizen/git.py | 6 +++- tests/commands/test_changelog_command.py | 38 +++++++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/commitizen/changelog.py b/commitizen/changelog.py index 273879b9ab..e2504b35db 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -320,7 +320,6 @@ def get_start_and_end_rev( """ start: Optional[str] = None end: Optional[str] = None - try: start, end = version.split("..") except ValueError: diff --git a/commitizen/git.py b/commitizen/git.py index 4e60b68793..53d93cebc5 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -39,11 +39,15 @@ class GitTag(GitObject): def __init__(self, name, rev, date): self.rev = rev.strip() self.name = name.strip() - self.date = date.strip() + self._date = date.strip() def __repr__(self): return f"GitTag('{self.name}', '{self.rev}', '{self.date}')" + @property + def date(self): + return self._date + @classmethod def from_line(cls, line: str, inner_delimiter: str) -> "GitTag": diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index acbb361279..e9826ca149 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -1,5 +1,8 @@ import sys +import time + from datetime import date +from unittest import mock import pytest @@ -533,6 +536,7 @@ def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_ @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_first_version_from_arg( mocker, config_path, changelog_path, file_regression ): @@ -541,17 +545,18 @@ def test_changelog_from_rev_first_version_from_arg( # create commit and tag create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) testargs = ["cz", "changelog", "0.2.0"] mocker.patch.object(sys, "argv", testargs) cli.main() @@ -564,6 +569,7 @@ def test_changelog_from_rev_first_version_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_latest_version_from_arg( mocker, config_path, changelog_path, file_regression ): @@ -575,14 +581,14 @@ def test_changelog_from_rev_latest_version_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) testargs = ["cz", "changelog", "0.3.0"] mocker.patch.object(sys, "argv", testargs) cli.main() @@ -651,6 +657,7 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path): @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_range_including_first_tag( mocker, config_path, changelog_path, file_regression ): @@ -682,6 +689,7 @@ def test_changelog_from_rev_version_range_including_first_tag( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_range_from_arg( mocker, config_path, changelog_path, file_regression ): @@ -693,19 +701,21 @@ def test_changelog_from_rev_version_range_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() + time.sleep(0.5) create_file_and_commit("feat: getting ready for this") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() + time.sleep(0.5) testargs = ["cz", "changelog", "0.3.0..0.4.0"] mocker.patch.object(sys, "argv", testargs) @@ -718,6 +728,7 @@ def test_changelog_from_rev_version_range_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_with_big_range_from_arg( mocker, config_path, changelog_path, file_regression ): @@ -726,9 +737,11 @@ def test_changelog_from_rev_version_with_big_range_from_arg( # create commit and tag create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() + time.sleep(0.5) create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") @@ -736,30 +749,32 @@ def test_changelog_from_rev_version_with_big_range_from_arg( testargs = ["cz", "bump", "--yes"] # 0.3.0 mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: getting ready for this") testargs = ["cz", "bump", "--yes"] # 0.4.0 mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("fix: small error") testargs = ["cz", "bump", "--yes"] # 0.4.1 mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: new shinny feature") testargs = ["cz", "bump", "--yes"] # 0.5.0 mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: amazing different shinny feature") + # dirty hack to avoid same time between tags testargs = ["cz", "bump", "--yes"] # 0.6.0 mocker.patch.object(sys, "argv", testargs) cli.main() + time.sleep(0.5) testargs = ["cz", "changelog", "0.3.0..0.5.0"] mocker.patch.object(sys, "argv", testargs) @@ -772,6 +787,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") +@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_latest_version_dry_run( mocker, capsys, config_path, changelog_path, file_regression ): @@ -784,7 +800,7 @@ def test_changelog_from_rev_latest_version_dry_run( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - + time.sleep(0.5) create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") @@ -792,7 +808,7 @@ def test_changelog_from_rev_latest_version_dry_run( mocker.patch.object(sys, "argv", testargs) cli.main() capsys.readouterr() - + time.sleep(0.5) testargs = ["cz", "changelog", "0.3.0", "--dry-run"] mocker.patch.object(sys, "argv", testargs) with pytest.raises(DryRunExit): From 0497d62ef9460e5961d90d7ba35fbb4e90b8e345 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Mon, 28 Feb 2022 13:14:04 +0100 Subject: [PATCH 0079/1498] refactor: speed up testing and wait for tags --- commitizen/bump.py | 4 +- commitizen/changelog.py | 51 +++++++-------- commitizen/commands/bump.py | 4 +- commitizen/commands/changelog.py | 7 +-- commitizen/git.py | 6 +- pyproject.toml | 1 + scripts/test | 2 +- tests/commands/test_changelog_command.py | 63 +++++++++++-------- ...eate_tag.py => test_bump_normalize_tag.py} | 2 +- tests/test_changelog_parser.py | 14 +++-- tests/utils.py | 15 +++++ 11 files changed, 99 insertions(+), 70 deletions(-) rename tests/{test_bump_create_tag.py => test_bump_normalize_tag.py} (93%) diff --git a/commitizen/bump.py b/commitizen/bump.py index d519c8e385..2b5d77a9f2 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -196,7 +196,9 @@ def _version_to_regex(version: str): return re.compile(f"{clean_regex}") -def create_tag(version: Union[Version, str], tag_format: Optional[str] = None) -> str: +def normalize_tag( + version: Union[Version, str], tag_format: Optional[str] = None +) -> str: """The tag and the software version might be different. That's why this function exists. diff --git a/commitizen/changelog.py b/commitizen/changelog.py index e2504b35db..0738c2e281 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -34,6 +34,7 @@ from jinja2 import Environment, PackageLoader from commitizen import defaults +from commitizen.bump import normalize_tag from commitizen.exceptions import InvalidConfigurationError from commitizen.git import GitCommit, GitTag @@ -284,7 +285,7 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List: def get_smart_tag_range( - tags: List[GitTag], start: str, end: Optional[str] = None + tags: List[GitTag], newest: str, oldest: Optional[str] = None ) -> List[GitTag]: """Smart because it finds the N+1 tag. @@ -292,14 +293,14 @@ def get_smart_tag_range( """ accumulator = [] keep = False - if not end: - end = start + if not oldest: + oldest = newest for index, tag in enumerate(tags): - if tag.name == start: + if tag.name == newest: keep = True if keep: accumulator.append(tag) - if tag.name == end: + if tag.name == oldest: keep = False try: accumulator.append(tags[index + 1]) @@ -309,8 +310,8 @@ def get_smart_tag_range( return accumulator -def get_start_and_end_rev( - tags: List[GitTag], version: str, tag_format: str, create_tag: Callable +def get_oldest_and_newest_rev( + tags: List[GitTag], version: str, tag_format: str ) -> Tuple[Optional[str], Optional[str]]: """Find the tags for the given version. @@ -318,34 +319,34 @@ def get_start_and_end_rev( - `0.1.0..0.4.0`: as a range - `0.3.0`: as a single version """ - start: Optional[str] = None - end: Optional[str] = None + oldest: Optional[str] = None + newest: Optional[str] = None try: - start, end = version.split("..") + oldest, newest = version.split("..") except ValueError: - end = version + newest = version - end_tag = create_tag(end, tag_format=tag_format) + newest_tag = normalize_tag(newest, tag_format=tag_format) - start_tag = None - if start: - start_tag = create_tag(start, tag_format=tag_format) + oldest_tag = None + if oldest: + oldest_tag = normalize_tag(oldest, tag_format=tag_format) - tags_range = get_smart_tag_range(tags, start=end_tag, end=start_tag) - if len(tags_range) == 0: + tags_range = get_smart_tag_range(tags, newest=newest_tag, oldest=oldest_tag) + if not tags_range: return None, None - start_rev: Optional[str] = tags_range[-1].name - end_rev = end_tag + oldest_rev: Optional[str] = tags_range[-1].name + newest_rev = newest_tag # check if it's the first tag created # and it's also being requested as part of the range - if start_rev == tags[-1].name and start_rev == start_tag: - return None, end_rev + if oldest_rev == tags[-1].name and oldest_rev == oldest_tag: + return None, newest_rev # when they are the same, and it's also the - # first tag crated - if start_rev == end_rev: - return None, end_rev + # first tag created + if oldest_rev == newest_rev: + return None, newest_rev - return start_rev, end_rev + return oldest_rev, newest_rev diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 70dcad263f..cd05e8a8f3 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -101,7 +101,7 @@ def __call__(self): # noqa: C901 is_files_only: Optional[bool] = self.arguments["files_only"] is_local_version: Optional[bool] = self.arguments["local_version"] - current_tag_version: str = bump.create_tag( + current_tag_version: str = bump.normalize_tag( current_version, tag_format=tag_format ) @@ -149,7 +149,7 @@ def __call__(self): # noqa: C901 is_local_version=is_local_version, ) - new_tag_version = bump.create_tag(new_version, tag_format=tag_format) + new_tag_version = bump.normalize_tag(new_version, tag_format=tag_format) message = bump.create_commit_message( current_version, new_version, bump_commit_message ) diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 4cb0dd8211..58c0ceaeef 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -3,7 +3,7 @@ from operator import itemgetter from typing import Callable, Dict, List, Optional -from commitizen import bump, changelog, factory, git, out +from commitizen import changelog, factory, git, out from commitizen.config import BaseConfig from commitizen.exceptions import ( DryRunExit, @@ -125,7 +125,7 @@ def __call__(self): if not tags: tags = [] - end_rev = "HEAD" + end_rev = "" if self.incremental: changelog_meta = changelog.get_metadata(self.file_name) @@ -134,11 +134,10 @@ def __call__(self): start_rev = self._find_incremental_rev(latest_version, tags) if self.rev_range and self.tag_format: - start_rev, end_rev = changelog.get_start_and_end_rev( + start_rev, end_rev = changelog.get_oldest_and_newest_rev( tags, version=self.rev_range, tag_format=self.tag_format, - create_tag=bump.create_tag, ) commits = git.get_commits( diff --git a/commitizen/git.py b/commitizen/git.py index 53d93cebc5..98ee40f2f2 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -86,10 +86,10 @@ def get_commits( ) if start: - c = cmd.run(f"{git_log_cmd} {start}..{end}") + command = f"{git_log_cmd} {start}..{end}" else: - c = cmd.run(f"{git_log_cmd} {end}") - + command = f"{git_log_cmd} {end}" + c = cmd.run(command) if not c.out: return [] diff --git a/pyproject.toml b/pyproject.toml index cb1a206d9f..3c4acaa332 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,6 +79,7 @@ types-termcolor = "^0.1.1" mkdocs = "^1.0" mkdocs-material = "^4.1" pydocstyle = "^5.0.2" +pytest-xdist = "^2.5.0" [tool.poetry.scripts] cz = "commitizen.cli:main" diff --git a/scripts/test b/scripts/test index 08c54035dc..b5541d2d3e 100755 --- a/scripts/test +++ b/scripts/test @@ -5,7 +5,7 @@ if [ -d 'venv' ] ; then export PREFIX="venv/bin/" fi -${PREFIX}pytest --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ +${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ ${PREFIX}black commitizen tests --check ${PREFIX}isort --check-only commitizen tests ${PREFIX}flake8 commitizen/ tests/ diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index e9826ca149..223c7bf1f1 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -1,8 +1,5 @@ import sys -import time - from datetime import date -from unittest import mock import pytest @@ -15,7 +12,7 @@ NotAGitProjectError, NotAllowed, ) -from tests.utils import create_file_and_commit +from tests.utils import create_file_and_commit, wait_for_tag @pytest.mark.usefixtures("tmp_commitizen_project") @@ -536,10 +533,11 @@ def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_ @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_first_version_from_arg( mocker, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") + with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -549,18 +547,18 @@ def test_changelog_from_rev_first_version_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() + create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + testargs = ["cz", "changelog", "0.2.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: out = f.read() @@ -569,10 +567,11 @@ def test_changelog_from_rev_first_version_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_latest_version_from_arg( mocker, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") + with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -581,14 +580,17 @@ def test_changelog_from_rev_latest_version_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() + create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + + wait_for_tag() + testargs = ["cz", "changelog", "0.3.0"] mocker.patch.object(sys, "argv", testargs) cli.main() @@ -613,12 +615,15 @@ def test_changelog_from_rev_single_version_not_found( mocker.patch.object(sys, "argv", testargs) cli.main() + wait_for_tag() + create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() + wait_for_tag() testargs = ["cz", "changelog", "0.8.0"] # it shouldn't exist mocker.patch.object(sys, "argv", testargs) @@ -657,10 +662,11 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path): @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_range_including_first_tag( mocker, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") + with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -683,16 +689,16 @@ def test_changelog_from_rev_version_range_including_first_tag( with open(changelog_path, "r") as f: out = f.read() - print(out) file_regression.check(out, extension=".md") @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_range_from_arg( mocker, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") + with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -701,21 +707,21 @@ def test_changelog_from_rev_version_range_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: getting ready for this") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() testargs = ["cz", "changelog", "0.3.0..0.4.0"] mocker.patch.object(sys, "argv", testargs) @@ -728,10 +734,11 @@ def test_changelog_from_rev_version_range_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_version_with_big_range_from_arg( mocker, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") + with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -741,7 +748,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") @@ -749,32 +756,32 @@ def test_changelog_from_rev_version_with_big_range_from_arg( testargs = ["cz", "bump", "--yes"] # 0.3.0 mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: getting ready for this") testargs = ["cz", "bump", "--yes"] # 0.4.0 mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("fix: small error") testargs = ["cz", "bump", "--yes"] # 0.4.1 mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: new shinny feature") testargs = ["cz", "bump", "--yes"] # 0.5.0 mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() create_file_and_commit("feat: amazing different shinny feature") # dirty hack to avoid same time between tags testargs = ["cz", "bump", "--yes"] # 0.6.0 mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() testargs = ["cz", "changelog", "0.3.0..0.5.0"] mocker.patch.object(sys, "argv", testargs) @@ -787,10 +794,10 @@ def test_changelog_from_rev_version_with_big_range_from_arg( @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") -@mock.patch("commitizen.git.GitTag.date", "2022-02-13") def test_changelog_from_rev_latest_version_dry_run( mocker, capsys, config_path, changelog_path, file_regression ): + mocker.patch("commitizen.git.GitTag.date", "2022-02-13") with open(config_path, "a") as f: f.write('tag_format = "$version"\n') @@ -800,7 +807,8 @@ def test_changelog_from_rev_latest_version_dry_run( testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() - time.sleep(0.5) + wait_for_tag() + create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: another feature") @@ -808,7 +816,8 @@ def test_changelog_from_rev_latest_version_dry_run( mocker.patch.object(sys, "argv", testargs) cli.main() capsys.readouterr() - time.sleep(0.5) + wait_for_tag() + testargs = ["cz", "changelog", "0.3.0", "--dry-run"] mocker.patch.object(sys, "argv", testargs) with pytest.raises(DryRunExit): diff --git a/tests/test_bump_create_tag.py b/tests/test_bump_normalize_tag.py similarity index 93% rename from tests/test_bump_create_tag.py rename to tests/test_bump_normalize_tag.py index 0d6ee60d69..3bc9828a2f 100644 --- a/tests/test_bump_create_tag.py +++ b/tests/test_bump_normalize_tag.py @@ -19,5 +19,5 @@ @pytest.mark.parametrize("test_input,expected", conversion) def test_create_tag(test_input, expected): version, format = test_input - new_tag = bump.create_tag(Version(version), format) + new_tag = bump.normalize_tag(Version(version), format) assert new_tag == expected diff --git a/tests/test_changelog_parser.py b/tests/test_changelog_parser.py index ae6df53912..540f62fd19 100644 --- a/tests/test_changelog_parser.py +++ b/tests/test_changelog_parser.py @@ -33,15 +33,17 @@ def changelog_content() -> str: @pytest.fixture -def existing_changelog_file(): - changelog_path = "tests/CHANGELOG.md" +def existing_changelog_file(tmpdir): + with tmpdir.as_cwd(): + changelog_path = os.path.join(os.getcwd(), "CHANGELOG.md") + # changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: - f.write(CHANGELOG_TEMPLATE) + with open(changelog_path, "w") as f: + f.write(CHANGELOG_TEMPLATE) - yield changelog_path + yield changelog_path - os.remove(changelog_path) + os.remove(changelog_path) def test_read_changelog_blocks(existing_changelog_file): diff --git a/tests/utils.py b/tests/utils.py index 7f5b2b87f3..a1583490b6 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,4 @@ +import time import uuid from pathlib import Path from typing import Optional @@ -19,3 +20,17 @@ def create_file_and_commit(message: str, filename: Optional[str] = None): Path(f"./{filename}").touch() cmd.run("git add .") git.commit(message) + + +def wait_for_tag(): + """Wait for tag. + + The resolution of timestamps is 1 second, so we need to wait + to create another tag unfortunately. + + This means: + If we create 2 tags under the same second, they might be returned in the wrong order + + See https://stackoverflow.com/questions/28237043/what-is-the-resolution-of-gits-commit-date-or-author-date-timestamps + """ + time.sleep(1.1) From f924fe6f1445aa9f2fa2a1d107a025109866dc4a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Mar 2022 01:48:06 +0000 Subject: [PATCH 0080/1498] =?UTF-8?q?bump:=20version=202.21.2=20=E2=86=92?= =?UTF-8?q?=202.22.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 11 +++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472d1e4e4b..6b00f3d044 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ +## v2.22.0 (2022-03-29) + +### Refactor + +- speed up testing and wait for tags +- **git**: use date as a function in GitTag to easily patch + +### Feat + +- **changelog**: add support for single version and version range + ## v2.21.2 (2022-02-22) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 6bd9995c3e..0ca0596150 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.21.2" +__version__ = "2.22.0" diff --git a/pyproject.toml b/pyproject.toml index 3c4acaa332..3e52f7455f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.21.2" +version = "2.22.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.21.2" +version = "2.22.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 807b18619be39ddd93325a2129888c41bbd6fadd Mon Sep 17 00:00:00 2001 From: matteo_fiore Date: Tue, 5 Oct 2021 16:08:45 +0200 Subject: [PATCH 0081/1498] feat(customize.py): adding support for commit_parser, changelog_pattern, change_type_map --- commitizen/cz/customize/customize.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 7a6f03a825..994c21c714 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -38,6 +38,18 @@ def __init__(self, config: BaseConfig): if custom_change_type_order: self.change_type_order = custom_change_type_order + commit_parser = self.custom_settings.get("commit_parser") + if commit_parser: + self.commit_parser = commit_parser + + changelog_pattern = self.custom_settings.get("changelog_pattern") + if changelog_pattern: + self.changelog_pattern = changelog_pattern + + change_type_map = self.custom_settings.get("change_type_map") + if change_type_map: + self.change_type_map = change_type_map + def questions(self) -> Questions: return self.custom_settings.get("questions", [{}]) From 9906eacc613aac8398906f5c0e4cf576140918f3 Mon Sep 17 00:00:00 2001 From: matteo_fiore Date: Tue, 5 Oct 2021 16:11:23 +0200 Subject: [PATCH 0082/1498] test(test_cz_customize): adding tests for commit_parser, changelog_pattern, change_type_map --- tests/test_cz_customize.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index e919093e04..84e463cf96 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -10,6 +10,9 @@ example = "feature: this feature enable customize through config file" schema = ": " schema_pattern = "(feature|bug fix):(\\s.*)" + commit_parser = "^(?Pfeature|bug fix):\\s(?P.*)?" + changelog_pattern = "^(feature|bug fix)?(!)?" + change_type_map = {"feature" = "Feat", "bug fix" = "Fix"} bump_pattern = "^(break|new|fix|hotfix)" bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} @@ -57,6 +60,9 @@ "fix": "PATCH", "hotfix": "PATCH" }, + "commit_parser": "^(?Pfeature|bug fix):\\s(?P.*)?", + "changelog_pattern": "^(feature|bug fix)?(!)?", + "change_type_map": {"feature": "Feat", "bug fix": "Fix"}, "change_type_order": ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"], "info": "This is a customized cz.", "questions": [ @@ -363,3 +369,18 @@ def test_info_with_info_path(tmpdir, config_info): def test_info_without_info(config_without_info): cz = CustomizeCommitsCz(config_without_info) assert cz.info() is None + + +def test_commit_parser(config): + cz = CustomizeCommitsCz(config) + assert cz.commit_parser == "^(?Pfeature|bug fix):\\s(?P.*)?" + + +def test_changelog_pattern(config): + cz = CustomizeCommitsCz(config) + assert cz.changelog_pattern == "^(feature|bug fix)?(!)?" + + +def test_change_type_map(config): + cz = CustomizeCommitsCz(config) + assert cz.change_type_map == {"feature": "Feat", "bug fix": "Fix"} From b0e98e103df137766f3d643b2882639fa829ba30 Mon Sep 17 00:00:00 2001 From: matteo_fiore Date: Tue, 5 Oct 2021 16:13:12 +0200 Subject: [PATCH 0083/1498] docs(customization): adding information on commit_parser, changelog_pattern, change_type_map customizable fields --- docs/customization.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/customization.md b/docs/customization.md index b165638e7c..92610f4585 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -26,6 +26,9 @@ info_path = "cz_customize_info.txt" info = """ This is customized info """ +commit_parser = "^(?Pfeature|bug fix):\\s(?P.*)?" +changelog_pattern = "^(feature|bug fix)?(!)?" +change_type_map = {"feature" = "Feat", "bug fix" = "Fix"} [[tool.commitizen.customize.questions]] type = "list" @@ -66,6 +69,9 @@ The equivalent example for a json config file: "change_type_order": ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"], "info_path": "cz_customize_info.txt", "info": "This is customized info", + "commit_parser": "^(?Pfeature|bug fix):\\s(?P.*)?", + "changelog_pattern": "^(feature|bug fix)?(!)?", + "change_type_map": {"feature": "Feat", "bug fix": "Fix"}, "questions": [ { "type": "list", @@ -109,6 +115,11 @@ commitizen: schema: ": " schema_pattern: "(feature|bug fix):(\\s.*)" bump_pattern: "^(break|new|fix|hotfix)" + commit_parser: "^(?Pfeature|bug fix):\\s(?P.*)?", + changelog_pattern: "^(feature|bug fix)?(!)?", + change_type_map: + feature: Feat + bug fix: Fix bump_map: break: MAJOR new: MINOR @@ -148,8 +159,12 @@ commitizen: | `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) | | `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) | | `change_type_order` | `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]` | +| `commit_parser` | `str` | `None` | (OPTIONAL) Regex to extract information used in creating changelog. [See more][changelog-spec] | +| `changelog_pattern` | `str` | `None` | (OPTIONAL) Regex to understand which commits to include in the changelog | +| `change_type_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the type of the commit to a changelog entry | [jinja2]: https://jinja.palletsprojects.com/en/2.10.x/ +[changelog-spec]: https://commitizen-tools.github.io/commitizen/changelog/ #### Detailed `questions` content From 0d269f2b4e10edbf1eda262430ec34414fe0b84b Mon Sep 17 00:00:00 2001 From: matteo_fiore Date: Mon, 11 Oct 2021 10:24:38 +0200 Subject: [PATCH 0084/1498] test(test_changelog_command): adding test for changelog generated with customize commits --- commitizen/defaults.py | 5 +++- tests/commands/conftest.py | 32 +++++++++++++++++++++++- tests/commands/test_changelog_command.py | 22 ++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 3fa7c5256d..0b217bf7f8 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,6 +1,6 @@ import pathlib from collections import OrderedDict -from typing import Any, Iterable, List, MutableMapping, Optional, Tuple, Union +from typing import Any, Dict, Iterable, List, MutableMapping, Optional, Tuple, Union from typing_extensions import TypedDict @@ -20,6 +20,9 @@ class CzSettings(TypedDict, total=False): info_path: Union[str, pathlib.Path] info: str message_template: str + commit_parser: Optional[str] + changelog_pattern: Optional[str] + change_type_map: Optional[Dict[str, str]] class Settings(TypedDict, total=False): diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index 3447b97422..91931849b2 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -3,7 +3,7 @@ import pytest from commitizen import defaults -from commitizen.config import BaseConfig +from commitizen.config import BaseConfig, JsonConfig @pytest.fixture() @@ -13,6 +13,36 @@ def config(): return _config +@pytest.fixture() +def config_customize(): + json_string = r"""{ + "commitizen": { + "name": "cz_customize", + "version": "3.0.0", + "changelog_incremental": "true", + "customize": { + "message_template": "{{prefix}}({{scope}}): {{subject}}\n\n{{body}}{% if is_breaking_change %}\nBREAKING CHANGE: {{footer}}{% endif %}", + "schema": "(): \n\n\n\n(BREAKING CHANGE: