diff --git a/commitizen/bump.py b/commitizen/bump.py index 2351dbd7ec..09e573edb1 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -44,7 +44,7 @@ def find_increment( if increment == MAJOR: break - return cast(Increment, increment) + return None if increment is None else Increment[increment] def update_version_in_files( diff --git a/commitizen/cli.py b/commitizen/cli.py index 1d1ebe1f68..b8f761fa41 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -244,7 +244,7 @@ def __call__( { "name": ["--prerelease", "-pr"], "help": "choose type of prerelease", - "choices": ["alpha", "beta", "rc"], + "choices": ["alpha", "beta", "rc", "none"], }, { "name": ["--devrelease", "-d"], diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 8497384665..545f2f6626 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -152,7 +152,7 @@ def __call__(self) -> None: # noqa: C901 dry_run: bool = self.arguments["dry_run"] is_yes: bool = self.arguments["yes"] increment: Increment | None = self.arguments["increment"] - prerelease: Prerelease | None = self.arguments["prerelease"] + prerelease: Prerelease | None = None if self.arguments["prerelease"] == "none" else self.arguments["prerelease"] devrelease: int | None = self.arguments["devrelease"] is_files_only: bool | None = self.arguments["files_only"] is_local_version: bool = self.arguments["local_version"] diff --git a/commitizen/version_schemes.py b/commitizen/version_schemes.py index 26a19ec1b1..e145bebec6 100644 --- a/commitizen/version_schemes.py +++ b/commitizen/version_schemes.py @@ -1,5 +1,6 @@ from __future__ import annotations +import enum import re import sys import warnings @@ -37,11 +38,23 @@ from typing import Self -Increment: TypeAlias = Literal["MAJOR", "MINOR", "PATCH"] -Prerelease: TypeAlias = Literal["alpha", "beta", "rc"] DEFAULT_VERSION_PARSER = r"v?(?P([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)" +class Increment(enum.StrEnum): + MAJOR = "MAJOR" + MINOR = "MINOR" + PATCH = "PATCH" + + +class Prerelease(enum.StrEnum): + alpha = "alpha" + beta = "beta" + rc = "rc" + none = "none" + + + @runtime_checkable class VersionProtocol(Protocol): parser: ClassVar[re.Pattern]