Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 345
Feat/next version#2036
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
Uh oh!
There was an error while loading. Please reload this page.
Feat/next version #2036
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,14 +4,20 @@ | ||
| from packaging.version import InvalidVersion | ||
| from commitizen import out | ||
| from commitizen import bump, factory, git, out | ||
| from commitizen.__version__ import __version__ | ||
| from commitizen.config import BaseConfig | ||
| from commitizen.exceptions import NoVersionSpecifiedError, VersionSchemeUnknown | ||
| from commitizen.exceptions import ( | ||
| NoCommitsFoundError, | ||
| NoPatternMapError, | ||
| NotAGitProjectError, | ||
| NoVersionSpecifiedError, | ||
| VersionSchemeUnknown, | ||
| ) | ||
| from commitizen.providers import get_provider | ||
| from commitizen.tags import TagRules | ||
| from commitizen.version_increment import VersionIncrement | ||
| from commitizen.version_schemes import Increment, get_version_scheme | ||
| from commitizen.version_schemes import Increment, VersionProtocol, get_version_scheme | ||
| class VersionArgs(TypedDict, total=False): | ||
| @@ -63,6 +69,9 @@ def __call__(self) -> None: | ||
| or self.arguments.get("next") | ||
| or self.arguments.get("manual_version") | ||
| ): | ||
| # TODO: once `cz --version` is implemented, move `self.cz` back to __init__ | ||
| self.cz = factory.committer_factory(self.config) | ||
| version_str = self.arguments.get("manual_version") | ||
| if version_str is None: | ||
| try: | ||
| @@ -84,11 +93,15 @@ def __call__(self) -> None: | ||
| if next_increment_str := self.arguments.get("next"): | ||
| if next_increment_str == "USE_GIT_COMMITS": | ||
| # Only check under `git` to allow the user to do stuff like | ||
| # `cz version 1.2.3 --major` | ||
| if not git.is_git_project(): | ||
| raise NotAGitProjectError() | ||
| # TODO: implement USE_GIT_COMMITS by deriving the increment from | ||
| # git history. This requires refactoring the bump logic out of | ||
| # `commitizen/commands/bump.py` so it can be reused here. See #1678. | ||
| out.error("--next USE_GIT_COMMITS is not implemented yet.") | ||
| return | ||
| version = self._get_next_git_version(version) | ||
| next_increment = VersionIncrement.from_value(next_increment_str) | ||
| increment: Increment | None | ||
| @@ -100,6 +113,9 @@ def __call__(self) -> None: | ||
| increment = "MINOR" | ||
| else: | ||
| increment = "MAJOR" | ||
| # TODO: Consider adding all the parameters `.bump` supports: | ||
| # prerelease, prerelease_offset,exact_increment, etc... | ||
| version = version.bump(increment=increment) | ||
| if self.arguments.get("major"): | ||
| @@ -139,3 +155,39 @@ def __call__(self) -> None: | ||
| # If no arguments are provided, just show the installed commitizen version | ||
| out.write(__version__) | ||
| def _get_next_git_version( | ||
| self, current_version: VersionProtocol | ||
| ) -> VersionProtocol: | ||
| """Calculate the next version based on commits.""" | ||
| rules = TagRules.from_settings(self.config.settings) | ||
| current_tag = rules.find_tag_for(git.get_tags(), current_version) | ||
| commits = git.get_commits(current_tag.name if current_tag else None) | ||
woile marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # No commits, there is no need to create an empty tag. | ||
| # Unless we previously had a prerelease. | ||
| if not commits and not current_version.is_prerelease: | ||
| raise NoCommitsFoundError("[NO_COMMITS_FOUND]\nNo new commits found.") | ||
woile marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| bump_map = ( | ||
| self.cz.bump_map_major_version_zero | ||
| if self.config.settings["major_version_zero"] | ||
| else self.cz.bump_map | ||
| ) | ||
| bump_pattern = self.cz.bump_pattern | ||
| if not bump_map or not bump_pattern: | ||
| raise NoPatternMapError( | ||
| f"'{self.config.settings['name']}' rule does not support bump" | ||
| ) | ||
| increment = bump.find_increment( | ||
| commits, regex=bump_pattern, increments_map=bump_map | ||
| ) | ||
| # TODO: Consider adding all the parameters `.bump` supports: | ||
| # prerelease, prerelease_offset,exact_increment, etc.. | ||
| new_version = current_version.bump( | ||
| increment, | ||
| ) | ||
| return new_version | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.