-
-
Notifications
You must be signed in to change notification settings - Fork 300
feat(bump): add functionality to write the next version to stdout #1195
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
Changes from all commits
476be78
6068a82
5f3ba4a
008c652
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| BumpTagFailedError, | ||
| DryRunExit, | ||
| ExpectedExit, | ||
| GetNextExit, | ||
| InvalidManualVersion, | ||
| NoCommitsFoundError, | ||
| NoneIncrementExit, | ||
|
|
@@ -159,6 +160,7 @@ def __call__(self) -> None: # noqa: C901 | |
| manual_version = self.arguments["manual_version"] | ||
| build_metadata = self.arguments["build_metadata"] | ||
| increment_mode: str = self.arguments["increment_mode"] | ||
| get_next: bool = self.arguments["get_next"] | ||
|
|
||
| if manual_version: | ||
| if increment: | ||
|
|
@@ -190,6 +192,9 @@ def __call__(self) -> None: # noqa: C901 | |
| "--prerelease-offset cannot be combined with MANUAL_VERSION" | ||
| ) | ||
|
|
||
| if get_next: | ||
| raise NotAllowed("--get-next cannot be combined with MANUAL_VERSION") | ||
|
|
||
| if major_version_zero: | ||
| if not current_version.release[0] == 0: | ||
| raise NotAllowed( | ||
|
|
@@ -202,6 +207,18 @@ def __call__(self) -> None: # noqa: C901 | |
| "--local-version cannot be combined with --build-metadata" | ||
| ) | ||
|
|
||
| # If user specified changelog_to_stdout, they probably want the | ||
| # changelog to be generated as well, this is the most intuitive solution | ||
| self.changelog = self.changelog or bool(self.changelog_to_stdout) | ||
|
|
||
| if get_next: | ||
| if self.changelog: | ||
| raise NotAllowed( | ||
| "--changelog or --changelog-to-stdout is not allowed with --get-next" | ||
| ) | ||
| # Setting dry_run to prevent any unwanted changes to the repo or files | ||
| self.dry_run = True | ||
|
Contributor
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. Is
Member
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.
Contributor
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.
I have tested in my local environment. The assignment is redundant and the |
||
|
|
||
| current_tag_version: str = bump.normalize_tag( | ||
| current_version, | ||
| tag_format=tag_format, | ||
|
|
@@ -210,10 +227,6 @@ def __call__(self) -> None: # noqa: C901 | |
|
|
||
| is_initial = self.is_initial_tag(current_tag_version, is_yes) | ||
|
|
||
| # If user specified changelog_to_stdout, they probably want the | ||
| # changelog to be generated as well, this is the most intuitive solution | ||
| self.changelog = self.changelog or bool(self.changelog_to_stdout) | ||
|
|
||
| if manual_version: | ||
| try: | ||
| new_version = self.scheme(manual_version) | ||
|
|
@@ -266,6 +279,16 @@ def __call__(self) -> None: # noqa: C901 | |
| current_version, new_version, bump_commit_message | ||
| ) | ||
|
|
||
| if get_next: | ||
| if increment is None and new_tag_version == current_tag_version: | ||
| raise NoneIncrementExit( | ||
| "[NO_COMMITS_TO_BUMP]\n" | ||
| "The commits found are not eligible to be bumped" | ||
| ) | ||
|
|
||
| out.write(str(new_version)) | ||
| raise GetNextExit() | ||
|
|
||
| # Report found information | ||
| information = f"{message}\n" f"tag to create: {new_tag_version}\n" | ||
| if increment: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| DryRunExit, | ||
| ExitCode, | ||
| ExpectedExit, | ||
| GetNextExit, | ||
| InvalidManualVersion, | ||
| NoCommitsFoundError, | ||
| NoneIncrementExit, | ||
|
|
@@ -1462,3 +1463,63 @@ def test_bump_command_shows_description_when_use_help_option( | |
|
|
||
| out, _ = capsys.readouterr() | ||
| file_regression.check(out, extension=".txt") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_get_next(mocker: MockFixture, capsys): | ||
| create_file_and_commit("feat: new file") | ||
|
|
||
| testargs = ["cz", "bump", "--yes", "--get-next"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
| with pytest.raises(GetNextExit): | ||
| cli.main() | ||
|
|
||
| out, _ = capsys.readouterr() | ||
| assert "0.2.0" in out | ||
|
|
||
| tag_exists = git.tag_exist("0.2.0") | ||
| assert tag_exists is False | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_get_next__changelog_is_not_allowed(mocker: MockFixture): | ||
|
Member
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. I feel we can combine these |
||
| create_file_and_commit("feat: new file") | ||
|
|
||
| testargs = ["cz", "bump", "--yes", "--get-next", "--changelog"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
|
|
||
| with pytest.raises(NotAllowed): | ||
| cli.main() | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_get_next__changelog_to_stdout_is_not_allowed(mocker: MockFixture): | ||
| create_file_and_commit("feat: new file") | ||
|
|
||
| testargs = ["cz", "bump", "--yes", "--get-next", "--changelog-to-stdout"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
|
|
||
| with pytest.raises(NotAllowed): | ||
| cli.main() | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_get_next__manual_version_is_not_allowed(mocker: MockFixture): | ||
| create_file_and_commit("feat: new file") | ||
|
|
||
| testargs = ["cz", "bump", "--yes", "--get-next", "0.2.1"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
|
|
||
| with pytest.raises(NotAllowed): | ||
| cli.main() | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_get_next__no_eligible_commits_raises(mocker: MockFixture): | ||
| create_file_and_commit("chore: new commit") | ||
|
|
||
| testargs = ["cz", "bump", "--yes", "--get-next"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
|
|
||
| with pytest.raises(NoneIncrementExit): | ||
| cli.main() | ||
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.
Probably not required in this PR, but I feel we could move these validations out as a separate function 🤔