-
-
Notifications
You must be signed in to change notification settings - Fork 304
fix(1694): changelog_merge_prerelease not working on cz bump #1700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9c98974
8516635
938f66a
73aa8a3
12e8d0b
747ed1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |
| from abc import ABCMeta | ||
| from typing import IO, TYPE_CHECKING, Any, ClassVar | ||
|
|
||
| from commitizen.changelog import Metadata | ||
| from commitizen.changelog import IncrementalMergeInfo, Metadata | ||
| from commitizen.config.base_config import BaseConfig | ||
| from commitizen.git import GitTag | ||
| from commitizen.tags import TagRules, VersionTag | ||
| from commitizen.version_schemes import get_version_scheme | ||
|
|
||
|
|
@@ -71,6 +73,29 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata: | |
|
|
||
| return meta | ||
|
|
||
| def get_latest_full_release(self, filepath: str) -> IncrementalMergeInfo: | ||
| if not os.path.isfile(filepath): | ||
| return IncrementalMergeInfo() | ||
|
|
||
| with open( | ||
| filepath, encoding=self.config.settings["encoding"] | ||
| ) as changelog_file: | ||
| return self.get_latest_full_release_from_file(changelog_file) | ||
|
|
||
| def get_latest_full_release_from_file(self, file: IO[Any]) -> IncrementalMergeInfo: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why extract this function? I don't see any benefits. You could put the whole function body under |
||
| latest_version_index: int | None = None | ||
| for index, line in enumerate(file): | ||
| latest_version_index = index | ||
| line = line.strip().lower() | ||
|
|
||
| parsed = self.parse_version_from_title(line) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you rename the variable Thanks! |
||
| if parsed: | ||
| if not self.tag_rules.extract_version( | ||
| GitTag(parsed.tag, "", "") | ||
| ).is_prerelease: | ||
|
Comment on lines
+92
to
+95
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine these |
||
| return IncrementalMergeInfo(name=parsed.tag, index=index) | ||
| return IncrementalMergeInfo(index=latest_version_index) | ||
|
|
||
| def parse_version_from_title(self, line: str) -> VersionTag | None: | ||
| """ | ||
| Extract the version from a title line if any | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -314,6 +314,8 @@ def __call__(self) -> None: | |
| "extras": self.extras, | ||
| "incremental": True, | ||
| "dry_run": dry_run, | ||
| "during_version_bump": self.arguments["prerelease"] | ||
| is None, # We let the changelog implementation know that we want to replace prereleases while staying incremental AND the new tag does not exist already | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is a bit unclear to me. |
||
| } | ||
| if self.changelog_to_stdout: | ||
| changelog_cmd = Changelog( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,3 +1705,73 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project): | |
| # Test case 4: No current tag, user denies | ||
| mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False)) | ||
| assert bump_cmd._is_initial_tag(None, is_yes=False) is False | ||
|
|
||
|
|
||
| @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") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| create_file_and_commit("irrelevant commit") | ||
| mocker.patch("commitizen.git.GitTag.date", "1970-01-01") | ||
| git.tag("0.1.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() | ||
|
|
||
| testargs = ["cz", "bump", "--changelog"] | ||
|
|
||
| mocker.patch.object(sys, "argv", testargs) | ||
| cli.main() | ||
|
|
||
| with open(changelog_path) as f: | ||
| out = f.read() | ||
| out = re.sub( | ||
| r" \([^)]*\)", "", out | ||
| ) # remove date from release, since I have no idea how to mock that | ||
|
|
||
| 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_only_prerelease_present( | ||
| mocker: MockFixture, changelog_path, config_path, file_regression, test_input | ||
| ): | ||
| # supposed to verify that logic regarding indexes is generic | ||
| with open(config_path, "a") as f: | ||
| f.write("changelog_merge_prerelease = true\n") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| create_file_and_commit("feat: more relevant commit") | ||
| testargs = ["cz", "bump", "--prerelease", test_input, "--yes"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
| cli.main() | ||
|
|
||
| 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() | ||
|
|
||
| testargs = ["cz", "bump", "--changelog"] | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove this blank line |
||
| mocker.patch.object(sys, "argv", testargs) | ||
| cli.main() | ||
|
|
||
| with open(changelog_path) as f: | ||
| out = f.read() | ||
| out = re.sub( | ||
| r" \([^)]*\)", "", out | ||
| ) # remove date from release, since I have no idea how to mock that | ||
|
|
||
| file_regression.check(out, extension=".md") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
| - more relevant commit | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
| - more relevant commit | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
| - more relevant commit | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ## 0.2.0 | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.