diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ef07676fb6..b55eccfcc1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -21,4 +21,5 @@ updates: - dependencies commit-message: prefix: "build(poetry)" + prefix-development:: "build(poetry-dev)" include: "scope" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 315524f0d3..322bd0d92d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v3.1.0 # automatically updated by Commitizen + rev: v3.1.1 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 392f9df4bb..3e765c9c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v3.1.1 (2023-04-28) + +### Fix + +- bump changelog for prerelease without commits + ## v3.1.0 (2023-04-25) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index f5f41e567e..d539d50ceb 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "3.1.0" +__version__ = "3.1.1" diff --git a/commitizen/changelog.py b/commitizen/changelog.py index 1a6ca04cc1..74cee3260a 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -90,10 +90,12 @@ def generate_tree_from_commits( pat = re.compile(changelog_pattern) map_pat = re.compile(commit_parser, re.MULTILINE) body_map_pat = re.compile(commit_parser, re.MULTILINE | re.DOTALL) + current_tag: Optional[GitTag] = None # Check if the latest commit is not tagged - latest_commit = commits[0] - current_tag: Optional[GitTag] = get_commit_tag(latest_commit, tags) + if commits: + latest_commit = commits[0] + current_tag = get_commit_tag(latest_commit, tags) current_tag_name: str = unreleased_version or "Unreleased" current_tag_date: str = "" diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 4c291d3ac2..69d223ed49 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -3,6 +3,8 @@ from operator import itemgetter from typing import Callable, Dict, List, Optional +from packaging.version import parse + from commitizen import bump, changelog, defaults, factory, git, out, version_types from commitizen.config import BaseConfig from commitizen.exceptions import ( @@ -36,6 +38,13 @@ def __init__(self, config: BaseConfig, args): "changelog_incremental" ) self.dry_run = args["dry_run"] + + self.current_version = ( + args.get("current_version") or self.config.settings.get("version") or "" + ) + self.current_version_instance = ( + parse(self.current_version) if self.current_version else None + ) self.unreleased_version = args["unreleased_version"] self.change_type_map = ( self.config.settings.get("change_type_map") or self.cz.change_type_map @@ -155,7 +164,10 @@ def __call__(self): ) commits = git.get_commits(start=start_rev, end=end_rev, args="--topo-order") - if not commits: + if not commits and ( + self.current_version_instance is None + or not self.current_version_instance.is_prerelease + ): raise NoCommitsFoundError("No commits found") tree = changelog.generate_tree_from_commits( diff --git a/poetry.lock b/poetry.lock index c8f8503177..1026be8db4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -14,22 +14,21 @@ files = [ [[package]] name = "argcomplete" -version = "2.1.2" +version = "3.0.6" description = "Bash tab completion for argparse" category = "main" optional = false python-versions = ">=3.6" files = [ - {file = "argcomplete-2.1.2-py3-none-any.whl", hash = "sha256:4ba9cdaa28c361d251edce884cd50b4b1215d65cdc881bd204426cdde9f52731"}, - {file = "argcomplete-2.1.2.tar.gz", hash = "sha256:fc82ef070c607b1559b5c720529d63b54d9dcf2dcfc2632b10e6372314a34457"}, + {file = "argcomplete-3.0.6-py3-none-any.whl", hash = "sha256:798f28e11dc141f415879497599316a8a9126672a883064b851597a0d94be8a9"}, + {file = "argcomplete-3.0.6.tar.gz", hash = "sha256:9fe49c66ba963b81b64025f74bfbd0275619a6bde1c7370654dc365d4ecc9a0b"}, ] [package.dependencies] -importlib-metadata = {version = ">=0.23,<6", markers = "python_version == \"3.7\""} +importlib-metadata = {version = ">=0.23,<7", markers = "python_version == \"3.7\""} [package.extras] -lint = ["flake8", "mypy"] -test = ["coverage", "flake8", "mypy", "pexpect", "wheel"] +test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] [[package]] name = "backcall" @@ -1599,4 +1598,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "ee6d7cb4d36c4f9312dcba8818bbdd1426f5c2b04ddf92687835fa99fd3f3a4e" +content-hash = "f85c312b8da45408e78e463496840bcb3d770ee5731a2aada55c56bcae86e547" diff --git a/pyproject.toml b/pyproject.toml index 0cf78c8cce..f27c80ca6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "3.1.0" +version = "3.1.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -9,7 +9,7 @@ version_files = [ [tool.poetry] name = "commitizen" -version = "3.1.0" +version = "3.1.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" @@ -43,7 +43,7 @@ packaging = ">=19" tomlkit = ">=0.5.3,<1.0.0" jinja2 = ">=2.10.3" pyyaml = ">=3.08" -argcomplete = ">=1.12.1,<2.2" +argcomplete = ">=1.12.1,<3.1" typing-extensions = { version = "^4.0.1", python = "<3.8" } charset-normalizer = ">=2.1.0,<4" # Use the Python 3.11 compatible API: https://github.com/python/importlib_metadata#compatibility diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index bdc384c3ca..4f25ebcad5 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -1,3 +1,4 @@ +import itertools import sys from datetime import datetime @@ -660,6 +661,36 @@ def test_changelog_incremental_with_release_candidate_version( file_regression.check(out, extension=".md") +@pytest.mark.parametrize( + "from_pre,to_pre", itertools.product(["alpha", "beta", "rc"], repeat=2) +) +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2021-06-11") +def test_changelog_incremental_with_prerelease_version_to_prerelease_version( + mocker: MockFixture, changelog_path, file_regression, from_pre, to_pre +): + 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", from_pre, "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + testargs = ["cz", "bump", "--changelog", "--prerelease", to_pre, "--yes"] + 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.parametrize("test_input", ["rc", "alpha", "beta"]) @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_release_candidate_version_with_merge_prerelease( diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_alpha_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_alpha_.md new file mode 100644 index 0000000000..cfaca36ab9 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_alpha_.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). + +## 0.2.0a1 (2021-06-11) + +## 0.2.0a0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_beta_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_beta_.md new file mode 100644 index 0000000000..013e16fc22 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_beta_.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). + +## 0.2.0b0 (2021-06-11) + +## 0.2.0a0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_rc_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_rc_.md new file mode 100644 index 0000000000..25cc27682b --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_alpha_rc_.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). + +## 0.2.0rc0 (2021-06-11) + +## 0.2.0a0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_alpha_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_alpha_.md new file mode 100644 index 0000000000..300ca95756 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_alpha_.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). + +## 0.2.0a0 (2021-06-11) + +## 0.2.0b0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_beta_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_beta_.md new file mode 100644 index 0000000000..ec9ab11d7b --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_beta_.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). + +## 0.2.0b1 (2021-06-11) + +## 0.2.0b0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_rc_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_rc_.md new file mode 100644 index 0000000000..22b1e14dba --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_beta_rc_.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). + +## 0.2.0rc0 (2021-06-11) + +## 0.2.0b0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_alpha_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_alpha_.md new file mode 100644 index 0000000000..9a7e9f161f --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_alpha_.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). + +## 0.2.0a0 (2021-06-11) + +## 0.2.0rc0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_beta_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_beta_.md new file mode 100644 index 0000000000..b3be6f3c1d --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_beta_.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). + +## 0.2.0b0 (2021-06-11) + +## 0.2.0rc0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_rc_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_rc_.md new file mode 100644 index 0000000000..e1c20b7e0d --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_prerelease_version_to_prerelease_version_rc_rc_.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). + +## 0.2.0rc1 (2021-06-11) + +## 0.2.0rc0 (2021-06-11) + +### Feat + +- add new output + +### Fix + +- 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_changelog.py b/tests/test_changelog.py index 0aa9fdfbff..78a2697c36 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -1083,6 +1083,17 @@ def test_generate_tree_from_commits(gitcommits, tags, merge_prereleases): assert tuple(tree) == COMMITS_TREE +def test_generate_tree_from_commits_with_no_commits(tags): + gitcommits = [] + parser = defaults.commit_parser + changelog_pattern = defaults.bump_pattern + tree = changelog.generate_tree_from_commits( + gitcommits, tags, parser, changelog_pattern + ) + + assert tuple(tree) == ({"changes": {}, "date": "", "version": "Unreleased"},) + + @pytest.mark.parametrize( "change_type_order, expected_reordering", (