From 59ad9c478f3fe5ef9dd6d65fb8855eb31a3e6ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 13 Apr 2023 08:13:41 +0200 Subject: [PATCH 1/3] feat(changelog): add merge_prereleases flag --- commitizen/changelog.py | 33 +- commitizen/cli.py | 11 +- commitizen/commands/changelog.py | 5 + commitizen/defaults.py | 2 + docs/changelog.md | 20 +- docs/config.md | 1 + tests/commands/test_changelog_command.py | 107 +++++++ ...log_config_flag_merge_prerelease_alpha_.md | 13 + ...elog_config_flag_merge_prerelease_beta_.md | 13 + ...ngelog_config_flag_merge_prerelease_rc_.md | 13 + ...ncremental_with_merge_prerelease_alpha_.md | 37 +++ ...incremental_with_merge_prerelease_beta_.md | 37 +++ ...g_incremental_with_merge_prerelease_rc_.md | 37 +++ ...te_version_with_merge_prerelease_alpha_.md | 13 + ...ate_version_with_merge_prerelease_beta_.md | 13 + ...idate_version_with_merge_prerelease_rc_.md | 13 + tests/test_changelog.py | 291 +++++++++++++++++- tests/test_conf.py | 2 + 18 files changed, 652 insertions(+), 9 deletions(-) create mode 100644 tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_alpha_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_beta_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_rc_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_alpha_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_beta_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_rc_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_alpha_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_beta_.md create mode 100644 tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_rc_.md diff --git a/commitizen/changelog.py b/commitizen/changelog.py index ead80ab775..dcbc9a1dea 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -32,6 +32,7 @@ from typing import Callable, Dict, Iterable, List, Optional, Tuple from jinja2 import Environment, PackageLoader +from packaging.version import InvalidVersion, Version from commitizen import defaults from commitizen.bump import normalize_tag @@ -43,6 +44,31 @@ def get_commit_tag(commit: GitCommit, tags: List[GitTag]) -> Optional[GitTag]: return next((tag for tag in tags if tag.rev == commit.rev), None) +def get_version(tag: GitTag) -> Optional[Version]: + version = None + try: + version = Version(tag.name) + except InvalidVersion: + pass + return version + + +def tag_included_in_changelog( + tag: GitTag, used_tags: List, merge_prerelease: bool +) -> bool: + if tag in used_tags: + return False + + version = get_version(tag) + if version is None: + return False + + if merge_prerelease and version.is_prerelease: + return False + + return True + + def generate_tree_from_commits( commits: List[GitCommit], tags: List[GitTag], @@ -51,6 +77,7 @@ def generate_tree_from_commits( unreleased_version: Optional[str] = None, change_type_map: Optional[Dict[str, str]] = None, changelog_message_builder_hook: Optional[Callable] = None, + merge_prerelease: bool = False, ) -> Iterable[Dict]: pat = re.compile(changelog_pattern) map_pat = re.compile(commit_parser, re.MULTILINE) @@ -73,15 +100,15 @@ def generate_tree_from_commits( for commit in commits: commit_tag = get_commit_tag(commit, tags) - if commit_tag is not None and commit_tag not in used_tags: + if commit_tag is not None and tag_included_in_changelog( + commit_tag, used_tags, merge_prerelease + ): used_tags.append(commit_tag) yield { "version": current_tag_name, "date": current_tag_date, "changes": changes, } - # TODO: Check if tag matches the version pattern, otherwise skip it. - # This in order to prevent tags that are not versions. current_tag_name = commit_tag.name current_tag_date = commit_tag.date changes = defaultdict(list) diff --git a/commitizen/cli.py b/commitizen/cli.py index 868e74dd9a..d6b2d5aae7 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -248,10 +248,19 @@ "name": "--start-rev", "default": None, "help": ( - "start rev of the changelog." + "start rev of the changelog. " "If not set, it will generate changelog from the start" ), }, + { + "name": "--merge-prerelease", + "action": "store_true", + "default": False, + "help": ( + "collect all changes from prereleases into next non-prerelease. " + "If not set, it will include prereleases in the changelog" + ), + }, ], }, { diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index d934ac2940..10fc890e9d 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -49,6 +49,9 @@ def __init__(self, config: BaseConfig, args): self.tag_format = args.get("tag_format") or self.config.settings.get( "tag_format" ) + self.merge_prerelease = args.get( + "merge_prerelease" + ) or self.config.settings.get("changelog_merge_prerelease") def _find_incremental_rev(self, latest_version: str, tags: List[GitTag]) -> str: """Try to find the 'start_rev'. @@ -110,6 +113,7 @@ def __call__(self): changelog_message_builder_hook: Optional[ Callable ] = self.cz.changelog_message_builder_hook + merge_prerelease = self.merge_prerelease if not changelog_pattern or not commit_parser: raise NoPatternMapError( @@ -156,6 +160,7 @@ def __call__(self): unreleased_version, change_type_map=change_type_map, changelog_message_builder_hook=changelog_message_builder_hook, + merge_prerelease=merge_prerelease, ) if self.change_type_order: tree = changelog.order_changelog_tree(tree, self.change_type_order) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 296193534f..2ab349367d 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -36,6 +36,7 @@ class Settings(TypedDict, total=False): changelog_file: str changelog_incremental: bool changelog_start_rev: Optional[str] + changelog_merge_prerelease: bool update_changelog_on_bump: bool use_shortcuts: bool style: Optional[List[Tuple[str, str]]] @@ -67,6 +68,7 @@ class Settings(TypedDict, total=False): "changelog_file": "CHANGELOG.md", "changelog_incremental": False, "changelog_start_rev": None, + "changelog_merge_prerelease": False, "update_changelog_on_bump": False, "use_shortcuts": False, "major_version_zero": False, diff --git a/docs/changelog.md b/docs/changelog.md index 6f92bb21cd..b6e43c4fdd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -21,7 +21,9 @@ optional arguments: 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 + --merge-prerelease + collect all changes from prereleases into next non-prerelease. If not set, it will include prereleases in the changelog ``` ### Examples @@ -161,6 +163,22 @@ cz changelog --start-rev="v0.2.0" changelog_start_rev = "v0.2.0" ``` +### merge-prerelease + +This flag can be set in the `toml` file with the key `changelog_merge_prerelease` under `tools.commitizen` + +Collects changes from prereleases into the next non-prerelease. This means that if you have a prerelease version, and then a normal release, the changelog will show the prerelease changes as part of the changes of the normal release. If not set, it will include prereleases in the changelog. + +```bash +cz changelog --merge-prerelease +``` + +```toml +[tools.commitizen] +# ... +changelog_merge_prerelease = true +``` + ## Hooks Supported hook methods: diff --git a/docs/config.md b/docs/config.md index cf38c5c37f..d752c1210e 100644 --- a/docs/config.md +++ b/docs/config.md @@ -17,6 +17,7 @@ | `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 | +| `changelog_merge_prerelease` | `bool` | `false` | Collect all changes of prerelease versions into the next non-prerelease version when creating 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] | diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index 7805c99ad5..01290c1d0a 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -538,6 +538,40 @@ def test_changelog_config_flag_increment( file_regression.check(out, extension=".md") +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_changelog_config_flag_merge_prerelease( + mocker: MockFixture, changelog_path, config_path, file_regression, test_input +): + with open(config_path, "a") as f: + f.write("changelog_merge_prerelease = true\n") + + create_file_and_commit("irrelevant commit") + mocker.patch("commitizen.git.GitTag.date", "1970-01-01") + git.tag("1.0.0") + + create_file_and_commit("feat: add new output") + create_file_and_commit("fix: output glitch") + + testargs = ["cz", "bump", "--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"] + + 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") def test_changelog_config_start_rev_option( mocker: MockFixture, capsys, config_path, file_regression @@ -626,6 +660,79 @@ def test_changelog_incremental_with_release_candidate_version( 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( + mocker: MockFixture, 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") + mocker.patch("commitizen.git.GitTag.date", "1970-01-01") + git.tag("1.0.0") + + create_file_and_commit("feat: add new output") + create_file_and_commit("fix: output glitch") + + testargs = ["cz", "bump", "--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", "--merge-prerelease"] + + 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_incremental_with_merge_prerelease( + mocker: MockFixture, 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") + mocker.patch("commitizen.git.GitTag.date", "1970-01-01") + git.tag("1.0.0") + + create_file_and_commit("feat: add new output") + + testargs = ["cz", "bump", "--prerelease", test_input, "--yes", "--changelog"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + create_file_and_commit("fix: output glitch") + + testargs = ["cz", "bump", "--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", "--merge-prerelease", "--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") + + @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_with_filename_as_empty_string( mocker: MockFixture, changelog_path, config_path diff --git a/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_alpha_.md b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_alpha_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_alpha_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_beta_.md b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_beta_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_beta_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_rc_.md b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_rc_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_config_flag_merge_prerelease_rc_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_alpha_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_alpha_.md new file mode 100644 index 0000000000..8e81f62572 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_alpha_.md @@ -0,0 +1,37 @@ +# 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 +- output glitch + +## 0.2.0a0 (2023-04-16) + +### 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_merge_prerelease_beta_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_beta_.md new file mode 100644 index 0000000000..65f14c068e --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_beta_.md @@ -0,0 +1,37 @@ +# 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 +- output glitch + +## 0.2.0b0 (2023-04-16) + +### 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_merge_prerelease_rc_.md b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_rc_.md new file mode 100644 index 0000000000..0987e1127d --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_incremental_with_merge_prerelease_rc_.md @@ -0,0 +1,37 @@ +# 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 +- output glitch + +## 0.2.0rc0 (2023-04-16) + +### 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_release_candidate_version_with_merge_prerelease_alpha_.md b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_alpha_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_alpha_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_beta_.md b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_beta_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_beta_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_rc_.md b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_rc_.md new file mode 100644 index 0000000000..dca7824480 --- /dev/null +++ b/tests/commands/test_changelog_command/test_changelog_release_candidate_version_with_merge_prerelease_rc_.md @@ -0,0 +1,13 @@ +## Unreleased + +### Feat + +- add more stuff +- add new output + +### Fix + +- mama gotta work +- output glitch + +## 1.0.0 (1970-01-01) diff --git a/tests/test_changelog.py b/tests/test_changelog.py index e68a3abdcf..0aa9fdfbff 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -513,6 +513,17 @@ def test_get_commit_tag_is_None(gitcommits, tags): assert current_key is None +@pytest.mark.parametrize("test_input", TAGS) +def test_valid_tag_included_in_changelog(test_input): + tag = git.GitTag(*test_input) + assert changelog.tag_included_in_changelog(tag, [], False) + + +def test_invalid_tag_included_in_changelog(): + tag = git.GitTag("not_a_version", "rev", "date") + assert not changelog.tag_included_in_changelog(tag, [], False) + + COMMITS_TREE = ( { "version": "v1.2.0", @@ -789,15 +800,287 @@ def test_get_commit_tag_is_None(gitcommits, tags): }, ) +COMMITS_TREE_AFTER_MERGED_PRERELEASES = ( + { + "version": "v1.2.0", + "date": "2019-04-19", + "changes": { + "feat": [ + { + "scope": None, + "breaking": None, + "message": "custom cz plugins now support bumping version", + } + ] + }, + }, + { + "version": "v1.1.1", + "date": "2019-04-18", + "changes": { + "refactor": [ + { + "scope": None, + "breaking": None, + "message": "changed stdout statements", + }, + { + "scope": "schema", + "breaking": None, + "message": "command logic removed from commitizen base", + }, + { + "scope": "info", + "breaking": None, + "message": "command logic removed from commitizen base", + }, + { + "scope": "example", + "breaking": None, + "message": "command logic removed from commitizen base", + }, + { + "scope": "commit", + "breaking": None, + "message": "moved most of the commit logic to the commit command", + }, + ], + "fix": [ + { + "scope": "bump", + "breaking": None, + "message": "commit message now fits better with semver", + }, + { + "scope": None, + "breaking": None, + "message": "conventional commit 'breaking change' in body instead of title", + }, + ], + }, + }, + { + "version": "v1.1.0", + "date": "2019-04-14", + "changes": { + "feat": [ + { + "scope": None, + "breaking": None, + "message": "new working bump command", + }, + {"scope": None, "breaking": None, "message": "create version tag"}, + { + "scope": None, + "breaking": None, + "message": "update given files with new version", + }, + { + "scope": "config", + "breaking": None, + "message": "new set key, used to set version to cfg", + }, + { + "scope": None, + "breaking": None, + "message": "support for pyproject.toml", + }, + { + "scope": None, + "breaking": None, + "message": "first semantic version bump implementation", + }, + ], + "fix": [ + { + "scope": None, + "breaking": None, + "message": "removed all from commit", + }, + { + "scope": None, + "breaking": None, + "message": "fix config file not working", + }, + ], + "refactor": [ + { + "scope": None, + "breaking": None, + "message": "added commands folder, better integration with decli", + } + ], + }, + }, + { + "version": "v1.0.0", + "date": "2019-03-01", + "changes": { + "refactor": [ + { + "scope": None, + "breaking": None, + "message": "removed delegator, added decli and many tests", + } + ], + "feat": [ + { + "scope": None, + "breaking": None, + "message": "py3 only, tests and conventional commits 1.0", + } + ], + "BREAKING CHANGE": [ + {"scope": None, "breaking": None, "message": "API is stable"} + ], + }, + }, + { + "version": "v0.9.11", + "date": "2018-12-17", + "changes": { + "fix": [ + { + "scope": "config", + "breaking": None, + "message": "load config reads in order without failing if there is no commitizen section", + } + ] + }, + }, + { + "version": "v0.9.10", + "date": "2018-09-22", + "changes": { + "fix": [ + { + "scope": None, + "breaking": None, + "message": "parse scope (this is my punishment for not having tests)", + } + ] + }, + }, + { + "version": "v0.9.9", + "date": "2018-09-22", + "changes": { + "fix": [{"scope": None, "breaking": None, "message": "parse scope empty"}] + }, + }, + { + "version": "v0.9.8", + "date": "2018-09-22", + "changes": { + "fix": [ + { + "scope": "scope", + "breaking": None, + "message": "parse correctly again", + } + ] + }, + }, + { + "version": "v0.9.7", + "date": "2018-09-22", + "changes": { + "fix": [{"scope": "scope", "breaking": None, "message": "parse correctly"}] + }, + }, + { + "version": "v0.9.6", + "date": "2018-09-19", + "changes": { + "refactor": [ + { + "scope": "conventionalCommit", + "breaking": None, + "message": "moved filters to questions instead of message", + } + ], + "fix": [ + { + "scope": "manifest", + "breaking": None, + "message": "included missing files", + } + ], + }, + }, + { + "version": "v0.9.5", + "date": "2018-08-24", + "changes": { + "fix": [ + { + "scope": "config", + "breaking": None, + "message": "home path for python versions between 3.0 and 3.5", + } + ] + }, + }, + { + "version": "v0.9.4", + "date": "2018-08-02", + "changes": { + "feat": [{"scope": "cli", "breaking": None, "message": "added version"}] + }, + }, + { + "version": "v0.9.3", + "date": "2018-07-28", + "changes": { + "feat": [ + { + "scope": "committer", + "breaking": None, + "message": "conventional commit is a bit more intelligent now", + } + ] + }, + }, + { + "version": "v0.9.2", + "date": "2017-11-11", + "changes": { + "refactor": [ + { + "scope": None, + "breaking": None, + "message": "renamed conventional_changelog to conventional_commits, not backward compatible", + } + ] + }, + }, + { + "version": "v0.9.1", + "date": "2017-11-11", + "changes": { + "fix": [ + { + "scope": "setup.py", + "breaking": None, + "message": "future is now required for every python version", + } + ] + }, + }, +) + -def test_generate_tree_from_commits(gitcommits, tags): +@pytest.mark.parametrize("merge_prereleases", (True, False)) +def test_generate_tree_from_commits(gitcommits, tags, merge_prereleases): parser = defaults.commit_parser changelog_pattern = defaults.bump_pattern tree = changelog.generate_tree_from_commits( - gitcommits, tags, parser, changelog_pattern + gitcommits, tags, parser, changelog_pattern, merge_prerelease=merge_prereleases ) - - assert tuple(tree) == COMMITS_TREE + if merge_prereleases: + assert tuple(tree) == COMMITS_TREE_AFTER_MERGED_PRERELEASES + else: + assert tuple(tree) == COMMITS_TREE @pytest.mark.parametrize( diff --git a/tests/test_conf.py b/tests/test_conf.py index ff28f71144..df17a108ef 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -53,6 +53,7 @@ "changelog_file": "CHANGELOG.md", "changelog_incremental": False, "changelog_start_rev": None, + "changelog_merge_prerelease": False, "update_changelog_on_bump": False, "use_shortcuts": False, "major_version_zero": False, @@ -73,6 +74,7 @@ "changelog_file": "CHANGELOG.md", "changelog_incremental": False, "changelog_start_rev": None, + "changelog_merge_prerelease": False, "update_changelog_on_bump": False, "use_shortcuts": False, "major_version_zero": False, From 558af4b3a3992150641fbbf7fa258181234e63da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 13 Apr 2023 09:12:02 +0200 Subject: [PATCH 2/3] ci: update codecov to newest version --- .github/workflows/pythonpackage.yml | 2 +- poetry.lock | 20 ++------------------ pyproject.toml | 1 - 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 8bd764d96b..656abae054 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -30,7 +30,7 @@ jobs: shell: bash - name: Upload coverage to Codecov if: runner.os == 'Linux' - uses: codecov/codecov-action@v1.0.3 + uses: codecov/codecov-action@v3 with: token: ${{secrets.CODECOV_TOKEN}} file: ./coverage.xml diff --git a/poetry.lock b/poetry.lock index f7d7e797b3..33d1358a3c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. [[package]] name = "appnope" @@ -153,22 +153,6 @@ files = [ colorama = {version = "*", markers = "platform_system == \"Windows\""} importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} -[[package]] -name = "codecov" -version = "2.1.12" -description = "Hosted coverage reports for GitHub, Bitbucket and Gitlab" -category = "dev" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -files = [ - {file = "codecov-2.1.12-py2.py3-none-any.whl", hash = "sha256:585dc217dc3d8185198ceb402f85d5cb5dbfa0c5f350a5abcdf9e347776a5b47"}, - {file = "codecov-2.1.12.tar.gz", hash = "sha256:a0da46bb5025426da895af90938def8ee12d37fcbcbbbc15b6dc64cf7ebc51c1"}, -] - -[package.dependencies] -coverage = "*" -requests = ">=2.7.9" - [[package]] name = "colorama" version = "0.4.6" @@ -1523,4 +1507,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "12181f1e683c5555c8be62a7de363a6c89b179ca070fbd4f0c68519d9509e47d" +content-hash = "ddc808e77dc10ac4d6e9a373becc1090d35fe5234f0c02c8ec00415d36148e8e" diff --git a/pyproject.toml b/pyproject.toml index 8f45d30d61..0f98f57946 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,6 @@ ipython = "^7.2" pytest = "^7.2.0" pytest-cov = "^4.0" pytest-mock = "^3.10" -codecov = "^2.0" pytest-regressions = "^2.4.0" pytest-freezer = "^0.4.6" # code formatter From e34de55fdc7e5536aa879fbcda382095ad22b585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 13 Apr 2023 13:12:28 +0200 Subject: [PATCH 3/3] test(scripts): run same file tests individually Running tests concurrently can cause temporary files, such as the file used to backup the commit message, to be deleted by one test but accessed by another test later on. --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index d57bdddc48..aa1e50c318 100755 --- a/scripts/test +++ b/scripts/test @@ -4,7 +4,7 @@ set -e export PREFIX='poetry run python -m ' export REGEX='^(?![.]|venv).*' -${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ +${PREFIX}pytest -n 3 --dist=loadfile --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/