From 1a33099c2d1450f6c6146f670f492e313e9273c5 Mon Sep 17 00:00:00 2001 From: Serpa <74364272+serpa-dystematic@users.noreply.github.com> Date: Fri, 15 Jan 2021 16:29:15 +0000 Subject: [PATCH 0001/1588] docs(bump): update cli tag format flag --- docs/bump.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/bump.md b/docs/bump.md index 668120588d..e78b92265c 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -167,11 +167,11 @@ It is used to read the format from the git tags, and also to generate the tags. Commitizen supports 2 types of formats, a simple and a more complex. ```bash -cz bump --tag_format="v$version" +cz bump --tag-format="v$version" ``` ```bash -cz bump --tag_format="v$minor.$major.$patch$prerelease" +cz bump --tag-format="v$minor.$major.$patch$prerelease" ``` In your `pyproject.toml` or `.cz.toml` From 20a54bf1b82cd7b573351db4d1e8814dd0be205d Mon Sep 17 00:00:00 2001 From: Oliver Berger Date: Tue, 22 Sep 2020 15:14:09 +0200 Subject: [PATCH 0002/1588] feat(#271): enable creation of annotated tags when bumping --- commitizen/cli.py | 5 +++++ commitizen/commands/bump.py | 14 +++++++++++-- commitizen/git.py | 4 ++-- docs/bump.md | 32 +++++++++++++++++++++-------- tests/commands/test_bump_command.py | 32 ++++++++++++++++++++++++++++- 5 files changed, 73 insertions(+), 14 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 45aa33f303..0436155d05 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -137,6 +137,11 @@ ), "action": "store_true", }, + { + "name": ["--annotated-tag", "-at"], + "help": "create annotated tag instead of lightweight one", + "action": "store_true", + }, ], }, { diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 666e29535d..16c12de0ec 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -32,7 +32,13 @@ def __init__(self, config: BaseConfig, arguments: dict): **config.settings, **{ key: arguments[key] - for key in ["tag_format", "prerelease", "increment", "bump_message"] + for key in [ + "tag_format", + "prerelease", + "increment", + "bump_message", + "annotated_tag", + ] if arguments[key] is not None }, } @@ -183,7 +189,11 @@ def __call__(self): # noqa: C901 c = git.commit(message, args=self._get_commit_args()) if c.return_code != 0: raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"') - c = git.tag(new_tag_version) + c = git.tag( + new_tag_version, + annotated=self.bump_settings.get("annotated_tag", False) + or bool(self.config.settings.get("annotated_tag", False)), + ) if c.return_code != 0: raise BumpTagFailedError(c.err) out.success("Done!") diff --git a/commitizen/git.py b/commitizen/git.py index 06ad240367..caaadd822f 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -45,8 +45,8 @@ def __repr__(self): return f"GitTag('{self.name}', '{self.rev}', '{self.date}')" -def tag(tag: str): - c = cmd.run(f"git tag {tag}") +def tag(tag: str, annotated: bool = False): + c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}") return c diff --git a/docs/bump.md b/docs/bump.md index 668120588d..3c92b965ee 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -57,30 +57,29 @@ $ cz bump --help usage: cz bump [-h] [--dry-run] [--files-only] [--changelog] [--no-verify] [--local-version] [--yes] [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] + [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] [--annotated-tag] optional arguments: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files --files-only bump version in the files from the config --changelog, -ch generate the changelog for the newest version - --no-verify this option bypasses the pre-commit and commit-msg - hooks + --no-verify this option bypasses the pre-commit and commit-msg hooks --yes accept automatically questions done --local-version bump the local portion of the version --tag-format TAG_FORMAT - the format used to tag the commit and read it, use it - in existing projects, wrap around simple quotes + the format used to tag the commit and read it, use it in existing projects, wrap + around simple quotes --bump-message BUMP_MESSAGE - template used to create the release commit, useful - when working with CI + template used to create the release commit, useful when working with CI --prerelease {alpha,beta,rc}, -pr {alpha,beta,rc} choose type of prerelease --increment {MAJOR,MINOR,PATCH} manually specify the desired increment --check-consistency, -cc - check consistency among versions defined in commitizen - configuration and version_files + check consistency among versions defined in commitizen configuration and + version_files + --annotated-tag, -at create annotated tag instead of lightweight one ``` ### `--files-only` @@ -158,6 +157,10 @@ version = "5.3.5+0.1.0" If `--local-version` is used, it will bump only the local version `0.1.0` and keep the public version `5.3.5` intact, bumping to the version `5.3.5+0.2.0`. +### `--annotated-tag` + +If `--annotated-tag` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. + ## Configuration ### `tag_format` @@ -256,6 +259,17 @@ defaults to: `false` update_changelog_on_bump = true ``` +--- + +### `annotated_tag` + +When set to `true` commitizen will create annotated tags. + +```toml +[tool.commitizen] +annotated_tag = true +``` + ## Custom bump Read the [customizing section](./customization.md). diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 77ea4840b0..ff4acd7a04 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -49,7 +49,37 @@ def test_bump_minor_increment(commit_msg, mocker): mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") - assert tag_exists is True + cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') + assert tag_exists is True and "commit:refs/tags/0.2.0\n" in cmd_res.out + + +@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_minor_increment_annotated(commit_msg, mocker): + create_file_and_commit(commit_msg) + testargs = ["cz", "bump", "--yes", "--annotated-tag"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + tag_exists = git.tag_exist("0.2.0") + cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') + assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out + + +@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +def test_bump_minor_increment_annotated_config_file( + commit_msg, mocker, tmp_commitizen_project +): + tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_commitizen_cfg_file.write( + f"{tmp_commitizen_cfg_file.read()}\n" f"annotated_tag = 1" + ) + create_file_and_commit(commit_msg) + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + tag_exists = git.tag_exist("0.2.0") + cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') + assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out @pytest.mark.usefixtures("tmp_commitizen_project") From ae9ba6fc5526cf478f52ef901418d85505109744 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 20 Jan 2021 16:02:14 +0000 Subject: [PATCH 0003/1588] =?UTF-8?q?bump:=20version=202.13.0=20=E2=86=92?= =?UTF-8?q?=202.14.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 d41450f03b..baf064bb59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v2.14.0 (2021-01-20) + +### Feat + +- **#271**: enable creation of annotated tags when bumping + ## v2.13.0 (2021-01-01) ### Refactor diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 930e2cd686..d0979fd030 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.13.0" +__version__ = "2.14.0" diff --git a/pyproject.toml b/pyproject.toml index e4b5e6ae88..656f81fc5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.13.0" +version = "2.14.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.13.0" +version = "2.14.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 427a9ec56c8003e1b1e05176cdece4a548fb91e1 Mon Sep 17 00:00:00 2001 From: Vinay Vennela <52368723+vinayvennela@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:14:14 +0530 Subject: [PATCH 0004/1588] fix: remove yaml warnings when using '.cz.yaml' --- commitizen/config/yaml_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/config/yaml_config.py b/commitizen/config/yaml_config.py index cc6c5f0338..510882b9b0 100644 --- a/commitizen/config/yaml_config.py +++ b/commitizen/config/yaml_config.py @@ -38,7 +38,7 @@ def set_key(self, key, value): We use to update the version number. """ with open(self.path, "r") as yaml_file: - parser = yaml.load(yaml_file) + parser = yaml.load(yaml_file, Loader=yaml.FullLoader) parser["commitizen"][key] = value with open(self.path, "w") as yaml_file: From aaba2b6992b4677740ce20bc8800fa64e7c8fb6c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 2 Feb 2021 09:24:34 +0000 Subject: [PATCH 0005/1588] =?UTF-8?q?bump:=20version=202.14.0=20=E2=86=92?= =?UTF-8?q?=202.14.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 baf064bb59..5bc01f3063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v2.14.1 (2021-02-02) + +### Fix + +- remove yaml warnings when using '.cz.yaml' + ## v2.14.0 (2021-01-20) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index d0979fd030..e199aa5550 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.14.0" +__version__ = "2.14.1" diff --git a/pyproject.toml b/pyproject.toml index 656f81fc5d..0dd3076b02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.14.0" +version = "2.14.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.14.0" +version = "2.14.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 3ef52577e648466aa39ea9e40e554f0e55dde15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Tue, 2 Feb 2021 10:34:27 +0100 Subject: [PATCH 0006/1588] ci: attempt to fix homebrew action --- .github/workflows/homebrewpublish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/homebrewpublish.yaml b/.github/workflows/homebrewpublish.yaml index fee4a70405..267ba4ec33 100644 --- a/.github/workflows/homebrewpublish.yaml +++ b/.github/workflows/homebrewpublish.yaml @@ -8,7 +8,7 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: macos-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout From 58c9c5a1024932b9ea7dbce98066d0fc156c074a Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 4 Feb 2021 18:52:36 +0800 Subject: [PATCH 0007/1588] fix(git): handle the empty commit and empty email cases --- commitizen/git.py | 3 +-- tests/test_git.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index caaadd822f..e50152296b 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -79,8 +79,7 @@ def get_commits( return [] git_commits = [] - for rev_and_commit in c.out.split(delimiter): - rev_and_commit = rev_and_commit.strip() + for rev_and_commit in c.out.split(f"\n{delimiter}\n"): if not rev_and_commit: continue rev, title, author, author_email, *body_list = rev_and_commit.split("\n") diff --git a/tests/test_git.py b/tests/test_git.py index bcbca58bb0..88c310e3c6 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -73,6 +73,33 @@ def test_get_commits_author_and_email(): assert "@" in commit.author_email +def test_get_commits_without_email(mocker): + raw_commit = ( + "a515bb8f71c403f6f7d1c17b9d8ebf2ce3959395\n" + "\n" + "user name\n" + "\n" + "----------commit-delimiter----------\n" + "12d3b4bdaa996ea7067a07660bb5df4772297bdd\n" + "feat(users): add username\n" + "user name\n" + "\n" + "----------commit-delimiter----------\n" + ) + mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=raw_commit)) + + commits = git.get_commits() + + assert commits[0].author == "user name" + assert commits[1].author == "user name" + + assert commits[0].author_email == "" + assert commits[1].author_email == "" + + assert commits[0].title == "" + assert commits[1].title == "feat(users): add username" + + def test_get_tag_names_has_correct_arrow_annotation(): arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"] From d6a817cbbabb56fd4c37e76bc70aed6796b31ef2 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 4 Feb 2021 18:52:52 +0800 Subject: [PATCH 0008/1588] style(init): remove unused comment out --- commitizen/commands/init.py | 1 - 1 file changed, 1 deletion(-) diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index 96b06f2080..eed9b83ae4 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -122,7 +122,6 @@ def _install_pre_commit_hook(self): # .pre-commit-config does not exist config_data["repos"] = [cz_hook_config] else: - # breakpoint() with open(pre_commit_config_filename) as config_file: yaml_data = yaml.safe_load(config_file) if yaml_data: From f01a03c5dc6fb3e364b730743bc33ab41f9986d9 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 6 Feb 2021 10:12:44 +0800 Subject: [PATCH 0009/1588] test(git): add test case to get_latest_tag_name --- tests/test_git.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_git.py b/tests/test_git.py index 88c310e3c6..b66ae60a92 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -3,7 +3,7 @@ import pytest -from commitizen import git +from commitizen import cmd, git from tests.utils import FakeCommand, create_file_and_commit @@ -104,3 +104,14 @@ def test_get_tag_names_has_correct_arrow_annotation(): arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"] assert arrow_annotation == List[Optional[str]] + + +def test_get_latest_tag_name(tmp_commitizen_project): + with tmp_commitizen_project.as_cwd(): + tag_name = git.get_latest_tag_name() + assert tag_name is None + + create_file_and_commit("feat(test): test") + cmd.run("git tag 1.0") + tag_name = git.get_latest_tag_name() + assert tag_name == "1.0" From 055fc17260676114e83f64acefe4c0ece4fb5677 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 6 Feb 2021 10:27:47 +0800 Subject: [PATCH 0010/1588] docs(readme): add download count badge --- docs/README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 52fc9d444e..05bdc79a22 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,10 +1,8 @@ [![Github Actions](https://github.com/commitizen-tools/commitizen/workflows/Python%20package/badge.svg?style=flat-square)](https://github.com/commitizen-tools/commitizen/actions) -[![Conventional -Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org) -[![PyPI Package latest -release](https://img.shields.io/pypi/v/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) -[![Supported -versions](https://img.shields.io/pypi/pyversions/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) +[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org) +[![PyPI Package latest release](https://img.shields.io/pypi/v/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) +[![PyPI Package download count (per month)](https://img.shields.io/pypi/dm/commitizen?style=flat-square)](https://pypi.org/project/commitizen/) +[![Supported versions](https://img.shields.io/pypi/pyversions/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) [![homebrew](https://img.shields.io/homebrew/v/commitizen?color=teal&style=flat-square)](https://formulae.brew.sh/formula/commitizen) [![Codecov](https://img.shields.io/codecov/c/github/commitizen-tools/commitizen.svg?style=flat-square)](https://codecov.io/gh/commitizen-tools/commitizen) From 8fabcff9a3de5a5f76c6fbe9e08745b10dac0c61 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 6 Feb 2021 09:40:49 +0000 Subject: [PATCH 0011/1588] =?UTF-8?q?bump:=20version=202.14.1=20=E2=86=92?= =?UTF-8?q?=202.14.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 5bc01f3063..c5091a188e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v2.14.2 (2021-02-06) + +### Fix + +- **git**: handle the empty commit and empty email cases + ## v2.14.1 (2021-02-02) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index e199aa5550..abe7e03a96 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.14.1" +__version__ = "2.14.2" diff --git a/pyproject.toml b/pyproject.toml index 0dd3076b02..37c99f2110 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.14.1" +version = "2.14.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.14.1" +version = "2.14.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 3fdf42d96035dea8f52ccd83da17856e9906a532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Sun, 7 Feb 2021 18:45:54 +0100 Subject: [PATCH 0012/1588] docs(faq): add new questions to faq --- docs/faq.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index ab6bb97fa1..37300c88e1 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -26,3 +26,50 @@ version_files = [ "package.json:\"version\":" ] ``` + +### 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 revert a bump? + +If for any reason, the created tag and changelog were to be undone, this is the snippet: + +```sh +git tag --delete +git reset HEAD~ +git reset --hard HEAD +``` + +This will remove the last tag created, plus the commit containing the update to `.cz.toml` and the changelog generated for the version. + +In case the commit was pushed to the server you can remove it by running + +```sh +git push --delete origin +``` + +## Is this project affiliated with the Commitizen JS project? + +It is not affiliated. + +Both are used for similar purposes, parsing commits, generating changelog and version we presume. +This one is written in python to make integration easier for python projects and the other serves the JS packages. + +They differ a bit in design, not sure if cz-js does any of this, but these are some of the stuff you can do with this repo (python's commitizen): + +- create custom rules, version bumps and changelog generation, by default we use the popular conventional commits (I think cz-js allows this). +- single package, install one thing and it will work (cz-js is a monorepo, but you have to install different dependencies AFAIK) +- pre-commit integration +- works on any language project, as long as you create the `.cz.toml` file. + +Where do they cross paths? + +If you are using conventional commits in your git history, then you could swap one with the other in theory. + +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 From bf3fce4ec4f7123bcb7ff7ad817766e05513cc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Sun, 7 Feb 2021 19:00:36 +0100 Subject: [PATCH 0013/1588] docs: update links on resources --- docs/external_links.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/external_links.md b/docs/external_links.md index b31ac85bb3..69ad952c66 100644 --- a/docs/external_links.md +++ b/docs/external_links.md @@ -1,14 +1,16 @@ +> If you have written over commitizen, make a PR and add the link here 💪 + ## Talks -- commitizen-tools: What can we gain from crafting a git message convention - - Speaker: Wei Lee - - Occasion: Taipey.py 2020 June Meetup, Remote Python Pizza 2020 - - Material - - [slides](https://speakerdeck.com/leew/commitizen-tools-what-can-we-gain-from-crafting-a-git-message-convention-at-taipey-dot-py) +| Name | Speaker | Occasion | Language | Extra | +| ------------------------------------------------------------------------- | --------------- | ---------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- | +| commitizen-tools: What can we gain from crafting a git message convention | Wei Lee | Taipey.py 2020 June Meetup, Remote Python Pizza 2020 | English | [slides](https://speakerdeck.com/leew/commitizen-tools-what-can-we-gain-from-crafting-a-git-message-convention-at-taipey-dot-py) | +| Automating release cycles | Santiago Fraire | PyAmsterdam June 24, 2020, Online | English | [slides](https://woile.github.io/commitizen-presentation/) | +| [Automatizando Releases con Commitizen y Github Actions][automatizando] | Santiago Fraire | PyConAr 2020, Remote | Español | [slides](https://woile.github.io/automating-releases-github-actions-presentation/#/) | ## Articles - [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](http://woile.github.io/posts/automating-semver-releases-with-commitizen/) (English) +- [Automating semantic release with commitizen](https://woile.dev/posts/automating-semver-releases-with-commitizen/) (English) -> If you have written about commitizen, you can make a PR to add the link here 💪 +[automatizando]: https://youtu.be/t3aE2M8UPBo From 1605d699f03f61432120febdc32e096ad4e3ee7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Tue, 9 Feb 2021 09:04:54 +0100 Subject: [PATCH 0014/1588] docs: correct title in faq --- docs/faq.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 37300c88e1..c0e22cefde 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -27,14 +27,14 @@ version_files = [ ] ``` -### Why are `revert` and `chore` valid types in the check pattern of cz conventional_commits but not types we can select? +## 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 revert a bump? +## How to revert a bump? If for any reason, the created tag and changelog were to be undone, this is the snippet: From 0621bc475eeb80dc8c035a61226bb093adc6329a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 19 Feb 2021 12:14:44 +0100 Subject: [PATCH 0015/1588] feat(changelog): add support for multiline BREAKING paragraph Closes #346 --- commitizen/changelog.py | 15 +++++++++++++-- setup.cfg | 2 +- tests/commands/test_changelog_command.py | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/commitizen/changelog.py b/commitizen/changelog.py index ca36015ed9..7bb9007cdc 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -76,6 +76,8 @@ def generate_tree_from_commits( ) -> Iterable[Dict]: pat = re.compile(changelog_pattern) map_pat = re.compile(commit_parser, re.MULTILINE) + body_map_pat = re.compile(commit_parser, re.MULTILINE | re.DOTALL) + # Check if the latest commit is not tagged latest_commit = commits[0] current_tag: Optional[GitTag] = get_commit_tag(latest_commit, tags) @@ -110,8 +112,8 @@ def generate_tree_from_commits( if not matches: continue + # Process subject from commit message message = map_pat.match(commit.message) - message_body = map_pat.search(commit.body) if message: parsed_message: Dict = message.groupdict() # change_type becomes optional by providing None @@ -122,9 +124,18 @@ def generate_tree_from_commits( if changelog_message_builder_hook: parsed_message = changelog_message_builder_hook(parsed_message, commit) changes[change_type].append(parsed_message) - if message_body: + + # Process body from commit message + body_parts = commit.body.split("\n\n") + for body_part in body_parts: + message_body = body_map_pat.match(body_part) + if not message_body: + continue parsed_message_body: Dict = message_body.groupdict() + change_type = parsed_message_body.pop("change_type", None) + if change_type_map: + change_type = change_type_map.get(change_type, change_type) changes[change_type].append(parsed_message_body) yield {"version": current_tag_name, "date": current_tag_date, "changes": changes} diff --git a/setup.cfg b/setup.cfg index de0172c175..d4e21ad5b3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,4 +35,4 @@ exclude = build, dist max-line-length = 88 -max-complexity = 11 +max-complexity = 12 diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index e5993dbdfa..7448fee320 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -386,6 +386,30 @@ def test_breaking_change_content_v1(mocker, capsys): ) +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_breaking_change_content_v1_multiline(mocker, capsys): + commit_message = ( + "feat(users): email pattern corrected\n\n" + "body content\n\n" + "BREAKING CHANGE: migrate by renaming user to users.\n" + "and then connect the thingy with the other thingy\n\n" + "footer content" + ) + create_file_and_commit(commit_message) + testargs = ["cz", "changelog", "--dry-run"] + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(DryRunExit): + cli.main() + out, _ = capsys.readouterr() + + assert out == ( + "## Unreleased\n\n### Feat\n\n- **users**: email pattern corrected\n\n" + "### BREAKING CHANGE\n\n- migrate by renaming user to users.\n" + "and then connect the thingy with the other thingy" + "\n\n" + ) + + @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_config_flag_increment(mocker, changelog_path, config_path): From 85f0cb906aa3b74476fc0b4c7abf1d2cf90913be Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 21 Feb 2021 10:11:08 +0000 Subject: [PATCH 0016/1588] =?UTF-8?q?bump:=20version=202.14.2=20=E2=86=92?= =?UTF-8?q?=202.15.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5091a188e..863b358077 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## v2.15.0 (2021-02-21) + ## v2.14.2 (2021-02-06) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index abe7e03a96..90c1ae3a02 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.14.2" +__version__ = "2.15.0" diff --git a/pyproject.toml b/pyproject.toml index 37c99f2110..aab052f856 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.14.2" +version = "2.15.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.14.2" +version = "2.15.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 4671258523cf331904080753c9d83c3cf8b55388 Mon Sep 17 00:00:00 2001 From: longhao Date: Sun, 21 Feb 2021 23:54:15 +0800 Subject: [PATCH 0017/1588] fix(config): change read mode from `r` to `rb` --- commitizen/config/__init__.py | 4 ++-- commitizen/config/base_config.py | 2 +- commitizen/config/json_config.py | 6 +++--- commitizen/config/toml_config.py | 6 +++--- commitizen/config/yaml_config.py | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/commitizen/config/__init__.py b/commitizen/config/__init__.py index 2cbd544825..e4e414437c 100644 --- a/commitizen/config/__init__.py +++ b/commitizen/config/__init__.py @@ -28,8 +28,8 @@ def read_cfg() -> BaseConfig: _conf: Union[TomlConfig, JsonConfig, YAMLConfig] - with open(filename, "r") as f: - data: str = f.read() + with open(filename, "rb") as f: + data: bytes = f.read() if "toml" in filename.suffix: _conf = TomlConfig(data=data, path=filename) diff --git a/commitizen/config/base_config.py b/commitizen/config/base_config.py index f3e0767dd2..76cd1706e1 100644 --- a/commitizen/config/base_config.py +++ b/commitizen/config/base_config.py @@ -31,5 +31,5 @@ def update(self, data: dict): def add_path(self, path: Union[str, Path]): self._path = Path(path) - def _parse_setting(self, data: str) -> dict: + def _parse_setting(self, data: Union[bytes, str]) -> dict: raise NotImplementedError() diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index fbf37bbd83..725e37a0eb 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -6,7 +6,7 @@ class JsonConfig(BaseConfig): - def __init__(self, *, data: str, path: Union[Path, str]): + def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(JsonConfig, self).__init__() self.is_empty_config = False self._parse_setting(data) @@ -22,7 +22,7 @@ def set_key(self, key, value): For now only strings are supported. We use to update the version number. """ - with open(self.path, "r") as f: + with open(self.path, "rb") as f: parser = json.load(f) parser["commitizen"][key] = value @@ -30,7 +30,7 @@ def set_key(self, key, value): json.dump(parser, f) return self - def _parse_setting(self, data: str): + def _parse_setting(self, data: Union[bytes, str]): """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 a9b3cfab1e..27ab47d4e2 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -7,7 +7,7 @@ class TomlConfig(BaseConfig): - def __init__(self, *, data: str, path: Union[Path, str]): + def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(TomlConfig, self).__init__() self.is_empty_config = False self._parse_setting(data) @@ -23,7 +23,7 @@ def set_key(self, key, value): For now only strings are supported. We use to update the version number. """ - with open(self.path, "r") as f: + with open(self.path, "rb") as f: parser = parse(f.read()) parser["tool"]["commitizen"][key] = value @@ -31,7 +31,7 @@ def set_key(self, key, value): f.write(parser.as_string()) return self - def _parse_setting(self, data: str): + def _parse_setting(self, data: Union[bytes, str]): """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 510882b9b0..5d199c1929 100644 --- a/commitizen/config/yaml_config.py +++ b/commitizen/config/yaml_config.py @@ -7,7 +7,7 @@ class YAMLConfig(BaseConfig): - def __init__(self, *, data: str, path: Union[Path, str]): + def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(YAMLConfig, self).__init__() self.is_empty_config = False self._parse_setting(data) @@ -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: str): + def _parse_setting(self, data: Union[bytes, str]): """We expect to have a section in cz.yaml looking like ``` @@ -37,7 +37,7 @@ def set_key(self, key, value): For now only strings are supported. We use to update the version number. """ - with open(self.path, "r") as yaml_file: + with open(self.path, "rb") as yaml_file: parser = yaml.load(yaml_file, Loader=yaml.FullLoader) parser["commitizen"][key] = value From d09841655e36c70fb6fd2624fc8325dfe0ab0b83 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 21 Feb 2021 20:12:18 +0000 Subject: [PATCH 0018/1588] =?UTF-8?q?bump:=20version=202.15.0=20=E2=86=92?= =?UTF-8?q?=202.15.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 863b358077..213cac413e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## v2.15.1 (2021-02-21) + ## v2.15.0 (2021-02-21) ## v2.14.2 (2021-02-06) diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 90c1ae3a02..b1b269754f 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.15.0" +__version__ = "2.15.1" diff --git a/pyproject.toml b/pyproject.toml index aab052f856..37765cb77c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.15.0" +version = "2.15.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.15.0" +version = "2.15.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 2756e91e3f056ba5e34cd59f681ff194ebf9bed3 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 24 Feb 2021 09:58:20 +0800 Subject: [PATCH 0019/1588] fix(git): fix get_commits deliminator --- commitizen/git.py | 2 +- tests/test_git.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/commitizen/git.py b/commitizen/git.py index e50152296b..b8fbd0715a 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -79,7 +79,7 @@ def get_commits( return [] git_commits = [] - for rev_and_commit in c.out.split(f"\n{delimiter}\n"): + for rev_and_commit in c.out.split(f"{delimiter}\n"): if not rev_and_commit: continue rev, title, author, author_email, *body_list = rev_and_commit.split("\n") diff --git a/tests/test_git.py b/tests/test_git.py index b66ae60a92..8ba2f64cb8 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -100,6 +100,43 @@ def test_get_commits_without_email(mocker): assert commits[1].title == "feat(users): add username" +def test_get_commits_without_breakline_in_each_commit(mocker): + raw_commit = ( + "ae9ba6fc5526cf478f52ef901418d85505109744\n" + "bump: version 2.13.0 → 2.14.0\n" + "GitHub Action\n" + "action@github.com\n" + "----------commit-delimiter----------\n" + "ff2f56ca844de72a9d59590831087bf5a97bac84\n" + "Merge pull request #332 from cliles/feature/271-redux\n" + "User\n" + "user@email.com\n" + "Feature/271 redux----------commit-delimiter----------\n" + "20a54bf1b82cd7b573351db4d1e8814dd0be205d\n" + "feat(#271): enable creation of annotated tags when bumping\n" + "User 2\n" + "user@email.edu\n" + "----------commit-delimiter----------\n" + ) + mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=raw_commit)) + + commits = git.get_commits() + + assert commits[0].author == "GitHub Action" + assert commits[1].author == "User" + assert commits[2].author == "User 2" + + assert commits[0].author_email == "action@github.com" + assert commits[1].author_email == "user@email.com" + assert commits[2].author_email == "user@email.edu" + + assert commits[0].title == "bump: version 2.13.0 → 2.14.0" + assert commits[1].title == "Merge pull request #332 from cliles/feature/271-redux" + assert ( + commits[2].title == "feat(#271): enable creation of annotated tags when bumping" + ) + + def test_get_tag_names_has_correct_arrow_annotation(): arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"] From 311019075f49798cd6971e514c2c01d83d60d21e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 24 Feb 2021 08:43:49 +0000 Subject: [PATCH 0020/1588] =?UTF-8?q?bump:=20version=202.15.1=20=E2=86=92?= =?UTF-8?q?=202.15.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 213cac413e..e55fc64df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## v2.15.2 (2021-02-24) + ## v2.15.1 (2021-02-21) ## v2.15.0 (2021-02-21) diff --git a/commitizen/__version__.py b/commitizen/__version__.py index b1b269754f..dd2b2a1e09 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.15.1" +__version__ = "2.15.2" diff --git a/pyproject.toml b/pyproject.toml index 37765cb77c..c565160f9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.15.1" +version = "2.15.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.15.1" +version = "2.15.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 07d1b788f9d4c5a1ebe5cb8999f964a8d6f395a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Wed, 24 Feb 2021 10:28:54 +0100 Subject: [PATCH 0021/1588] docs(CHANGELOG): regenerate missing data from previous bug --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e55fc64df4..2b7b5be6b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,22 @@ + ## v2.15.2 (2021-02-24) +### Fix + +- **git**: fix get_commits deliminator + ## v2.15.1 (2021-02-21) +### Fix + +- **config**: change read mode from `r` to `rb` + ## v2.15.0 (2021-02-21) +### Feat + +- **changelog**: add support for multiline BREAKING paragraph + ## v2.14.2 (2021-02-06) ### Fix From ed06664a91551a93120ddcf3f25cda46edf1ddce Mon Sep 17 00:00:00 2001 From: 7kachika Date: Fri, 26 Feb 2021 19:15:07 +0800 Subject: [PATCH 0022/1588] fix: add utf-8 encode when write toml file --- commitizen/config/toml_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index 27ab47d4e2..1950cb11d1 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -27,8 +27,8 @@ def set_key(self, key, value): parser = parse(f.read()) parser["tool"]["commitizen"][key] = value - with open(self.path, "w") as f: - f.write(parser.as_string()) + with open(self.path, "wb") as f: + f.write(parser.as_string().encode("utf-8")) return self def _parse_setting(self, data: Union[bytes, str]): From e1c1ca86dc4b6e63d7bd1ee13ec16ab3d36eeb16 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 26 Feb 2021 13:31:24 +0000 Subject: [PATCH 0023/1588] =?UTF-8?q?bump:=20version=202.15.2=20=E2=86=92?= =?UTF-8?q?=202.15.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 2b7b5be6b1..fd49b91bc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.15.3 (2021-02-26) + +### Fix + +- add utf-8 encode when write toml file + ## v2.15.2 (2021-02-24) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index dd2b2a1e09..44e30b1266 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.15.2" +__version__ = "2.15.3" diff --git a/pyproject.toml b/pyproject.toml index c565160f9a..c6afee1864 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.15.2" +version = "2.15.3" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.15.2" +version = "2.15.3" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 80bc84a2cf0efa94309eaa8c3a740d2fac909c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 5 Mar 2021 11:34:10 -0300 Subject: [PATCH 0024/1588] feat(bump): send incremental changelog to stdout and bump output to stderr --- commitizen/cli.py | 6 +++++ commitizen/commands/bump.py | 36 +++++++++++++++++++++++++++-- commitizen/out.py | 4 ++++ tests/commands/test_bump_command.py | 18 +++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 0436155d05..a5c336f9fd 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -142,6 +142,12 @@ "help": "create annotated tag instead of lightweight one", "action": "store_true", }, + { + "name": ["--changelog-to-stdout"], + "action": "store_true", + "default": False, + "help": "Output changelog to the stdout", + }, ], }, { diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 16c12de0ec..4f2a0d3981 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -46,6 +46,7 @@ def __init__(self, config: BaseConfig, arguments: dict): self.changelog = arguments["changelog"] or self.config.settings.get( "update_changelog_on_bump" ) + self.changelog_to_stdout = arguments["changelog_to_stdout"] self.no_verify = arguments["no_verify"] self.check_consistency = arguments["check_consistency"] @@ -110,6 +111,11 @@ def __call__(self): # noqa: C901 else: commits = git.get_commits(current_tag_version) + # If user specified changelog_to_stdout, they probably want the + # changelog to be generated as well, this is the most intuitive solution + if not self.changelog and self.changelog_to_stdout: + self.changelog = True + # No commits, there is no need to create an empty tag. # Unless we previously had a prerelease. if not commits and not current_version_instance.is_prerelease: @@ -149,12 +155,20 @@ def __call__(self): # noqa: C901 ) # Report found information - out.write( + information = ( f"{message}\n" f"tag to create: {new_tag_version}\n" f"increment detected: {increment}\n" ) + if self.changelog_to_stdout: + # When the changelog goes to stdout, we want to send + # the bump information to stderr, this way the + # changelog output can be captured + out.diagnostic(information) + else: + out.write(information) + if increment is None and new_tag_version == current_tag_version: raise NoneIncrementExit() @@ -170,6 +184,19 @@ def __call__(self): # noqa: C901 ) if self.changelog: + if self.changelog_to_stdout: + changelog_cmd = Changelog( + self.config, + { + "unreleased_version": new_tag_version, + "incremental": True, + "dry_run": True, + }, + ) + try: + changelog_cmd() + except DryRunExit: + pass changelog_cmd = Changelog( self.config, { @@ -196,7 +223,12 @@ def __call__(self): # noqa: C901 ) if c.return_code != 0: raise BumpTagFailedError(c.err) - out.success("Done!") + + # TODO: For v3 output this only as diagnostic and remove this if + if self.changelog_to_stdout: + out.diagnostic("Done!") + else: + out.success("Done!") def _get_commit_args(self): commit_args = ["-a"] diff --git a/commitizen/out.py b/commitizen/out.py index 268f02e29f..7ac5ba420b 100644 --- a/commitizen/out.py +++ b/commitizen/out.py @@ -26,3 +26,7 @@ def success(value: str): def info(value: str): message = colored(value, "blue") line(message) + + +def diagnostic(value: str): + line(value, file=sys.stderr) diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index ff4acd7a04..8508c66eee 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -414,3 +414,21 @@ def test_prevent_prerelease_when_no_increment_detected( "[NO_COMMITS_FOUND]\n" "No commits found to generate a pre-release." ) assert expected_error_message in str(excinfo.value) + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path): + create_file_and_commit("feat(user): this should appear in stdout") + testargs = ["cz", "bump", "--yes", "--changelog-to-stdout"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + out, _ = capsys.readouterr() + + assert "this should appear in stdout" in out + tag_exists = git.tag_exist("0.2.0") + assert tag_exists is True + + with open(changelog_path, "r") as f: + out = f.read() + assert out.startswith("#") + assert "0.2.0" in out From ab35a0115dcaedf5d08d429c696f8a4215d65f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 5 Mar 2021 12:03:23 -0300 Subject: [PATCH 0025/1588] test: correct yaml load warning --- tests/commands/test_init_command.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 977e9e6a11..729950fc8a 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -116,7 +116,9 @@ def test_no_existing_pre_commit_conifg(_, default_choice, tmpdir, config): if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: - assert yaml.load(file) == EXPECTED_DICT_CONFIG + assert ( + yaml.load(file, Loader=yaml.FullLoader) == EXPECTED_DICT_CONFIG + ) else: config_data = file.read() assert config_data == expected_config @@ -136,7 +138,9 @@ def test_empty_pre_commit_config(_, default_choice, tmpdir, config): if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: - assert yaml.load(file) == EXPECTED_DICT_CONFIG + assert ( + yaml.load(file, Loader=yaml.FullLoader) == EXPECTED_DICT_CONFIG + ) else: config_data = file.read() assert config_data == expected_config @@ -162,7 +166,9 @@ def test_pre_commit_config_without_cz_hook(_, default_choice, tmpdir, config): if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: - assert yaml.load(file) == EXPECTED_DICT_CONFIG + assert ( + yaml.load(file, Loader=yaml.FullLoader) == EXPECTED_DICT_CONFIG + ) else: config_data = file.read() assert config_data == expected_config @@ -184,7 +190,9 @@ def test_cz_hook_exists_in_pre_commit_config(_, default_choice, tmpdir, config): if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: - assert yaml.load(file) == EXPECTED_DICT_CONFIG + assert ( + yaml.load(file, Loader=yaml.FullLoader) == EXPECTED_DICT_CONFIG + ) else: config_data = file.read() assert config_data == expected_config From ea372e3602ad246c760154392fc5f0cc8bfc4494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 5 Mar 2021 12:10:58 -0300 Subject: [PATCH 0026/1588] docs(bump): explain new flag --changelog-to-stdout --- docs/bump.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/bump.md b/docs/bump.md index 086cfa2ea2..bf3b207cd6 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -139,7 +139,6 @@ However, it will still update `pyproject.toml` and `src/__version__.py`. To fix it, you'll first `git checkout .` to reset to the status before trying to bump and update the version in `setup.py` to `1.21.0` - ### `--local-version` Bump the local portion of the version. @@ -161,6 +160,25 @@ If `--local-version` is used, it will bump only the local version `0.1.0` and ke If `--annotated-tag` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. +### `--changelog-to-stdout` + +If `--changelog-to-stdout` is used, the incremental changelog generated by the bump +will be sent to the stdout, and any other message generated by the bump will be +sent to stderr. + +If `--changelog` is not used with this command, it is still smart enough to +understand that the user wants to create a changelog. It is recommened to be +explicit and use `--changelog` (or the setting `update_changelog_on_bump`). + +This command is useful to "transport" the newly created changelog. +It can be sent to an auditing system, or to create a Github Release. + +Example: + +```bash +cz bump --changelog --changelog-to-stdout > body.md +``` + ## Configuration ### `tag_format` @@ -198,7 +216,7 @@ Supported variables: --- -### `version_files` * +### `version_files` \* It is used to identify the files which should be updated with the new version. It is also possible to provide a pattern for each file, separated by colons (`:`). From 3b591f02c8c0008adb57775a17ece7a9b0d6f230 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 8 Mar 2021 01:16:51 +0000 Subject: [PATCH 0027/1588] =?UTF-8?q?bump:=20version=202.15.3=20=E2=86=92?= =?UTF-8?q?=202.16.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 fd49b91bc0..024535f0dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.16.0 (2021-03-08) + +### Feat + +- **bump**: send incremental changelog to stdout and bump output to stderr + ## v2.15.3 (2021-02-26) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 44e30b1266..8f4a351703 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.15.3" +__version__ = "2.16.0" diff --git a/pyproject.toml b/pyproject.toml index c6afee1864..82f8a88e28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.15.3" +version = "2.16.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.15.3" +version = "2.16.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From e2c73030f94dd00a6c134a97a091325b315c158f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Mon, 8 Mar 2021 11:34:19 -0300 Subject: [PATCH 0028/1588] docs(tutorial/github_action): explain how to create a github release --- docs/tutorials/github_actions.md | 70 ++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/docs/tutorials/github_actions.md b/docs/tutorials/github_actions.md index aad2e8eb4f..58726afcd2 100644 --- a/docs/tutorials/github_actions.md +++ b/docs/tutorials/github_actions.md @@ -7,12 +7,12 @@ the new tag, back to your master branch, we have to: 1. Create a personal access token. [Follow the instructions here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token). And copy the generated key 2. Create a secret called `PERSONAL_ACCESS_TOKEN`, with the copied key, by going to your -project repository and then `Settings > Secrets > Add new secret`. + project repository and then `Settings > Secrets > Add new secret`. 3. In your repository create a new file `.github/workflows/bumpversion.yml` -with the following content. + with the following content. !!! warning - If you use `GITHUB_TOKEN` instead of `PERSONAL_ACCESS_TOKEN`, the job won't trigger another workflow. It's like using `[skip ci]` in other CI's. +If you use `GITHUB_TOKEN` instead of `PERSONAL_ACCESS_TOKEN`, the job won't trigger another workflow. It's like using `[skip ci]` in other CI's. ```yaml name: Bump version @@ -31,17 +31,43 @@ jobs: - name: Check out uses: actions/checkout@v2 with: - token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}' + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" fetch-depth: 0 - name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - ``` Push to master and that's it. +### Creating a github release + +You can modify the previous action. + +Add the variable `changelog_increment_filename` in the `commitizen-action`, specifying +where to output the content of the changelog for the newly created version. + +And then add a step using a github action to create the release: `softprops/action-gh-release` + +The commitizen action creates an env variable called `REVISION`, containing the +newely created version. + +```yaml +- name: Create bump and changelog + uses: commitizen-tools/commitizen-action@master + with: + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + changelog_increment_filename: body.md +- name: Release + uses: softprops/action-gh-release@v1 + with: + body_path: "body.md" + tag_name: ${{ env.REVISION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + ### Publishing a python package Once the new tag is created, triggering an automatic publish command would be desired. @@ -62,28 +88,28 @@ name: Upload Python Package on: push: tags: - - '*' # Will trigger for every tag, alternative: 'v*' + - "*" # Will trigger for every tag, alternative: 'v*' jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --pre -U poetry - poetry --version - poetry install - - name: Build and publish - env: - PYPI_USERNAME: __token__ - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - ./scripts/publish + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --pre -U poetry + poetry --version + poetry install + - name: Build and publish + env: + PYPI_USERNAME: __token__ + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + ./scripts/publish ``` Notice that we are calling a bash script in `./scripts/publish`, you should configure it with your tools (twine, poetry, etc.). Check [commitizen example](https://github.com/commitizen-tools/commitizen/blob/master/scripts/publish) From e8955d4e36dedb7f7ab35efe0ca858b44664ae9b Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 22 Mar 2021 00:59:34 +0200 Subject: [PATCH 0029/1588] docs(README): correct typo --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 05bdc79a22..f930841380 100644 --- a/docs/README.md +++ b/docs/README.md @@ -177,7 +177,7 @@ See [Third-Party Commitizen Templates](third-party-commitizen.md). ### 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](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) From 8902b4092a58fb498066e9e804591a73917555e8 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 31 Mar 2021 09:03:39 +0100 Subject: [PATCH 0030/1588] docs: remove duplicated file name `.cz.toml` is specified twice and gets confusing. --- docs/customization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/customization.md b/docs/customization.md index 204395ed4b..3492d8288c 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -3,7 +3,7 @@ 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.toml`, `.cz.json`, and `cz.json`)** +**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: From cd7018ebae89b76d9174d103407d140a1dd7bf09 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Sat, 20 Mar 2021 22:39:33 +0100 Subject: [PATCH 0031/1588] feat: Support versions on random positions --- commitizen/bump.py | 47 +++++++++++++--------- tests/test_bump_update_version_in_files.py | 36 +++++++++++++++++ 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index ccb1257e7d..2d0c7aee83 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -150,26 +150,25 @@ def update_version_in_files( """ # TODO: separate check step and write step for location in files: - filepath, *regexes = location.split(":", maxsplit=1) + filepath, *regexes = location.split(":") regex = regexes[0] if regexes else None - - # Read in the file - file_content = [] current_version_found = False - with open(filepath, "r") as version_file: - for line in version_file: - if regex: - match = re.search(regex, line) - if not match: - file_content.append(line) - continue - - # Replace the target string - if current_version in line: - current_version_found = True - file_content.append(line.replace(current_version, new_version)) - else: - file_content.append(line) + + version_file = open(filepath, "r").read() + match = regex and re.search(regex, version_file, re.MULTILINE) + if match: + left = version_file[: match.end()] + right = version_file[match.end() :] + line_break = _get_line_break_position(right) + middle = right[:line_break] + current_version_found = current_version in middle + right = right[line_break:] + version_file = left + middle.replace(current_version, new_version) + right + + if not regex: + current_version_regex = _version_to_regex(current_version) + current_version_found = current_version_regex.search(version_file) and True + version_file = current_version_regex.sub(new_version, version_file) if check_consistency and not current_version_found: raise CurrentVersionNotFoundError( @@ -180,7 +179,17 @@ def update_version_in_files( # Write the file out again with open(filepath, "w") as file: - file.write("".join(file_content)) + file.write("".join(version_file)) + + +def _get_line_break_position(text: str) -> int: + position = text.find("\n") + return max(position, 0) + + +def _version_to_regex(version: str): + clean_regex = version.replace(".", r"\.").replace("+", r"\+") + return re.compile(f"\\b{clean_regex}\\b") def create_tag(version: Union[Version, str], tag_format: Optional[str] = None): diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 26a6ad677a..cadf4af8d2 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -1,3 +1,5 @@ +import re + import pytest from commitizen import bump @@ -33,6 +35,21 @@ } """ +# The order cannot be guaranteed here +CARGO_LOCK = """ +[[package]] +name = "textwrap" +version = "1.2.3" + +[[package]] +name = "there-i-fixed-it" +version = "1.2.3" + +[[package]] +name = "other-project" +version = "1.2.3" +""" + @pytest.fixture(scope="function") def commitizen_config_file(tmpdir): @@ -55,6 +72,13 @@ def inconsistent_python_version_file(tmpdir): return str(tmp_file) +@pytest.fixture(scope="function") +def random_location_version_file(tmpdir): + tmp_file = tmpdir.join("Cargo.lock") + tmp_file.write(CARGO_LOCK) + return str(tmp_file) + + @pytest.fixture(scope="function") def version_repeated_file(tmpdir): tmp_file = tmpdir.join("package.json") @@ -90,6 +114,18 @@ def test_partial_update_of_file(version_repeated_file): assert old_version in data +def test_random_location(random_location_version_file): + old_version = "1.2.3" + new_version = "2.0.0" + location = f"{random_location_version_file}:there-i-fixed-it.+\nversion" + + bump.update_version_in_files(old_version, new_version, [location]) + with open(random_location_version_file, "r") as f: + data = f.read() + assert len(re.findall(old_version, data)) == 2 + assert len(re.findall(new_version, data)) == 1 + + def test_file_version_inconsistent_error( commitizen_config_file, inconsistent_python_version_file, version_repeated_file ): From 8689546f84d4d5a3f9ff7a747207b3601baa92a3 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Wed, 31 Mar 2021 17:45:14 +0200 Subject: [PATCH 0032/1588] chore: Fix CR questions --- commitizen/bump.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index 2d0c7aee83..b91639289f 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -154,7 +154,9 @@ def update_version_in_files( regex = regexes[0] if regexes else None current_version_found = False - version_file = open(filepath, "r").read() + with open(filepath, "r") as f: + version_file = f.read() + match = regex and re.search(regex, version_file, re.MULTILINE) if match: left = version_file[: match.end()] @@ -167,7 +169,7 @@ def update_version_in_files( if not regex: current_version_regex = _version_to_regex(current_version) - current_version_found = current_version_regex.search(version_file) and True + current_version_found = bool(current_version_regex.search(version_file)) version_file = current_version_regex.sub(new_version, version_file) if check_consistency and not current_version_found: From 32916abd2210e8c2c8852b42f51fcbbb01181f4b Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 2 Apr 2021 01:27:36 +0000 Subject: [PATCH 0033/1588] =?UTF-8?q?bump:=20version=202.16.0=20=E2=86=92?= =?UTF-8?q?=202.17.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 024535f0dc..913780b54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.0 (2021-04-02) + +### Feat + +- Support versions on random positions + ## v2.16.0 (2021-03-08) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 8f4a351703..a6b62ff3b2 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.16.0" +__version__ = "2.17.0" diff --git a/pyproject.toml b/pyproject.toml index 82f8a88e28..07676c21ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.16.0" +version = "2.17.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.16.0" +version = "2.17.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From b8bc9522a60149f744835da7b347c9397f9edf71 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 8 Apr 2021 17:59:33 +0800 Subject: [PATCH 0034/1588] fix(commands/init): fix toml config format error #367 --- commitizen/config/toml_config.py | 16 +++++++++++++--- tests/commands/test_init_command.py | 1 + tests/test_conf.py | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index 1950cb11d1..284e8d41b5 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -1,7 +1,8 @@ +import os from pathlib import Path from typing import Union -from tomlkit import exceptions, parse +from tomlkit import exceptions, parse, table from .base_config import BaseConfig @@ -14,8 +15,17 @@ def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): self.add_path(path) def init_empty_config_content(self): - with open(self.path, "a") as toml_file: - toml_file.write("[tool.commitizen]") + if os.path.isfile(self.path): + with open(self.path, "rb") as input_toml_file: + parser = parse(input_toml_file.read()) + else: + parser = parse("") + + with open(self.path, "wb") as output_toml_file: + if parser.get("tool") is None: + parser["tool"] = table() + parser["tool"]["commitizen"] = table() + output_toml_file.write(parser.as_string().encode("utf-8")) def set_key(self, key, value): """Set or update a key in the conf. diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 729950fc8a..e7f2c00edf 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -25,6 +25,7 @@ def ask(self): } expected_config = ( + "[tool]\n" "[tool.commitizen]\n" 'name = "cz_conventional_commits"\n' 'version = "0.0.1"\n' diff --git a/tests/test_conf.py b/tests/test_conf.py index ea7b3a3c98..f05603cfe4 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -132,7 +132,7 @@ def test_init_empty_config_content(self, tmpdir): toml_config.init_empty_config_content() with open(path, "r") as toml_file: - assert toml_file.read() == "[tool.commitizen]" + assert toml_file.read() == "[tool]\n[tool.commitizen]\n" def test_init_empty_config_content_with_existing_content(self, tmpdir): existing_content = "[tool.black]\n" "line-length = 88\n" @@ -143,7 +143,7 @@ def test_init_empty_config_content_with_existing_content(self, tmpdir): toml_config.init_empty_config_content() with open(path, "r") as toml_file: - assert toml_file.read() == existing_content + "[tool.commitizen]" + assert toml_file.read() == existing_content + "\n[tool.commitizen]\n" class TestJsonConfig: From b541addb23cd4b42c78f2c7d22ba48c70763314f Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 8 Apr 2021 10:42:45 +0000 Subject: [PATCH 0035/1588] =?UTF-8?q?bump:=20version=202.17.0=20=E2=86=92?= =?UTF-8?q?=202.17.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 | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 913780b54f..5089b2233c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.1 (2021-04-08) + +### Fix + +- **commands/init**: fix toml config format error + ## v2.17.0 (2021-04-02) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index a6b62ff3b2..1976873631 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.0" +__version__ = "2.17.1" diff --git a/pyproject.toml b/pyproject.toml index 07676c21ea..9430095da0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.0" +version = "2.17.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", From 5b3c9e2fb2289eadfee4f0b12560ff6cf28d8514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Fri, 9 Apr 2021 18:36:01 +0200 Subject: [PATCH 0036/1588] fix(wip): add test for current breaking change --- tests/test_bump_update_version_in_files.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index cadf4af8d2..aebd87996f 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -126,6 +126,18 @@ def test_random_location(random_location_version_file): assert len(re.findall(new_version, data)) == 1 +def test_duplicates_are_change_with_no_regex(random_location_version_file): + old_version = "1.2.3" + new_version = "2.0.0" + location = f"{random_location_version_file}:version" + + bump.update_version_in_files(old_version, new_version, [location]) + with open(random_location_version_file, "r") as f: + data = f.read() + assert len(re.findall(old_version, data)) == 0 + assert len(re.findall(new_version, data)) == 3 + + def test_file_version_inconsistent_error( commitizen_config_file, inconsistent_python_version_file, version_repeated_file ): From f4cbc35fd72c75bf6782daf7066a2f3d5e10019e Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sat, 10 Apr 2021 15:55:26 +0800 Subject: [PATCH 0037/1588] fix(bump): replace all occurances that match regex --- commitizen/bump.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index b91639289f..5e2709255d 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -157,15 +157,17 @@ def update_version_in_files( with open(filepath, "r") as f: version_file = f.read() - match = regex and re.search(regex, version_file, re.MULTILINE) - if match: - left = version_file[: match.end()] - right = version_file[match.end() :] - line_break = _get_line_break_position(right) - middle = right[:line_break] - current_version_found = current_version in middle - right = right[line_break:] - version_file = left + middle.replace(current_version, new_version) + right + if regex: + for match in re.finditer(regex, version_file, re.MULTILINE): + left = version_file[: match.end()] + right = version_file[match.end() :] + line_break = _get_line_break_position(right) + middle = right[:line_break] + current_version_found = current_version in middle + right = right[line_break:] + version_file = ( + left + middle.replace(current_version, new_version) + right + ) if not regex: current_version_regex = _version_to_regex(current_version) From 2b64adf53f3ddcf04258eaa67b6270348a46cd0a Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 10 Apr 2021 08:03:56 +0000 Subject: [PATCH 0038/1588] =?UTF-8?q?bump:=20version=202.17.1=20=E2=86=92?= =?UTF-8?q?=202.17.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 7 +++++++ commitizen/__version__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5089b2233c..84e98ac549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## v2.17.2 (2021-04-10) + +### Fix + +- **bump**: replace all occurances that match regex +- **wip**: add test for current breaking change + ## v2.17.1 (2021-04-08) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 1976873631..4d144b2359 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.1" +__version__ = "2.17.2" diff --git a/pyproject.toml b/pyproject.toml index 9430095da0..9302ba555a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.1" +version = "2.17.2" tag_format = "v$version" version_files = [ "pyproject.toml:version", From 6be8d931a87d0dee8083c9c7b51f939b89033f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Sat, 10 Apr 2021 10:10:00 +0200 Subject: [PATCH 0039/1588] ci: update package version in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9302ba555a..212075517d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.0" +version = "2.17.2" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 127d1b041648a7ba24eadbbf6a4068e2a599b6ca Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Sat, 17 Apr 2021 19:45:37 +0200 Subject: [PATCH 0040/1588] fix: fix multiple versions bumps when version changes the string size --- commitizen/bump.py | 38 ++++++++++++------- tests/test_bump_update_version_in_files.py | 43 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index 5e2709255d..e6c9089bef 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -152,24 +152,15 @@ def update_version_in_files( for location in files: filepath, *regexes = location.split(":") regex = regexes[0] if regexes else None - current_version_found = False with open(filepath, "r") as f: version_file = f.read() if regex: - for match in re.finditer(regex, version_file, re.MULTILINE): - left = version_file[: match.end()] - right = version_file[match.end() :] - line_break = _get_line_break_position(right) - middle = right[:line_break] - current_version_found = current_version in middle - right = right[line_break:] - version_file = ( - left + middle.replace(current_version, new_version) + right - ) - - if not regex: + current_version_found, version_file = _bump_with_regex( + version_file, current_version, new_version, regex + ) + else: current_version_regex = _version_to_regex(current_version) current_version_found = bool(current_version_regex.search(version_file)) version_file = current_version_regex.sub(new_version, version_file) @@ -186,6 +177,27 @@ def update_version_in_files( file.write("".join(version_file)) +def _bump_with_regex(version_file_contents, current_version, new_version, regex): + current_version_found = False + # Bumping versions that change the string length move the offset on the file contents as finditer keeps a + # reference to the initial string that was used and calling search many times would lead in infinite loops + # e.g.: 1.1.9 -> 1.1.20 + offset = 0 + for match in re.finditer(regex, version_file_contents, re.MULTILINE): + left = version_file_contents[: match.end() + offset] + right = version_file_contents[match.end() + offset :] + line_break = _get_line_break_position(right) + middle = right[:line_break] + current_version_found_in_block = current_version in middle + offset += len(new_version) - len(current_version) + current_version_found |= current_version_found_in_block + right = right[line_break:] + version_file_contents = ( + left + middle.replace(current_version, new_version) + right + ) + return current_version_found, version_file_contents + + def _get_line_break_position(text: str) -> int: position = text.find("\n") return max(position, 0) diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index aebd87996f..0e0e8f5c30 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -50,6 +50,9 @@ version = "1.2.3" """ +MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n' * 30 +MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n' * 30 + @pytest.fixture(scope="function") def commitizen_config_file(tmpdir): @@ -86,6 +89,20 @@ def version_repeated_file(tmpdir): return str(tmp_file) +@pytest.fixture(scope="function") +def multiple_versions_increase_string(tmpdir): + tmp_file = tmpdir.join("anyfile") + tmp_file.write(MULTIPLE_VERSIONS_INCREASE_STRING) + return str(tmp_file) + + +@pytest.fixture(scope="function") +def multiple_versions_reduce_string(tmpdir): + tmp_file = tmpdir.join("anyfile") + tmp_file.write(MULTIPLE_VERSIONS_REDUCE_STRING) + return str(tmp_file) + + @pytest.fixture(scope="function") def version_files(commitizen_config_file, python_version_file, version_repeated_file): return [commitizen_config_file, python_version_file, version_repeated_file] @@ -138,6 +155,32 @@ def test_duplicates_are_change_with_no_regex(random_location_version_file): assert len(re.findall(new_version, data)) == 3 +def test_version_bump_increase_string_length(multiple_versions_increase_string): + old_version = "1.2.9" + new_version = "1.2.10" + version_bump_change_string_size( + multiple_versions_increase_string, old_version, new_version + ) + + +def test_version_bump_reduce_string_length(multiple_versions_reduce_string): + old_version = "1.2.10" + new_version = "2.0.0" + version_bump_change_string_size( + multiple_versions_reduce_string, old_version, new_version + ) + + +def version_bump_change_string_size(filename, old_version, new_version): + location = f"{filename}:version" + + bump.update_version_in_files(old_version, new_version, [location]) + with open(filename, "r") as f: + data = f.read() + assert len(re.findall(old_version, data)) == 0 + assert len(re.findall(new_version, data)) == 30 + + def test_file_version_inconsistent_error( commitizen_config_file, inconsistent_python_version_file, version_repeated_file ): From 8a354571319b02bf2be42a0ee648d0f925c8d58f Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 19 Apr 2021 00:51:27 +0000 Subject: [PATCH 0041/1588] =?UTF-8?q?bump:=20version=202.17.2=20=E2=86=92?= =?UTF-8?q?=202.17.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 84e98ac549..e83f1770fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.3 (2021-04-19) + +### Fix + +- fix multiple versions bumps when version changes the string size + ## v2.17.2 (2021-04-10) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 4d144b2359..58f5db05c9 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.2" +__version__ = "2.17.3" diff --git a/pyproject.toml b/pyproject.toml index 212075517d..11a9543f97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.2" +version = "2.17.3" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.2" +version = "2.17.3" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 8638512bfc5018d07a90851889b30a99bb9007ce Mon Sep 17 00:00:00 2001 From: Peter Slump Date: Thu, 22 Apr 2021 13:39:37 +0200 Subject: [PATCH 0042/1588] fix: version update in a docker-compose.yaml file --- commitizen/bump.py | 2 +- tests/test_bump_update_version_in_files.py | 30 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index e6c9089bef..3a93575941 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -205,7 +205,7 @@ def _get_line_break_position(text: str) -> int: def _version_to_regex(version: str): clean_regex = version.replace(".", r"\.").replace("+", r"\+") - return re.compile(f"\\b{clean_regex}\\b") + return re.compile(f"{clean_regex}") def create_tag(version: Union[Version, str], tag_format: Optional[str] = None): diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 0e0e8f5c30..4b0cf19a44 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -50,6 +50,15 @@ version = "1.2.3" """ +DOCKER_COMPOSE = """ +version: "3.3" + +services: + app: + image: my-repo/my-container:v1.2.3 + command: my-command +""" + MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n' * 30 MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n' * 30 @@ -104,8 +113,25 @@ def multiple_versions_reduce_string(tmpdir): @pytest.fixture(scope="function") -def version_files(commitizen_config_file, python_version_file, version_repeated_file): - return [commitizen_config_file, python_version_file, version_repeated_file] +def docker_compose_file(tmpdir): + tmp_file = tmpdir.join("docker-compose.yaml") + tmp_file.write(DOCKER_COMPOSE) + return str(tmp_file) + + +@pytest.fixture(scope="function") +def version_files( + commitizen_config_file, + python_version_file, + version_repeated_file, + docker_compose_file, +): + return [ + commitizen_config_file, + python_version_file, + version_repeated_file, + docker_compose_file, + ] def test_update_version_in_files(version_files): From ba94e3f90e2df2a80c9946968e1ff15696584b79 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 22 Apr 2021 12:02:06 +0000 Subject: [PATCH 0043/1588] =?UTF-8?q?bump:=20version=202.17.3=20=E2=86=92?= =?UTF-8?q?=202.17.4?= 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 e83f1770fd..e993ab1142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.4 (2021-04-22) + +### Fix + +- version update in a docker-compose.yaml file + ## v2.17.3 (2021-04-19) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 58f5db05c9..de06464cf1 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.3" +__version__ = "2.17.4" diff --git a/pyproject.toml b/pyproject.toml index 11a9543f97..fff7f46898 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.3" +version = "2.17.4" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.3" +version = "2.17.4" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From ff45677bad756270aa5b18501b8a980d1b0e871a Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 6 May 2021 03:39:30 +0800 Subject: [PATCH 0044/1588] fix docs typo --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 41a5615d6c..f5dd5fd5e3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,7 +88,7 @@ By introducing `unreleased_version` you can prevent this situation. Before bumping you can run: ```bash -cz changelog --unreleased_version="v1.0.0" +cz changelog --unreleased-version="v1.0.0" ``` Remember to use the tag instead of the raw version number From 6082b647e1f6c1e94d03f75e66247a54ab93630c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 6 May 2021 01:48:47 +0000 Subject: [PATCH 0045/1588] =?UTF-8?q?bump:=20version=202.17.4=20=E2=86=92?= =?UTF-8?q?=202.17.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e993ab1142..33e4c7d403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ +## v2.17.5 (2021-05-06) + ## v2.17.4 (2021-04-22) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index de06464cf1..b33b8dc03b 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.4" +__version__ = "2.17.5" diff --git a/pyproject.toml b/pyproject.toml index fff7f46898..9922259f89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.4" +version = "2.17.5" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.4" +version = "2.17.5" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 881ad02adb1945b03306aa1f2339f98d5d977714 Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 10:27:08 +0200 Subject: [PATCH 0046/1588] fix(cz/conventional_commits): optionally expect '!' right before ':' in schema_pattern Closes: #381 --- commitizen/cz/conventional_commits/conventional_commits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 7d5c27570c..6ac62d5ec1 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -178,8 +178,8 @@ def schema(self) -> str: def schema_pattern(self) -> str: PATTERN = ( - r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)!?" - r"(\(\S+\))?:(\s.*)" + r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" + r"(\(\S+\))?!?:(\s.*)" ) return PATTERN From ba58b22e1f44b9a953dc12fd2132535b35f7568c Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 11:02:26 +0200 Subject: [PATCH 0047/1588] test(cz/conventional_commits): test check command and process_commit with conventional commits --- tests/commands/test_check_command.py | 12 ++++++++++-- tests/test_cz_conventional_commits.py | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index df54c1234e..7377a8a388 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -124,12 +124,19 @@ def test_check_conventional_commit_succeeds(mocker, capsys): assert "Commit validation: successful!" in out -def test_check_no_conventional_commit(config, mocker, tmpdir): +@pytest.mark.parametrize( + "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): error_mock = mocker.patch("commitizen.out.error") tempfile = tmpdir.join("temp_commit_file") - tempfile.write("no conventional commit") + tempfile.write(commit_msg) check_cmd = commands.Check( config=config, arguments={"commit_msg_file": tempfile} @@ -141,6 +148,7 @@ def test_check_no_conventional_commit(config, mocker, tmpdir): @pytest.mark.parametrize( "commit_msg", ( + "feat(lang)!: removed polish language", "feat(lang): added polish language", "feat: add polish language", "bump: 0.0.1 -> 1.0.0", diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 62eef11a19..2a239cafee 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -132,7 +132,23 @@ def test_info(config): assert isinstance(info, str) -def test_process_commit(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", + "", + ), + ] +) +def test_process_commit(commit_message, expected_message, config): conventional_commits = ConventionalCommitsCz(config) - message = conventional_commits.process_commit("test(test_scope): this is test msg") - assert message == "this is test msg" + message = conventional_commits.process_commit(commit_message) + assert message == expected_message From e1074115a1eae62326f5e998ed52692b956f8163 Mon Sep 17 00:00:00 2001 From: Sonny V Date: Thu, 6 May 2021 11:03:38 +0200 Subject: [PATCH 0048/1588] style(tests): format tests --- tests/commands/test_check_command.py | 6 +----- tests/test_cz_conventional_commits.py | 20 ++++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index 7377a8a388..ac545e3a6a 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -125,11 +125,7 @@ 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_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 2a239cafee..e43284a121 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -132,21 +132,13 @@ def test_info(config): assert isinstance(info, str) -@pytest.mark.parametrize(("commit_message", "expected_message"), +@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): conventional_commits = ConventionalCommitsCz(config) From aa0debe9ae5939afb54de5f26c7f0c395894e330 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 6 May 2021 09:21:16 +0000 Subject: [PATCH 0049/1588] =?UTF-8?q?bump:=20version=202.17.5=20=E2=86=92?= =?UTF-8?q?=202.17.6?= 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 33e4c7d403..167c010b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.6 (2021-05-06) + +### Fix + +- **cz/conventional_commits**: optionally expect '!' right before ':' in schema_pattern + ## v2.17.5 (2021-05-06) ## v2.17.4 (2021-04-22) diff --git a/commitizen/__version__.py b/commitizen/__version__.py index b33b8dc03b..a4d4630238 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.5" +__version__ = "2.17.6" diff --git a/pyproject.toml b/pyproject.toml index 9922259f89..ee8a8622bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.5" +version = "2.17.6" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.5" +version = "2.17.6" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From b7741290513eb97c9f3fd031942f319b985a6364 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 25 May 2021 19:33:47 +0800 Subject: [PATCH 0050/1588] test(bump): add test cast that fails to bump correctly #383 --- tests/test_bump_update_version_in_files.py | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 4b0cf19a44..5d022db50d 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -59,6 +59,36 @@ command: my-command """ +MULTIPLE_VERSIONS_TO_UPDATE_POETRY_LOCK = """ +[[package]] +name = "to-update-1" +version = "1.2.9" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.9" +""" + MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n' * 30 MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n' * 30 @@ -119,6 +149,13 @@ def docker_compose_file(tmpdir): return str(tmp_file) +@pytest.fixture(scope="function") +def multiple_versions_to_update_poetry_lock(tmpdir): + tmp_file = tmpdir.join("pyproject.toml") + tmp_file.write(MULTIPLE_VERSIONS_TO_UPDATE_POETRY_LOCK) + return str(tmp_file) + + @pytest.fixture(scope="function") def version_files( commitizen_config_file, @@ -228,3 +265,15 @@ def test_file_version_inconsistent_error( "version_files are possibly inconsistent." ) assert expected_msg in str(excinfo.value) + + +def test_multiplt_versions_to_bump(multiple_versions_to_update_poetry_lock): + old_version = "1.2.9" + new_version = "1.2.10" + location = f"{multiple_versions_to_update_poetry_lock}:version" + + bump.update_version_in_files(old_version, new_version, [location]) + with open(multiple_versions_to_update_poetry_lock, "r") as f: + data = f.read() + assert len(re.findall(old_version, data)) == 0 + assert len(re.findall(new_version, data)) == 2 From 20d0629a84f54c9f66ef882b230a4e24e3cc5f30 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 25 May 2021 19:40:15 +0800 Subject: [PATCH 0051/1588] fix(bump): fix offset error due to partially match for examply, if what we want to bump is "version = 1.2.9", we still lookup up "version = 2.0.0" and changed the offset this is fixed by changing offset only when matching is found #383 --- commitizen/bump.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index 3a93575941..a4714322e0 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -188,13 +188,13 @@ def _bump_with_regex(version_file_contents, current_version, new_version, regex) right = version_file_contents[match.end() + offset :] line_break = _get_line_break_position(right) middle = right[:line_break] - current_version_found_in_block = current_version in middle - offset += len(new_version) - len(current_version) - current_version_found |= current_version_found_in_block - right = right[line_break:] - version_file_contents = ( - left + middle.replace(current_version, new_version) + right - ) + if current_version in middle: + offset += len(new_version) - len(current_version) + current_version_found = True + right = right[line_break:] + version_file_contents = ( + left + middle.replace(current_version, new_version) + right + ) return current_version_found, version_file_contents From 45b3566dfd33be08ed5dd76dcb130c7c71529ba1 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 25 May 2021 19:44:43 +0800 Subject: [PATCH 0052/1588] build(poetry): add pytest-regression as dev dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index ee8a8622bb..b344305706 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ isort = "^5.7.0" freezegun = "^0.3.15" pydocstyle = "^5.0.2" pre-commit = "^2.6.0" +pytest-regressions = "^2.2.0" [tool.poetry.scripts] cz = "commitizen.cli:main" From 39872992b9b47cbad4e7b1daac7f1ff4bb804b76 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 25 May 2021 19:45:08 +0800 Subject: [PATCH 0053/1588] test(bump): refactor test_multiplt_versions_to_bump through file_regression --- tests/test_bump_update_version_in_files.py | 8 +++--- .../test_multiplt_versions_to_bump.toml | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 5d022db50d..0daa2ecb22 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -267,13 +267,13 @@ def test_file_version_inconsistent_error( assert expected_msg in str(excinfo.value) -def test_multiplt_versions_to_bump(multiple_versions_to_update_poetry_lock): +def test_multiplt_versions_to_bump( + multiple_versions_to_update_poetry_lock, file_regression +): old_version = "1.2.9" new_version = "1.2.10" location = f"{multiple_versions_to_update_poetry_lock}:version" bump.update_version_in_files(old_version, new_version, [location]) with open(multiple_versions_to_update_poetry_lock, "r") as f: - data = f.read() - assert len(re.findall(old_version, data)) == 0 - assert len(re.findall(new_version, data)) == 2 + file_regression.check(f.read(), extension=".toml") diff --git a/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml new file mode 100644 index 0000000000..d5e8bf082f --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml @@ -0,0 +1,28 @@ + +[[package]] +name = "to-update-1" +version = "1.2.10" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.10" From a36063b3e8756b7ff2248b1487d4889e7024a840 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 25 May 2021 23:11:33 +0800 Subject: [PATCH 0054/1588] style(config): ignore TomlConfig._parse_setting type annotation --- commitizen/config/toml_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index 284e8d41b5..b5b7f7b2a1 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -49,8 +49,8 @@ def _parse_setting(self, data: Union[bytes, str]): name = "cz_conventional_commits" ``` """ - doc = parse(data) + doc = parse(data) # type: ignore try: - self.settings.update(doc["tool"]["commitizen"]) + self.settings.update(doc["tool"]["commitizen"]) # type: ignore except exceptions.NonExistentKey: self.is_empty_config = True From dcb18bbf71e35312aa5e0e64295b1fc2b3a0008a Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 26 May 2021 15:49:30 +0800 Subject: [PATCH 0055/1588] test(bump_update_verison_in_files): refactor test cases through pytest-regression --- .pre-commit-config.yaml | 1 + commitizen/bump.py | 2 +- tests/test_bump_update_version_in_files.py | 163 +++++------------- ...t_duplicates_are_change_with_no_regex.lock | 11 ++ .../test_multiplt_versions_to_bump.toml | 1 - .../test_partial_update_of_file.json | 7 + .../test_random_location.lock | 11 ++ .../test_update_version_in_files.txt | 20 +++ ...st_version_bump_increase_string_length.txt | 30 ++++ ...test_version_bump_reduce_string_length.txt | 30 ++++ .../inconsistent_version.py | 4 + ...multiple_versions_to_update_pyproject.toml | 27 +++ .../repeated_version_number.json | 7 + tests/testing_version_files/sample_cargo.lock | 11 ++ .../sample_docker_compose.yaml | 6 + .../sample_pyproject.toml | 3 + tests/testing_version_files/sample_version.py | 4 + 17 files changed, 213 insertions(+), 125 deletions(-) create mode 100644 tests/test_bump_update_version_in_files/test_duplicates_are_change_with_no_regex.lock create mode 100644 tests/test_bump_update_version_in_files/test_partial_update_of_file.json create mode 100644 tests/test_bump_update_version_in_files/test_random_location.lock create mode 100644 tests/test_bump_update_version_in_files/test_update_version_in_files.txt create mode 100644 tests/test_bump_update_version_in_files/test_version_bump_increase_string_length.txt create mode 100644 tests/test_bump_update_version_in_files/test_version_bump_reduce_string_length.txt create mode 100644 tests/testing_version_files/inconsistent_version.py create mode 100644 tests/testing_version_files/multiple_versions_to_update_pyproject.toml create mode 100644 tests/testing_version_files/repeated_version_number.json create mode 100644 tests/testing_version_files/sample_cargo.lock create mode 100644 tests/testing_version_files/sample_docker_compose.yaml create mode 100644 tests/testing_version_files/sample_pyproject.toml create mode 100644 tests/testing_version_files/sample_version.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 36bbcfb646..6ecfdc2041 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: hooks: - id: check-vcs-permalinks - id: end-of-file-fixer + exclude: "tests/test_*/*" - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - id: debug-statements diff --git a/commitizen/bump.py b/commitizen/bump.py index a4714322e0..c4fbadc07c 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -188,10 +188,10 @@ def _bump_with_regex(version_file_contents, current_version, new_version, regex) right = version_file_contents[match.end() + offset :] line_break = _get_line_break_position(right) middle = right[:line_break] + right = right[line_break:] if current_version in middle: offset += len(new_version) - len(current_version) current_version_found = True - right = right[line_break:] version_file_contents = ( left + middle.replace(current_version, new_version) + right ) diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 0daa2ecb22..55189da030 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -1,130 +1,48 @@ -import re +from shutil import copyfile import pytest from commitizen import bump from commitizen.exceptions import CurrentVersionNotFoundError -PYPROJECT = """ -[tool.poetry] -name = "commitizen" -version = "1.2.3" -""" - -VERSION_PY = """ -__title__ = 'requests' -__description__ = 'Python HTTP for Humans.' -__url__ = 'http://python-requests.org' -__version__ = '1.2.3' -""" - -INCONSISTENT_VERSION_PY = """ -__title__ = 'requests' -__description__ = 'Python HTTP for Humans.' -__url__ = 'http://python-requests.org' -__version__ = '2.10.3' -""" - -REPEATED_VERSION_NUMBER = """ -{ - "name": "magictool", - "version": "1.2.3", - "dependencies": { - "lodash": "1.2.3" - } -} -""" - -# The order cannot be guaranteed here -CARGO_LOCK = """ -[[package]] -name = "textwrap" -version = "1.2.3" - -[[package]] -name = "there-i-fixed-it" -version = "1.2.3" - -[[package]] -name = "other-project" -version = "1.2.3" -""" - -DOCKER_COMPOSE = """ -version: "3.3" - -services: - app: - image: my-repo/my-container:v1.2.3 - command: my-command -""" - -MULTIPLE_VERSIONS_TO_UPDATE_POETRY_LOCK = """ -[[package]] -name = "to-update-1" -version = "1.2.9" - -[[package]] -name = "not-to-update" -version = "1.3.3" - -[[package]] -name = "not-to-update" -version = "1.3.3" - -[[package]] -name = "not-to-update" -version = "1.3.3" - -[[package]] -name = "not-to-update" -version = "1.3.3" - -[[package]] -name = "not-to-update" -version = "1.3.3" - -[[package]] -name = "to-update-2" -version = "1.2.9" -""" - MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n' * 30 MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n' * 30 +TESTING_FILE_PREFIX = "tests/testing_version_files" + @pytest.fixture(scope="function") def commitizen_config_file(tmpdir): tmp_file = tmpdir.join("pyproject.toml") - tmp_file.write(PYPROJECT) + copyfile(f"{TESTING_FILE_PREFIX}/sample_pyproject.toml", str(tmp_file)) return str(tmp_file) @pytest.fixture(scope="function") def python_version_file(tmpdir): tmp_file = tmpdir.join("__verion__.py") - tmp_file.write(VERSION_PY) + copyfile(f"{TESTING_FILE_PREFIX}/sample_version.py", str(tmp_file)) return str(tmp_file) @pytest.fixture(scope="function") def inconsistent_python_version_file(tmpdir): tmp_file = tmpdir.join("__verion__.py") - tmp_file.write(INCONSISTENT_VERSION_PY) + copyfile(f"{TESTING_FILE_PREFIX}/inconsistent_version.py", str(tmp_file)) return str(tmp_file) @pytest.fixture(scope="function") def random_location_version_file(tmpdir): tmp_file = tmpdir.join("Cargo.lock") - tmp_file.write(CARGO_LOCK) + copyfile(f"{TESTING_FILE_PREFIX}/sample_cargo.lock", str(tmp_file)) return str(tmp_file) @pytest.fixture(scope="function") def version_repeated_file(tmpdir): tmp_file = tmpdir.join("package.json") - tmp_file.write(REPEATED_VERSION_NUMBER) + copyfile(f"{TESTING_FILE_PREFIX}/repeated_version_number.json", str(tmp_file)) return str(tmp_file) @@ -145,14 +63,17 @@ def multiple_versions_reduce_string(tmpdir): @pytest.fixture(scope="function") def docker_compose_file(tmpdir): tmp_file = tmpdir.join("docker-compose.yaml") - tmp_file.write(DOCKER_COMPOSE) + copyfile(f"{TESTING_FILE_PREFIX}/sample_docker_compose.yaml", str(tmp_file)) return str(tmp_file) @pytest.fixture(scope="function") def multiple_versions_to_update_poetry_lock(tmpdir): tmp_file = tmpdir.join("pyproject.toml") - tmp_file.write(MULTIPLE_VERSIONS_TO_UPDATE_POETRY_LOCK) + copyfile( + f"{TESTING_FILE_PREFIX}/multiple_versions_to_update_pyproject.toml", + str(tmp_file), + ) return str(tmp_file) @@ -171,17 +92,19 @@ def version_files( ] -def test_update_version_in_files(version_files): +def test_update_version_in_files(version_files, file_regression): old_version = "1.2.3" new_version = "2.0.0" bump.update_version_in_files(old_version, new_version, version_files) + + file_contents = "" for filepath in version_files: with open(filepath, "r") as f: - data = f.read() - assert new_version in data + file_contents += f.read() + file_regression.check(file_contents, extension=".txt") -def test_partial_update_of_file(version_repeated_file): +def test_partial_update_of_file(version_repeated_file, file_regression): old_version = "1.2.3" new_version = "2.0.0" regex = "version" @@ -189,59 +112,53 @@ def test_partial_update_of_file(version_repeated_file): bump.update_version_in_files(old_version, new_version, [location]) with open(version_repeated_file, "r") as f: - data = f.read() - assert new_version in data - assert old_version in data + file_regression.check(f.read(), extension=".json") -def test_random_location(random_location_version_file): +def test_random_location(random_location_version_file, file_regression): old_version = "1.2.3" new_version = "2.0.0" location = f"{random_location_version_file}:there-i-fixed-it.+\nversion" bump.update_version_in_files(old_version, new_version, [location]) with open(random_location_version_file, "r") as f: - data = f.read() - assert len(re.findall(old_version, data)) == 2 - assert len(re.findall(new_version, data)) == 1 + file_regression.check(f.read(), extension=".lock") -def test_duplicates_are_change_with_no_regex(random_location_version_file): +def test_duplicates_are_change_with_no_regex( + random_location_version_file, file_regression +): old_version = "1.2.3" new_version = "2.0.0" location = f"{random_location_version_file}:version" bump.update_version_in_files(old_version, new_version, [location]) with open(random_location_version_file, "r") as f: - data = f.read() - assert len(re.findall(old_version, data)) == 0 - assert len(re.findall(new_version, data)) == 3 + file_regression.check(f.read(), extension=".lock") -def test_version_bump_increase_string_length(multiple_versions_increase_string): +def test_version_bump_increase_string_length( + multiple_versions_increase_string, file_regression +): old_version = "1.2.9" new_version = "1.2.10" - version_bump_change_string_size( - multiple_versions_increase_string, old_version, new_version - ) + location = f"{multiple_versions_increase_string}:version" + + bump.update_version_in_files(old_version, new_version, [location]) + with open(multiple_versions_increase_string, "r") as f: + file_regression.check(f.read(), extension=".txt") -def test_version_bump_reduce_string_length(multiple_versions_reduce_string): +def test_version_bump_reduce_string_length( + multiple_versions_reduce_string, file_regression +): old_version = "1.2.10" new_version = "2.0.0" - version_bump_change_string_size( - multiple_versions_reduce_string, old_version, new_version - ) - - -def version_bump_change_string_size(filename, old_version, new_version): - location = f"{filename}:version" + location = f"{multiple_versions_reduce_string}:version" bump.update_version_in_files(old_version, new_version, [location]) - with open(filename, "r") as f: - data = f.read() - assert len(re.findall(old_version, data)) == 0 - assert len(re.findall(new_version, data)) == 30 + with open(multiple_versions_reduce_string, "r") as f: + file_regression.check(f.read(), extension=".txt") def test_file_version_inconsistent_error( diff --git a/tests/test_bump_update_version_in_files/test_duplicates_are_change_with_no_regex.lock b/tests/test_bump_update_version_in_files/test_duplicates_are_change_with_no_regex.lock new file mode 100644 index 0000000000..eed8f4c79d --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_duplicates_are_change_with_no_regex.lock @@ -0,0 +1,11 @@ +[[package]] +name = "textwrap" +version = "2.0.0" + +[[package]] +name = "there-i-fixed-it" +version = "2.0.0" + +[[package]] +name = "other-project" +version = "2.0.0" diff --git a/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml index d5e8bf082f..f279eb4d61 100644 --- a/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml +++ b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml @@ -1,4 +1,3 @@ - [[package]] name = "to-update-1" version = "1.2.10" diff --git a/tests/test_bump_update_version_in_files/test_partial_update_of_file.json b/tests/test_bump_update_version_in_files/test_partial_update_of_file.json new file mode 100644 index 0000000000..59224bca04 --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_partial_update_of_file.json @@ -0,0 +1,7 @@ +{ + "name": "magictool", + "version": "2.0.0", + "dependencies": { + "lodash": "1.2.3" + } +} diff --git a/tests/test_bump_update_version_in_files/test_random_location.lock b/tests/test_bump_update_version_in_files/test_random_location.lock new file mode 100644 index 0000000000..94422116aa --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_random_location.lock @@ -0,0 +1,11 @@ +[[package]] +name = "textwrap" +version = "1.2.3" + +[[package]] +name = "there-i-fixed-it" +version = "2.0.0" + +[[package]] +name = "other-project" +version = "1.2.3" diff --git a/tests/test_bump_update_version_in_files/test_update_version_in_files.txt b/tests/test_bump_update_version_in_files/test_update_version_in_files.txt new file mode 100644 index 0000000000..c4e527ac47 --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_update_version_in_files.txt @@ -0,0 +1,20 @@ +[tool.poetry] +name = "commitizen" +version = "2.0.0" +__title__ = "requests" +__description__ = "Python HTTP for Humans." +__url__ = "http://python-requests.org" +__version__ = "2.0.0" +{ + "name": "magictool", + "version": "2.0.0", + "dependencies": { + "lodash": "2.0.0" + } +} +version: "3.3" + +services: + app: + image: my-repo/my-container:v2.0.0 + command: my-command diff --git a/tests/test_bump_update_version_in_files/test_version_bump_increase_string_length.txt b/tests/test_bump_update_version_in_files/test_version_bump_increase_string_length.txt new file mode 100644 index 0000000000..4b6d6d64be --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_version_bump_increase_string_length.txt @@ -0,0 +1,30 @@ +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" +version = "1.2.10" diff --git a/tests/test_bump_update_version_in_files/test_version_bump_reduce_string_length.txt b/tests/test_bump_update_version_in_files/test_version_bump_reduce_string_length.txt new file mode 100644 index 0000000000..8e619de1ab --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_version_bump_reduce_string_length.txt @@ -0,0 +1,30 @@ +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" +version = "2.0.0" diff --git a/tests/testing_version_files/inconsistent_version.py b/tests/testing_version_files/inconsistent_version.py new file mode 100644 index 0000000000..47646762dc --- /dev/null +++ b/tests/testing_version_files/inconsistent_version.py @@ -0,0 +1,4 @@ +__title__ = "requests" +__description__ = "Python HTTP for Humans." +__url__ = "http://python-requests.org" +__version__ = "2.10.3" diff --git a/tests/testing_version_files/multiple_versions_to_update_pyproject.toml b/tests/testing_version_files/multiple_versions_to_update_pyproject.toml new file mode 100644 index 0000000000..de4ead0343 --- /dev/null +++ b/tests/testing_version_files/multiple_versions_to_update_pyproject.toml @@ -0,0 +1,27 @@ +[[package]] +name = "to-update-1" +version = "1.2.9" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.9" diff --git a/tests/testing_version_files/repeated_version_number.json b/tests/testing_version_files/repeated_version_number.json new file mode 100644 index 0000000000..8421026df9 --- /dev/null +++ b/tests/testing_version_files/repeated_version_number.json @@ -0,0 +1,7 @@ +{ + "name": "magictool", + "version": "1.2.3", + "dependencies": { + "lodash": "1.2.3" + } +} diff --git a/tests/testing_version_files/sample_cargo.lock b/tests/testing_version_files/sample_cargo.lock new file mode 100644 index 0000000000..a3a0b1bb7a --- /dev/null +++ b/tests/testing_version_files/sample_cargo.lock @@ -0,0 +1,11 @@ +[[package]] +name = "textwrap" +version = "1.2.3" + +[[package]] +name = "there-i-fixed-it" +version = "1.2.3" + +[[package]] +name = "other-project" +version = "1.2.3" diff --git a/tests/testing_version_files/sample_docker_compose.yaml b/tests/testing_version_files/sample_docker_compose.yaml new file mode 100644 index 0000000000..9da8caf1f6 --- /dev/null +++ b/tests/testing_version_files/sample_docker_compose.yaml @@ -0,0 +1,6 @@ +version: "3.3" + +services: + app: + image: my-repo/my-container:v1.2.3 + command: my-command diff --git a/tests/testing_version_files/sample_pyproject.toml b/tests/testing_version_files/sample_pyproject.toml new file mode 100644 index 0000000000..9f50155cb7 --- /dev/null +++ b/tests/testing_version_files/sample_pyproject.toml @@ -0,0 +1,3 @@ +[tool.poetry] +name = "commitizen" +version = "1.2.3" diff --git a/tests/testing_version_files/sample_version.py b/tests/testing_version_files/sample_version.py new file mode 100644 index 0000000000..4dd4512dba --- /dev/null +++ b/tests/testing_version_files/sample_version.py @@ -0,0 +1,4 @@ +__title__ = "requests" +__description__ = "Python HTTP for Humans." +__url__ = "http://python-requests.org" +__version__ = "1.2.3" From fde3b72096d6d53e45c65723ac752015029948b9 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 26 May 2021 17:24:50 +0800 Subject: [PATCH 0056/1588] test(bump): add test case that fails when using regex with version file without end of line if we bump with version file with no end of line through regex, the last version will be ignored --- .pre-commit-config.yaml | 2 +- .../inconsistent_version.py | 0 ...multiple_versions_to_update_pyproject.toml | 0 ...e_versions_to_update_pyproject_wo_eol.toml | 27 +++++++++++++++++++ .../repeated_version_number.json | 0 .../sample_cargo.lock | 0 .../sample_docker_compose.yaml | 0 .../sample_pyproject.toml | 0 .../sample_version.py | 0 tests/test_bump_update_version_in_files.py | 18 ++++++++----- ..._multiplt_versions_to_bump_with_eol_.toml} | 0 ...ultiplt_versions_to_bump_without_eol_.toml | 27 +++++++++++++++++++ 12 files changed, 67 insertions(+), 7 deletions(-) rename tests/{testing_version_files => data}/inconsistent_version.py (100%) rename tests/{testing_version_files => data}/multiple_versions_to_update_pyproject.toml (100%) create mode 100644 tests/data/multiple_versions_to_update_pyproject_wo_eol.toml rename tests/{testing_version_files => data}/repeated_version_number.json (100%) rename tests/{testing_version_files => data}/sample_cargo.lock (100%) rename tests/{testing_version_files => data}/sample_docker_compose.yaml (100%) rename tests/{testing_version_files => data}/sample_pyproject.toml (100%) rename tests/{testing_version_files => data}/sample_version.py (100%) rename tests/test_bump_update_version_in_files/{test_multiplt_versions_to_bump.toml => test_multiplt_versions_to_bump_with_eol_.toml} (100%) create mode 100644 tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_without_eol_.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ecfdc2041..a5c2d68036 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: hooks: - id: check-vcs-permalinks - id: end-of-file-fixer - exclude: "tests/test_*/*" + exclude: "tests/[test_*|data]/*" - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - id: debug-statements diff --git a/tests/testing_version_files/inconsistent_version.py b/tests/data/inconsistent_version.py similarity index 100% rename from tests/testing_version_files/inconsistent_version.py rename to tests/data/inconsistent_version.py diff --git a/tests/testing_version_files/multiple_versions_to_update_pyproject.toml b/tests/data/multiple_versions_to_update_pyproject.toml similarity index 100% rename from tests/testing_version_files/multiple_versions_to_update_pyproject.toml rename to tests/data/multiple_versions_to_update_pyproject.toml diff --git a/tests/data/multiple_versions_to_update_pyproject_wo_eol.toml b/tests/data/multiple_versions_to_update_pyproject_wo_eol.toml new file mode 100644 index 0000000000..e2746fa9eb --- /dev/null +++ b/tests/data/multiple_versions_to_update_pyproject_wo_eol.toml @@ -0,0 +1,27 @@ +[[package]] +name = "to-update-1" +version = "1.2.9" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.9" \ No newline at end of file diff --git a/tests/testing_version_files/repeated_version_number.json b/tests/data/repeated_version_number.json similarity index 100% rename from tests/testing_version_files/repeated_version_number.json rename to tests/data/repeated_version_number.json diff --git a/tests/testing_version_files/sample_cargo.lock b/tests/data/sample_cargo.lock similarity index 100% rename from tests/testing_version_files/sample_cargo.lock rename to tests/data/sample_cargo.lock diff --git a/tests/testing_version_files/sample_docker_compose.yaml b/tests/data/sample_docker_compose.yaml similarity index 100% rename from tests/testing_version_files/sample_docker_compose.yaml rename to tests/data/sample_docker_compose.yaml diff --git a/tests/testing_version_files/sample_pyproject.toml b/tests/data/sample_pyproject.toml similarity index 100% rename from tests/testing_version_files/sample_pyproject.toml rename to tests/data/sample_pyproject.toml diff --git a/tests/testing_version_files/sample_version.py b/tests/data/sample_version.py similarity index 100% rename from tests/testing_version_files/sample_version.py rename to tests/data/sample_version.py diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 55189da030..ad1beee774 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -8,7 +8,7 @@ MULTIPLE_VERSIONS_INCREASE_STRING = 'version = "1.2.9"\n' * 30 MULTIPLE_VERSIONS_REDUCE_STRING = 'version = "1.2.10"\n' * 30 -TESTING_FILE_PREFIX = "tests/testing_version_files" +TESTING_FILE_PREFIX = "tests/data" @pytest.fixture(scope="function") @@ -19,7 +19,7 @@ def commitizen_config_file(tmpdir): @pytest.fixture(scope="function") -def python_version_file(tmpdir): +def python_version_file(tmpdir, request): tmp_file = tmpdir.join("__verion__.py") copyfile(f"{TESTING_FILE_PREFIX}/sample_version.py", str(tmp_file)) return str(tmp_file) @@ -67,12 +67,18 @@ def docker_compose_file(tmpdir): return str(tmp_file) -@pytest.fixture(scope="function") -def multiple_versions_to_update_poetry_lock(tmpdir): +@pytest.fixture( + scope="function", + params=( + "multiple_versions_to_update_pyproject.toml", + "multiple_versions_to_update_pyproject_wo_eol.toml", + ), + ids=("with_eol", "without_eol"), +) +def multiple_versions_to_update_poetry_lock(tmpdir, request): tmp_file = tmpdir.join("pyproject.toml") copyfile( - f"{TESTING_FILE_PREFIX}/multiple_versions_to_update_pyproject.toml", - str(tmp_file), + f"{TESTING_FILE_PREFIX}/{request.param}", str(tmp_file), ) return str(tmp_file) diff --git a/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_with_eol_.toml similarity index 100% rename from tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump.toml rename to tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_with_eol_.toml diff --git a/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_without_eol_.toml b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_without_eol_.toml new file mode 100644 index 0000000000..47092b958b --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_multiplt_versions_to_bump_without_eol_.toml @@ -0,0 +1,27 @@ +[[package]] +name = "to-update-1" +version = "1.2.10" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.10" \ No newline at end of file From 76b3030f65ac310a2def731a558763f363cc8af3 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 26 May 2021 17:42:36 +0800 Subject: [PATCH 0057/1588] fix(bump): fix error due to bumping version file without eol through regex --- commitizen/bump.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index c4fbadc07c..9312491044 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -186,9 +186,11 @@ def _bump_with_regex(version_file_contents, current_version, new_version, regex) for match in re.finditer(regex, version_file_contents, re.MULTILINE): left = version_file_contents[: match.end() + offset] right = version_file_contents[match.end() + offset :] - line_break = _get_line_break_position(right) + + line_break = right.find("\n") middle = right[:line_break] right = right[line_break:] + if current_version in middle: offset += len(new_version) - len(current_version) current_version_found = True @@ -198,11 +200,6 @@ def _bump_with_regex(version_file_contents, current_version, new_version, regex) return current_version_found, version_file_contents -def _get_line_break_position(text: str) -> int: - position = text.find("\n") - return max(position, 0) - - def _version_to_regex(version: str): clean_regex = version.replace(".", r"\.").replace("+", r"\+") return re.compile(f"{clean_regex}") From b36594db12d8555a36f83fd42e1c9ea351dfff14 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 26 May 2021 17:58:57 +0800 Subject: [PATCH 0058/1588] test(bump): refactor file loading with extracted utility function --- tests/test_bump_update_version_in_files.py | 77 +++++++++++----------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index ad1beee774..a00286df71 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -1,6 +1,7 @@ from shutil import copyfile import pytest +from py._path.local import LocalPath from commitizen import bump from commitizen.exceptions import CurrentVersionNotFoundError @@ -11,60 +12,50 @@ TESTING_FILE_PREFIX = "tests/data" +def _copy_sample_file_to_tmpdir( + tmpdir: LocalPath, source_filename: str, dest_filename: str +) -> str: + tmp_file = tmpdir.join(dest_filename) + copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file)) + return str(tmp_file) + + @pytest.fixture(scope="function") def commitizen_config_file(tmpdir): - tmp_file = tmpdir.join("pyproject.toml") - copyfile(f"{TESTING_FILE_PREFIX}/sample_pyproject.toml", str(tmp_file)) - return str(tmp_file) + return _copy_sample_file_to_tmpdir( + tmpdir, "sample_pyproject.toml", "pyproject.toml" + ) @pytest.fixture(scope="function") def python_version_file(tmpdir, request): - tmp_file = tmpdir.join("__verion__.py") - copyfile(f"{TESTING_FILE_PREFIX}/sample_version.py", str(tmp_file)) - return str(tmp_file) + return _copy_sample_file_to_tmpdir(tmpdir, "sample_version.py", "__version__.py") @pytest.fixture(scope="function") def inconsistent_python_version_file(tmpdir): - tmp_file = tmpdir.join("__verion__.py") - copyfile(f"{TESTING_FILE_PREFIX}/inconsistent_version.py", str(tmp_file)) - return str(tmp_file) + return _copy_sample_file_to_tmpdir( + tmpdir, "inconsistent_version.py", "__version__.py" + ) @pytest.fixture(scope="function") def random_location_version_file(tmpdir): - tmp_file = tmpdir.join("Cargo.lock") - copyfile(f"{TESTING_FILE_PREFIX}/sample_cargo.lock", str(tmp_file)) - return str(tmp_file) + return _copy_sample_file_to_tmpdir(tmpdir, "sample_cargo.lock", "Cargo.lock") @pytest.fixture(scope="function") def version_repeated_file(tmpdir): - tmp_file = tmpdir.join("package.json") - copyfile(f"{TESTING_FILE_PREFIX}/repeated_version_number.json", str(tmp_file)) - return str(tmp_file) - - -@pytest.fixture(scope="function") -def multiple_versions_increase_string(tmpdir): - tmp_file = tmpdir.join("anyfile") - tmp_file.write(MULTIPLE_VERSIONS_INCREASE_STRING) - return str(tmp_file) - - -@pytest.fixture(scope="function") -def multiple_versions_reduce_string(tmpdir): - tmp_file = tmpdir.join("anyfile") - tmp_file.write(MULTIPLE_VERSIONS_REDUCE_STRING) - return str(tmp_file) + return _copy_sample_file_to_tmpdir( + tmpdir, "repeated_version_number.json", "package.json" + ) @pytest.fixture(scope="function") def docker_compose_file(tmpdir): - tmp_file = tmpdir.join("docker-compose.yaml") - copyfile(f"{TESTING_FILE_PREFIX}/sample_docker_compose.yaml", str(tmp_file)) - return str(tmp_file) + return _copy_sample_file_to_tmpdir( + tmpdir, "sample_docker_compose.yaml", "docker-compose.yaml" + ) @pytest.fixture( @@ -76,10 +67,20 @@ def docker_compose_file(tmpdir): ids=("with_eol", "without_eol"), ) def multiple_versions_to_update_poetry_lock(tmpdir, request): - tmp_file = tmpdir.join("pyproject.toml") - copyfile( - f"{TESTING_FILE_PREFIX}/{request.param}", str(tmp_file), - ) + return _copy_sample_file_to_tmpdir(tmpdir, request.param, "pyproject.toml") + + +@pytest.fixture(scope="function") +def multiple_versions_increase_string(tmpdir): + tmp_file = tmpdir.join("anyfile") + tmp_file.write(MULTIPLE_VERSIONS_INCREASE_STRING) + return str(tmp_file) + + +@pytest.fixture(scope="function") +def multiple_versions_reduce_string(tmpdir): + tmp_file = tmpdir.join("anyfile") + tmp_file.write(MULTIPLE_VERSIONS_REDUCE_STRING) return str(tmp_file) @@ -90,12 +91,12 @@ def version_files( version_repeated_file, docker_compose_file, ): - return [ + return ( commitizen_config_file, python_version_file, version_repeated_file, docker_compose_file, - ] + ) def test_update_version_in_files(version_files, file_regression): From 96078744448023dc01d4816085d63291fb7760a0 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 26 May 2021 18:14:41 +0800 Subject: [PATCH 0059/1588] test(git): add test case for is_staging_clean --- tests/test_git.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_git.py b/tests/test_git.py index 8ba2f64cb8..1fe2b9251a 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -152,3 +152,14 @@ def test_get_latest_tag_name(tmp_commitizen_project): cmd.run("git tag 1.0") tag_name = git.get_latest_tag_name() assert tag_name == "1.0" + + +def test_is_staging_clean(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("echo 'test' > test_file") + + assert git.is_staging_clean() is False From 6192fc389a224db8ded0a52ba4004d479ec752ae Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 26 May 2021 14:12:25 +0000 Subject: [PATCH 0060/1588] =?UTF-8?q?bump:=20version=202.17.6=20=E2=86=92?= =?UTF-8?q?=202.17.7?= 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 167c010b7a..6d1f74f2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## v2.17.7 (2021-05-26) + +### Fix + +- **bump**: fix error due to bumping version file without eol through regex +- **bump**: fix offset error due to partially match + ## v2.17.6 (2021-05-06) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index a4d4630238..36ce2b9412 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.6" +__version__ = "2.17.7" diff --git a/pyproject.toml b/pyproject.toml index b344305706..dadbd30d86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.6" +version = "2.17.7" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.6" +version = "2.17.7" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 72d9dbd7124dff8e6874c85cb8a2d7e9a263dab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Fri, 28 May 2021 10:40:26 +0200 Subject: [PATCH 0061/1588] fix(changelog): annotated tags not generating proper changelog --- commitizen/git.py | 21 ++++++++++-- tests/commands/test_changelog_command.py | 27 ++++++++++++++++ ...p_a_changelog_sample_with_annotated_tag.md | 32 +++++++++++++++++++ tests/test_git.py | 6 ++-- 4 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag.md diff --git a/commitizen/git.py b/commitizen/git.py index b8fbd0715a..a4476de6bb 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -44,6 +44,15 @@ def __init__(self, name, rev, date): def __repr__(self): return f"GitTag('{self.name}', '{self.rev}', '{self.date}')" + @classmethod + def from_line(cls, line: str, inner_delimiter: str) -> "GitTag": + + name, objectname, date, obj = line.split(inner_delimiter) + if not obj: + obj = objectname + + return cls(name=name, rev=obj, date=date) + def tag(tag: str, annotated: bool = False): c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}") @@ -100,13 +109,19 @@ def get_tags(dateformat: str = "%Y-%m-%d") -> List[GitTag]: formatter = ( f'"%(refname:lstrip=2){inner_delimiter}' f"%(objectname){inner_delimiter}" - f'%(committerdate:format:{dateformat})"' + f"%(creatordate:format:{dateformat}){inner_delimiter}" + f'%(object)"' ) - c = cmd.run(f"git tag --format={formatter} --sort=-committerdate") + c = cmd.run(f"git tag --format={formatter} --sort=-creatordate") + if c.err or not c.out: return [] - git_tags = [GitTag(*line.split(inner_delimiter)) for line in c.out.split("\n")[:-1]] + git_tags = [ + GitTag.from_line(line=line, inner_delimiter=inner_delimiter) + for line in c.out.split("\n")[:-1] + ] + return git_tags diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 7448fee320..95e4775aad 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -453,3 +453,30 @@ def test_changelog_config_start_rev_option(mocker, capsys, config_path): out, _ = capsys.readouterr() assert out == "## Unreleased\n\n### Feat\n\n- after 0.2\n- after 0.2.0\n\n" + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( + mocker, capsys, changelog_path, file_regression +): + """Fix #378""" + with open(changelog_path, "w") as f: + f.write(KEEP_A_CHANGELOG) + create_file_and_commit("irrelevant commit") + git.tag("1.0.0", annotated=True) + + create_file_and_commit("feat: add new output") + create_file_and_commit("fix: output glitch") + create_file_and_commit("fix: mama gotta work") + create_file_and_commit("feat: add more stuff") + create_file_and_commit("Merge into master") + + testargs = ["cz", "changelog", "--incremental"] + + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag.md b/tests/commands/test_changelog_command/test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag.md new file mode 100644 index 0000000000..56e2cf81f5 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag.md @@ -0,0 +1,32 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## [1.0.0] - 2017-06-20 +### Added +- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). +- Version navigation. + +### Changed +- Start using "changelog" over "change log" since it's the common usage. + +### Removed +- Section about "changelog" vs "CHANGELOG". + +## [0.3.0] - 2015-12-03 +### Added +- RU translation from [@aishek](https://github.com/aishek). diff --git a/tests/test_git.py b/tests/test_git.py index 1fe2b9251a..03ddcbaa13 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -19,9 +19,9 @@ def test_git_object_eq(): def test_get_tags(mocker): tag_str = ( - "v1.0.0---inner_delimiter---333---inner_delimiter---2020-01-20\n" - "v0.5.0---inner_delimiter---222---inner_delimiter---2020-01-17\n" - "v0.0.1---inner_delimiter---111---inner_delimiter---2020-01-17\n" + "v1.0.0---inner_delimiter---333---inner_delimiter---2020-01-20---inner_delimiter---\n" + "v0.5.0---inner_delimiter---222---inner_delimiter---2020-01-17---inner_delimiter---\n" + "v0.0.1---inner_delimiter---111---inner_delimiter---2020-01-17---inner_delimiter---\n" ) mocker.patch("commitizen.cmd.run", return_value=FakeCommand(out=tag_str)) From 8829441fcf0dffb72e1f65447812f068f8564819 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 28 May 2021 08:54:52 +0000 Subject: [PATCH 0062/1588] =?UTF-8?q?bump:=20version=202.17.7=20=E2=86=92?= =?UTF-8?q?=202.17.8?= 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 6d1f74f2ff..d4c53f528c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.8 (2021-05-28) + +### Fix + +- **changelog**: annotated tags not generating proper changelog + ## v2.17.7 (2021-05-26) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 36ce2b9412..757a1dcbe0 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.7" +__version__ = "2.17.8" diff --git a/pyproject.toml b/pyproject.toml index dadbd30d86..a13c53a733 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.7" +version = "2.17.8" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.7" +version = "2.17.8" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 96265ce7ebe6fc6bd97b113d90ff3b10566392db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Fri, 28 May 2021 11:14:15 +0200 Subject: [PATCH 0063/1588] ci(homebrewpublish): add tag to homebrew formula action --- .github/workflows/homebrewpublish.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/homebrewpublish.yaml b/.github/workflows/homebrewpublish.yaml index 267ba4ec33..817d881794 100644 --- a/.github/workflows/homebrewpublish.yaml +++ b/.github/workflows/homebrewpublish.yaml @@ -13,8 +13,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install -U commitizen + - name: Set Project version env variable + run: | + echo "project_version=$(cz version --project)" >> $GITHUB_ENV - name: Update Homebrew formula uses: dawidd6/action-homebrew-bump-formula@v3 with: token: ${{secrets.PERSONAL_ACCESS_TOKEN}} formula: commitizen + tag: v${{ env.project_version }} From 7eec5a023b81f67dcb978babfe689cec7b2474eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Fri, 11 Jun 2021 12:18:27 +0200 Subject: [PATCH 0064/1588] fix(changelog): generating changelog after a pre-release Closes #357 --- commitizen/defaults.py | 2 +- tests/commands/test_changelog_command.py | 33 +++++++++++++++ ...l_with_release_candidate_version_alpha_.md | 40 +++++++++++++++++++ ...al_with_release_candidate_version_beta_.md | 40 +++++++++++++++++++ ...ntal_with_release_candidate_version_rc_.md | 40 +++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_alpha_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_beta_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_rc_.md diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 77fc4b0a50..83f2ca4636 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -43,4 +43,4 @@ 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-]+)?)" +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/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 95e4775aad..34ef90a302 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -480,3 +480,36 @@ def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( out = f.read() file_regression.check(out, extension=".md") + + +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_changelog_incremental_with_release_candidate_version( + mocker, capsys, changelog_path, file_regression, test_input +): + """Fix #357""" + with open(changelog_path, "w") as f: + f.write(KEEP_A_CHANGELOG) + create_file_and_commit("irrelevant commit") + git.tag("1.0.0", annotated=True) + + create_file_and_commit("feat: add new output") + create_file_and_commit("fix: output glitch") + + testargs = ["cz", "bump", "--changelog", "--prerelease", test_input, "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("fix: mama gotta work") + create_file_and_commit("feat: add more stuff") + create_file_and_commit("Merge into master") + + testargs = ["cz", "changelog", "--incremental"] + + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + file_regression.check(out, extension=".md") diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_alpha_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_alpha_.md new file mode 100644 index 0000000000..1fd5ca870d --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_alpha_.md @@ -0,0 +1,40 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Feat + +- add more stuff + +### Fix + +- mama gotta work + +## 0.2.0a0 (2021-06-11) + +### Fix + +- output glitch + +### Feat + +- add new output + +## [1.0.0] - 2017-06-20 +### Added +- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). +- Version navigation. + +### Changed +- Start using "changelog" over "change log" since it's the common usage. + +### Removed +- Section about "changelog" vs "CHANGELOG". + +## [0.3.0] - 2015-12-03 +### Added +- RU translation from [@aishek](https://github.com/aishek). diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_beta_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_beta_.md new file mode 100644 index 0000000000..6ef1c0daad --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_beta_.md @@ -0,0 +1,40 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Feat + +- add more stuff + +### Fix + +- mama gotta work + +## 0.2.0b0 (2021-06-11) + +### Fix + +- output glitch + +### Feat + +- add new output + +## [1.0.0] - 2017-06-20 +### Added +- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). +- Version navigation. + +### Changed +- Start using "changelog" over "change log" since it's the common usage. + +### Removed +- Section about "changelog" vs "CHANGELOG". + +## [0.3.0] - 2015-12-03 +### Added +- RU translation from [@aishek](https://github.com/aishek). diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_rc_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_rc_.md new file mode 100644 index 0000000000..1898179dbf --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_release_candidate_version_rc_.md @@ -0,0 +1,40 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Feat + +- add more stuff + +### Fix + +- mama gotta work + +## 0.2.0rc0 (2021-06-11) + +### Fix + +- output glitch + +### Feat + +- add new output + +## [1.0.0] - 2017-06-20 +### Added +- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). +- Version navigation. + +### Changed +- Start using "changelog" over "change log" since it's the common usage. + +### Removed +- Section about "changelog" vs "CHANGELOG". + +## [0.3.0] - 2015-12-03 +### Added +- RU translation from [@aishek](https://github.com/aishek). From d82727c1931eee1d5929880c8d8731a5bbaba17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Fri, 11 Jun 2021 12:33:27 +0200 Subject: [PATCH 0065/1588] docs(README): add pre-commit badge --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index f930841380..ea45b2d68a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,6 +5,7 @@ [![Supported versions](https://img.shields.io/pypi/pyversions/commitizen.svg?style=flat-square)](https://pypi.org/project/commitizen/) [![homebrew](https://img.shields.io/homebrew/v/commitizen?color=teal&style=flat-square)](https://formulae.brew.sh/formula/commitizen) [![Codecov](https://img.shields.io/codecov/c/github/commitizen-tools/commitizen.svg?style=flat-square)](https://codecov.io/gh/commitizen-tools/commitizen) +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=flat-square&logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) ![Using commitizen cli](images/demo.gif) From 7573d167b015f6104c5fbb8cfcf285bbeb8f928b Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 11 Jun 2021 17:13:15 +0000 Subject: [PATCH 0066/1588] =?UTF-8?q?bump:=20version=202.17.8=20=E2=86=92?= =?UTF-8?q?=202.17.9?= 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 d4c53f528c..198f5a71e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.9 (2021-06-11) + +### Fix + +- **changelog**: generating changelog after a pre-release + ## v2.17.8 (2021-05-28) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 757a1dcbe0..1ad4769cce 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.8" +__version__ = "2.17.9" diff --git a/pyproject.toml b/pyproject.toml index a13c53a733..7f7e6d3720 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.8" +version = "2.17.9" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.8" +version = "2.17.9" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 00f81d3bc4fc53982898af7bac9e176b648cce18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Mon, 21 Jun 2021 19:15:06 +0200 Subject: [PATCH 0067/1588] fix: add support for jinja2 v3 Closes #391 --- pyproject.toml | 3 ++- tests/commands/test_changelog_command.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7f7e6d3720..fdfa833ee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ colorama = "^0.4.1" termcolor = "^1.1" packaging = ">=19,<21" tomlkit = ">=0.5.3,<1.0.0" -jinja2 = "^2.10.3" +jinja2 = ">=2.10.3" pyyaml = ">=3.08" argcomplete = "^1.12.1" @@ -71,6 +71,7 @@ freezegun = "^0.3.15" pydocstyle = "^5.0.2" pre-commit = "^2.6.0" pytest-regressions = "^2.2.0" +pytest-freezegun = "^0.4.2" [tool.poetry.scripts] cz = "commitizen.cli:main" diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 34ef90a302..02e0e74644 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -484,6 +484,7 @@ def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( @pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) @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 ): From dc22f2e940959b4bdf116d1c6d6cb16b1bdae81c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 22 Jun 2021 07:16:23 +0000 Subject: [PATCH 0068/1588] =?UTF-8?q?bump:=20version=202.17.9=20=E2=86=92?= =?UTF-8?q?=202.17.10?= 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 198f5a71e8..09148fface 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.10 (2021-06-22) + +### Fix + +- add support for jinja2 v3 + ## v2.17.9 (2021-06-11) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 1ad4769cce..81fde34689 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.9" +__version__ = "2.17.10" diff --git a/pyproject.toml b/pyproject.toml index fdfa833ee2..9d39fcfadb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.9" +version = "2.17.10" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.9" +version = "2.17.10" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 986f2d8fda44bd69e1d1763ab3a3cadf120566df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Wed, 23 Jun 2021 20:57:34 +0200 Subject: [PATCH 0069/1588] fix: correct indentation for json config for better readability --- commitizen/config/json_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index 725e37a0eb..445f2aac5f 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -27,7 +27,7 @@ def set_key(self, key, value): parser["commitizen"][key] = value with open(self.path, "w") as f: - json.dump(parser, f) + json.dump(parser, f, indent=2) return self def _parse_setting(self, data: Union[bytes, str]): From bec20ebf433f2281c70f1eb4b0b6a1d0ed83e9b2 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 24 Jun 2021 08:50:45 +0000 Subject: [PATCH 0070/1588] =?UTF-8?q?bump:=20version=202.17.10=20=E2=86=92?= =?UTF-8?q?=202.17.11?= 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 09148fface..3f6d6b193e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.11 (2021-06-24) + +### Fix + +- correct indentation for json config for better readability + ## v2.17.10 (2021-06-22) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 81fde34689..37684dd0a9 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.10" +__version__ = "2.17.11" diff --git a/pyproject.toml b/pyproject.toml index 9d39fcfadb..2e7f806d4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.10" +version = "2.17.11" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.10" +version = "2.17.11" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 9eae518235d051f145807ddf971ceb79ad49953a Mon Sep 17 00:00:00 2001 From: Jeffrey James Date: Mon, 5 Jul 2021 23:20:12 -0400 Subject: [PATCH 0071/1588] fix(git.py): ensure signed commits in changelog when git config log.showsignature=true #397 --- commitizen/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commitizen/git.py b/commitizen/git.py index a4476de6bb..2904d6cb05 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -77,7 +77,9 @@ def get_commits( args: str = "", ) -> List[GitCommit]: """Get the commits between start and end.""" - git_log_cmd = f"git log --pretty={log_format}{delimiter} {args}" + git_log_cmd = ( + f"git -c log.showSignature=False log --pretty={log_format}{delimiter} {args}" + ) if start: c = cmd.run(f"{git_log_cmd} {start}..{end}") From 184c439603d6060892076057a2a2a52d7b73de76 Mon Sep 17 00:00:00 2001 From: Jeffrey James Date: Tue, 6 Jul 2021 01:47:41 -0400 Subject: [PATCH 0072/1588] test(git.py): Test get_commits() with a gpg-signed commit #397 --- tests/test_git.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_git.py b/tests/test_git.py index 03ddcbaa13..dc8023b956 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -1,4 +1,5 @@ import inspect +import shutil from typing import List, Optional import pytest @@ -137,6 +138,27 @@ def test_get_commits_without_breakline_in_each_commit(mocker): ) +def test_get_commits_with_signature(): + config_file = ".git/config" + config_backup = ".git/config.bak" + shutil.copy(config_file, config_backup) + + try: + # temporarily turn on --show-signature + cmd.run("git config log.showsignature true") + + # retrieve a commit that we know has a signature + commit = git.get_commits( + start="bec20ebf433f2281c70f1eb4b0b6a1d0ed83e9b2", + end="9eae518235d051f145807ddf971ceb79ad49953a", + )[0] + + assert commit.title.startswith("fix") + finally: + # restore the repo's original config + shutil.move(config_backup, config_file) + + def test_get_tag_names_has_correct_arrow_annotation(): arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"] From 4dad5c87491d1503307f803a7bd6c6060841108f Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 6 Jul 2021 17:44:16 +0000 Subject: [PATCH 0073/1588] =?UTF-8?q?bump:=20version=202.17.11=20=E2=86=92?= =?UTF-8?q?=202.17.12?= 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 3f6d6b193e..ddfa7f2cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.17.12 (2021-07-06) + +### Fix + +- **git.py**: ensure signed commits in changelog when git config log.showsignature=true + ## v2.17.11 (2021-06-24) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 37684dd0a9..2943092d1b 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.11" +__version__ = "2.17.12" diff --git a/pyproject.toml b/pyproject.toml index 2e7f806d4d..a3dcdfe264 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.11" +version = "2.17.12" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.11" +version = "2.17.12" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 99648b5c39a08703eb9ca10b3484e3741a77fd43 Mon Sep 17 00:00:00 2001 From: Wojciech Kusa Date: Tue, 13 Jul 2021 17:18:00 +0200 Subject: [PATCH 0074/1588] docs(README): fix URL in README.md fix link to Customization --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index ea45b2d68a..fa62b2eab6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -178,7 +178,7 @@ See [Third-Party Commitizen Templates](third-party-commitizen.md). ### 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](https://commitizen-tools.github.io/commitizen/customization.html)) 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 7a347788b87ac6cbfff55dd556f5bd84e1ac6944 Mon Sep 17 00:00:00 2001 From: Wojciech Kusa Date: Wed, 14 Jul 2021 15:17:34 +0200 Subject: [PATCH 0075/1588] docs(README): fix URL in README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index fa62b2eab6..f8482f4a69 100644 --- a/docs/README.md +++ b/docs/README.md @@ -178,7 +178,7 @@ See [Third-Party Commitizen Templates](third-party-commitizen.md). ### 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.html)) +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) From 50d57acc8137ae9f7ff470c86e1e9009467669d3 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 14 Jul 2021 15:01:37 +0000 Subject: [PATCH 0076/1588] =?UTF-8?q?bump:=20version=202.17.12=20=E2=86=92?= =?UTF-8?q?=202.17.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddfa7f2cfa..25a748580c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ +## v2.17.13 (2021-07-14) + ## v2.17.12 (2021-07-06) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 2943092d1b..90c07a41b7 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.12" +__version__ = "2.17.13" diff --git a/pyproject.toml b/pyproject.toml index a3dcdfe264..d4c844edd4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.12" +version = "2.17.13" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.12" +version = "2.17.13" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From d5eeef676e649b57b544f81df7fff19f0a4d24fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Sat, 21 Nov 2020 18:52:39 +0100 Subject: [PATCH 0077/1588] ci: run tests on linux, mac and windows --- .github/workflows/pythonpackage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 3fa8855279..c7eb887399 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -4,12 +4,12 @@ on: [pull_request] jobs: python-check: - runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: python-version: [3.6, 3.7, 3.8] - + platform: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 with: From a074a79697744d995fbc3459766dec7705b80a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Fraire=20Willemo=C3=ABs?= Date: Sat, 21 Nov 2020 18:55:24 +0100 Subject: [PATCH 0078/1588] ci: run tests on oldest py3.6 and last 2 py3.9 and py3.8 --- .github/workflows/pythonpackage.yml | 3 +-- pyproject.toml | 4 +++- tests/commands/conftest.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index c7eb887399..82078d4b93 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -5,9 +5,8 @@ on: [pull_request] jobs: python-check: strategy: - max-parallel: 4 matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.6, 3.8, 3.9] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: diff --git a/pyproject.toml b/pyproject.toml index d4c844edd4..40346652df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,7 +63,7 @@ flake8 = "^3.6" pytest-cov = "^2.6" pytest-mock = "^2.0" codecov = "^2.0" -mypy = "^0.770" +mypy = "0.910" mkdocs = "^1.0" mkdocs-material = "^4.1" isort = "^5.7.0" @@ -72,6 +72,8 @@ pydocstyle = "^5.0.2" pre-commit = "^2.6.0" pytest-regressions = "^2.2.0" pytest-freezegun = "^0.4.2" +types-PyYAML = "^5.4.3" +types-termcolor = "^0.1.1" [tool.poetry.scripts] cz = "commitizen.cli:main" diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index 25bab04464..faae727918 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -13,11 +13,11 @@ def config(): return _config -@pytest.fixture() +@pytest.fixture() # type: ignore def changelog_path() -> str: return os.path.join(os.getcwd(), "CHANGELOG.md") -@pytest.fixture() +@pytest.fixture() # type: ignore def config_path() -> str: return os.path.join(os.getcwd(), "pyproject.toml") From 078183510ba415457532b6e811a2e398ab9a5ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Mon, 2 Aug 2021 09:51:23 +0200 Subject: [PATCH 0079/1588] style: remove unused mypy comment --- commitizen/commands/init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index eed9b83ae4..d4a4180aa3 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -51,7 +51,7 @@ def __call__(self): def _ask_config_path(self) -> str: name = questionary.select( "Please choose a supported config file: (default: pyproject.toml)", - choices=config_files, # type: ignore + choices=config_files, default="pyproject.toml", style=self.cz.style, ).ask() From 33c3c49c252890db7859f2cad76525fd86b8eaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fraire=20Willemo=C3=ABs=2C=20Santiago?= Date: Tue, 27 Jul 2021 08:12:39 +0200 Subject: [PATCH 0080/1588] docs(contributing): do not request modifications to changelog --- docs/contributing.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/contributing.md b/docs/contributing.md index 4f04978a25..b106edc73c 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -15,7 +15,9 @@ If you're a first-time contributor, you can check the issues with [good first is 5. Check out a new branch and add your modification. 6. Add test cases for all your changes. (We use [CodeCov](https://codecov.io/) to ensure our test coverage does not drop.) -7. Use [commitizen](https://github.com/commitizen-tools/commitizen) to do git commit. +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` and `CHANGELOG.md` for your changes. +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) 🙏 + +[conventional-commmits]: https://www.conventionalcommits.org/ From cfec0f5cbbb86176e372889051289e21c10a5518 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Fri, 16 Jul 2021 19:09:45 -0700 Subject: [PATCH 0081/1588] feat(prompt): add keyboard shortcuts with config option --- .../conventional_commits.py | 17 +++++++++++++++-- commitizen/defaults.py | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 6ac62d5ec1..d51e8bdf20 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -45,16 +45,23 @@ def questions(self) -> List[Dict[str, Any]]: "type": "list", "name": "prefix", "message": "Select the type of change you are committing", + "use_shortcuts": self.config.settings['use_shortcuts'], "choices": [ { "value": "fix", "name": "fix: A bug fix. Correlates with PATCH in SemVer", + "key": "x", }, { "value": "feat", "name": "feat: A new feature. Correlates with MINOR in SemVer", + "key": "f", + }, + { + "value": "docs", + "name": "docs: Documentation only changes", + "key": "d", }, - {"value": "docs", "name": "docs: Documentation only changes"}, { "value": "style", "name": ( @@ -62,6 +69,7 @@ def questions(self) -> List[Dict[str, Any]]: "meaning of the code (white-space, formatting," " missing semi-colons, etc)" ), + "key": "s", }, { "value": "refactor", @@ -69,16 +77,19 @@ def questions(self) -> List[Dict[str, Any]]: "refactor: A code change that neither fixes " "a bug nor adds a feature" ), + "key": "r", }, { "value": "perf", "name": "perf: A code change that improves performance", + "key": "p", }, { "value": "test", "name": ( "test: Adding missing or correcting " "existing tests" ), + "key": "t", }, { "value": "build", @@ -86,6 +97,7 @@ def questions(self) -> List[Dict[str, Any]]: "build: Changes that affect the build system or " "external dependencies (example scopes: pip, docker, npm)" ), + "key": "b", }, { "value": "ci", @@ -93,7 +105,8 @@ def questions(self) -> List[Dict[str, Any]]: "ci: Changes to our CI configuration files and " "scripts (example scopes: GitLabCI)" ), - }, + "key": "c", + } ], }, { diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 83f2ca4636..5d21f67a98 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -21,6 +21,7 @@ "changelog_incremental": False, "changelog_start_rev": None, "update_changelog_on_bump": False, + "use_shortcuts": False, } MAJOR = "MAJOR" From 3910f844f45effa8d3e9fe8475fbb38c22975a30 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Fri, 6 Aug 2021 11:39:15 -0700 Subject: [PATCH 0082/1588] test: update tests for keyboard shortcuts Only testing that cz_conventional_commits has keyboard shortcuts configured, and that the use_shortcuts config option is known. Actually mocking and asserting against what's written to stdout is a footgun #406, #380 --- tests/test_conf.py | 2 ++ tests/test_cz_conventional_commits.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/tests/test_conf.py b/tests/test_conf.py index f05603cfe4..786af25756 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -46,6 +46,7 @@ "changelog_incremental": False, "changelog_start_rev": None, "update_changelog_on_bump": False, + "use_shortcuts": False, } _new_settings = { @@ -59,6 +60,7 @@ "changelog_incremental": False, "changelog_start_rev": None, "update_changelog_on_bump": False, + "use_shortcuts": False, } _read_settings = { diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index e43284a121..6a3b538ed3 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -62,6 +62,15 @@ def test_questions(config): assert isinstance(questions[0], dict) +def test_choices_all_have_keyboard_shortcuts(config): + conventional_commits = ConventionalCommitsCz(config) + questions = conventional_commits.questions() + + list_questions = (q for q in questions if q['type'] == "list") + for select in list_questions: + assert all('key' in choice for choice in select['choices']) + + def test_small_answer(config): conventional_commits = ConventionalCommitsCz(config) answers = { From 6820271877fc3c7176bf842dc513ef5be1305882 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Mon, 9 Aug 2021 09:42:35 -0700 Subject: [PATCH 0083/1588] style: formatting --- commitizen/cz/conventional_commits/conventional_commits.py | 4 ++-- commitizen/defaults.py | 2 +- tests/test_cz_conventional_commits.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index d51e8bdf20..fea3d61848 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -45,7 +45,7 @@ def questions(self) -> List[Dict[str, Any]]: "type": "list", "name": "prefix", "message": "Select the type of change you are committing", - "use_shortcuts": self.config.settings['use_shortcuts'], + "use_shortcuts": self.config.settings["use_shortcuts"], "choices": [ { "value": "fix", @@ -106,7 +106,7 @@ def questions(self) -> List[Dict[str, Any]]: "scripts (example scopes: GitLabCI)" ), "key": "c", - } + }, ], }, { diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 5d21f67a98..e460bbd6f7 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -21,7 +21,7 @@ "changelog_incremental": False, "changelog_start_rev": None, "update_changelog_on_bump": False, - "use_shortcuts": False, + "use_shortcuts": False, } MAJOR = "MAJOR" diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 6a3b538ed3..b84144e94c 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -66,9 +66,9 @@ def test_choices_all_have_keyboard_shortcuts(config): conventional_commits = ConventionalCommitsCz(config) questions = conventional_commits.questions() - list_questions = (q for q in questions if q['type'] == "list") + list_questions = (q for q in questions if q["type"] == "list") for select in list_questions: - assert all('key' in choice for choice in select['choices']) + assert all("key" in choice for choice in select["choices"]) def test_small_answer(config): From e333537b3dd51216f674db4711608de720ebf690 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 11 Aug 2021 18:40:41 -0700 Subject: [PATCH 0084/1588] refactor(shortcuts): move check for shortcut config setting to apply to any list select --- commitizen/commands/commit.py | 2 ++ commitizen/cz/conventional_commits/conventional_commits.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 4c6f7aa03c..ac646a0220 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -46,6 +46,8 @@ def prompt_commit_questions(self) -> str: # Prompt user for the commit message cz = self.cz questions = cz.questions() + for question in filter(lambda q: q['type'] == 'list', questions): + question["use_shortcuts"] = self.config.settings["use_shortcuts"] try: answers = questionary.prompt(questions, style=cz.style) except ValueError as err: diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index fea3d61848..61f7b7f94b 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -45,7 +45,6 @@ def questions(self) -> List[Dict[str, Any]]: "type": "list", "name": "prefix", "message": "Select the type of change you are committing", - "use_shortcuts": self.config.settings["use_shortcuts"], "choices": [ { "value": "fix", From 90c9918e259fd3956e64be80e1358c1cfb75a7d2 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 11 Aug 2021 18:43:13 -0700 Subject: [PATCH 0085/1588] docs(shortcuts): update to include info about keyboard shortcut options --- docs/config.md | 28 +++++++++++++++--------- docs/customization.md | 51 +++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/docs/config.md b/docs/config.md index 204edcf887..eee90e1dcc 100644 --- a/docs/config.md +++ b/docs/config.md @@ -122,13 +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](https://commitizen-tools.github.io/commitizen/bump/#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](https://commitizen-tools.github.io/commitizen/bump/#tag_format) | -| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more](https://commitizen-tools.github.io/commitizen/bump/#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)](https://github.com/tmbo/questionary#additional-features) | -| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more](https://commitizen-tools.github.io/commitizen/customization/) | +| 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) | + +[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 +[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 diff --git a/docs/customization.md b/docs/customization.md index 3492d8288c..b96c459e41 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -138,30 +138,39 @@ commitizen: ### Customize configuration -| Parameter | Type | Default | Description | -| ------------------ | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `questions` | `dict` | `None` | Questions regarding the commit message. Detailed below. | -| `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2](https://jinja.palletsprojects.com/en/2.10.x/) 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`. | -| `schema_pattern` | `str` | `None` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. | -| `info_path` | `str` | `None` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. | -| `info` | `str` | `None` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. | -| `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"]` | - +| Parameter | Type | Default | Description | +| ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `questions` | `dict` | `None` | Questions regarding the commit message. Detailed below. | +| `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`. | +| `schema_pattern` | `str` | `None` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. | +| `info_path` | `str` | `None` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. | +| `info` | `str` | `None` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. | +| `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"]` | + +[jinja2]: https://jinja.palletsprojects.com/en/2.10.x/ #### Detailed `questions` content -| Parameter | Type | Default | Description | -| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -| `type` | `str` | `None` | The type of questions. Valid type: `list`, `input` and etc. [See More](https://github.com/tmbo/questionary#different-question-types) | -| `name` | `str` | `None` | The key for the value answered by user. It's used in `message_template` | -| `message` | `str` | `None` | Detail description for the question. | -| `choices` | `list` | `None` | (OPTIONAL) The choices when `type = list`. Either use a list of values or a list of dicitionaries with `name` and `value` keys. 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)** | +| Parameter | Type | Default | Description | +| --------- | ------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `type` | `str` | `None` | The type of questions. Valid type: `list`, `input` and etc. [See More][different-question-types] | +| `name` | `str` | `None` | The key for the value answered by user. It's used in `message_template` | +| `message` | `str` | `None` | Detail description for the question. | +| `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 +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. +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: From dedcb2dd3a54d0b4011c7a68abdae74cfb9125c4 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 11 Aug 2021 18:45:20 -0700 Subject: [PATCH 0086/1588] style: forgot to run black --- commitizen/commands/commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index ac646a0220..bad47dd572 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -46,7 +46,7 @@ def prompt_commit_questions(self) -> str: # Prompt user for the commit message cz = self.cz questions = cz.questions() - for question in filter(lambda q: q['type'] == 'list', questions): + for question in filter(lambda q: q["type"] == "list", questions): question["use_shortcuts"] = self.config.settings["use_shortcuts"] try: answers = questionary.prompt(questions, style=cz.style) From cf646706b53bbd7921b291d24063b8d7eb300899 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 13 Aug 2021 09:16:08 +0000 Subject: [PATCH 0087/1588] =?UTF-8?q?bump:=20version=202.17.13=20=E2=86=92?= =?UTF-8?q?=202.18.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 ++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25a748580c..a9b383bac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,14 @@ +## v2.18.0 (2021-08-13) + +### Refactor + +- **shortcuts**: move check for shortcut config setting to apply to any list select + +### Feat + +- **prompt**: add keyboard shortcuts with config option + ## v2.17.13 (2021-07-14) ## v2.17.12 (2021-07-06) diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 90c07a41b7..6ebac24f89 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.17.13" +__version__ = "2.18.0" diff --git a/pyproject.toml b/pyproject.toml index 40346652df..c72e717fdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.17.13" +version = "2.18.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -29,7 +29,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.17.13" +version = "2.18.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From d1e6dad31889646fcbd94ed0ba19aea8077a32d4 Mon Sep 17 00:00:00 2001 From: falko-apheris <86360866+falko-apheris@users.noreply.github.com> Date: Fri, 13 Aug 2021 14:32:22 +0200 Subject: [PATCH 0088/1588] docs: add docs for 3rd party module cz-github-jira-conventional --- docs/third-party-commitizen.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/third-party-commitizen.md b/docs/third-party-commitizen.md index 7c27e75d80..ff6144e6b9 100644 --- a/docs/third-party-commitizen.md +++ b/docs/third-party-commitizen.md @@ -11,6 +11,17 @@ meaningful way. It can be installed with `pip install conventional-JIRA`. +### [GitHub JIRA Conventional](https://pypi.org/project/cz-github-jira-conventional/) + +This plugin extends the commitizen tools by: +- requiring a JIRA issue id in the commit message +- creating links to GitHub commits in the CHANGELOG.md +- creating links to JIRA issues in the CHANGELOG.md + +It can be installed with `cz-github-jira-conventional`. + +For installation instructions (configuration and pre-commit) please visit https://github.com/apheris/cz-github-jira-conventional + ### [Commitizen emoji](https://pypi.org/project/commitizen-emoji/) Just like *conventional commit* format, but with emojis and optionally time spent and related tasks. From 79b31566ab1e66560856ae1e813f702264aba06b Mon Sep 17 00:00:00 2001 From: Bryan Dady Date: Fri, 10 Sep 2021 23:36:10 -0600 Subject: [PATCH 0089/1588] 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 0090/1588] 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 0091/1588] 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 0092/1588] =?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 0093/1588] 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 0094/1588] 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 0095/1588] =?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 0096/1588] 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 0097/1588] =?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 0098/1588] 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 0099/1588] 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 0100/1588] 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 0101/1588] =?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 0102/1588] 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 0103/1588] 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 0104/1588] 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 0105/1588] 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 0106/1588] 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 0107/1588] 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 0108/1588] 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 0109/1588] 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 0110/1588] 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 0111/1588] 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 0112/1588] 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 0113/1588] 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 0114/1588] 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 0115/1588] 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 0116/1588] 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 0117/1588] 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 0118/1588] 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 0119/1588] 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 0120/1588] 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 0121/1588] 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 0122/1588] 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 0123/1588] 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 0124/1588] 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 0125/1588] 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 0126/1588] 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 0127/1588] 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 0128/1588] 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 0129/1588] =?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 0130/1588] 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 0131/1588] 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 0132/1588] =?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 0133/1588] 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 0134/1588] 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 0135/1588] 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 0136/1588] 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 0137/1588] =?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 0138/1588] 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 0139/1588] 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 0140/1588] 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 0141/1588] 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 0142/1588] 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 0143/1588] 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 0144/1588] 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 0145/1588] =?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 0146/1588] 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 0147/1588] 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 0148/1588] 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 0149/1588] 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 0150/1588] 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 0151/1588] 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 0152/1588] 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 0153/1588] 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 0154/1588] =?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 0155/1588] 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 0156/1588] =?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 0157/1588] 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 0158/1588] 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 0159/1588] 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 0160/1588] =?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 0161/1588] 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 0162/1588] 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 0163/1588] =?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 0164/1588] 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 0165/1588] 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 0166/1588] 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 0167/1588] 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 0168/1588] =?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 0169/1588] 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 0170/1588] 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 0171/1588] 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 0172/1588] 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: