diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 884fe1663a..e624b37579 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,4 +3,5 @@ blank_issues_enabled: false contact_links: - name: Security Contact + url: https://github.com/woile about: Please report security vulnerabilities to santiwilly@gmail.com diff --git a/commitizen/cli.py b/commitizen/cli.py index ed4305ea1f..e9689d75f3 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -543,6 +543,18 @@ def __call__( "action": "store_true", "exclusive_group": "group1", }, + { + "name": ["--major"], + "help": "get just the major version", + "action": "store_true", + "exclusive_group": "group2", + }, + { + "name": ["--minor"], + "help": "get just the minor version", + "action": "store_true", + "exclusive_group": "group2", + }, ], }, ], diff --git a/commitizen/commands/version.py b/commitizen/commands/version.py index 35e9aa6cd6..04fa664f25 100644 --- a/commitizen/commands/version.py +++ b/commitizen/commands/version.py @@ -5,14 +5,17 @@ from commitizen import out from commitizen.__version__ import __version__ from commitizen.config import BaseConfig -from commitizen.exceptions import NoVersionSpecifiedError +from commitizen.exceptions import NoVersionSpecifiedError, VersionSchemeUnknown from commitizen.providers import get_provider +from commitizen.version_schemes import get_version_scheme class VersionArgs(TypedDict, total=False): report: bool project: bool verbose: bool + major: bool + minor: bool class Version: @@ -41,6 +44,17 @@ def __call__(self) -> None: out.error("No project information in this project.") return + try: + version_scheme = get_version_scheme(self.config.settings) + except VersionSchemeUnknown: + out.error("Unknown version scheme.") + _version = version_scheme(version) + + if self.parameter.get("major"): + version = f"{_version.major}" + elif self.parameter.get("minor"): + version = f"{_version.minor}" + out.write(f"Project Version: {version}" if verbose else version) return diff --git a/commitizen/version_schemes.py b/commitizen/version_schemes.py index e9f99c5514..0696d85aa5 100644 --- a/commitizen/version_schemes.py +++ b/commitizen/version_schemes.py @@ -410,7 +410,9 @@ def _get_prerelease(self) -> str: def get_version_scheme(settings: Settings, name: str | None = None) -> VersionScheme: """ Get the version scheme as defined in the configuration - or from an overridden `name` + or from an overridden `name`. + + :raises VersionSchemeUnknown: if the version scheme is not found. """ diff --git a/docs/contributing.md b/docs/contributing.md index 8389e9370d..16db930626 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -38,7 +38,7 @@ If you're a first-time contributor, please check out issues labeled [good first ```bash git remote add upstream https://github.com/commitizen-tools/commitizen.git ``` -4. Set up the development environment: +4. Set up the development environment (nix users go to [nix section](#nix)): ```bash poetry install ``` @@ -70,6 +70,7 @@ If you're a first-time contributor, please check out issues labeled [good first 5. **Documentation** - Update `docs/README.md` if needed - For CLI help screenshots: `poetry doc:screenshots` + - Prefer [Google style documentation](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings), which works well with editors like VSCode and PyCharm - **DO NOT** update `CHANGELOG.md` (automatically generated) - **DO NOT** update version numbers (automatically handled) 6. **Pull Request** @@ -153,3 +154,16 @@ flowchart TD --modification-received--> review ``` + +## Nix + +If you have installed poetry globally, the project won't work because it requires `poethepoet` for command management. + +You'll have to install poetry locally. + +```sh +python -m venv .venv +. .venv/bin/activate +pip install -U pip && pip install poetry +poetry install +``` diff --git a/docs/contributing_tldr.md b/docs/contributing_tldr.md index f5483cddcd..9eecc3efa0 100644 --- a/docs/contributing_tldr.md +++ b/docs/contributing_tldr.md @@ -12,7 +12,7 @@ Please check the [pyproject.toml](https://github.com/commitizen-tools/commitizen ### Code Changes ```bash -# Ensure you have the correct dependencies +# Ensure you have the correct dependencies, for nix user's see below poetry install # Make ruff happy @@ -35,3 +35,14 @@ pytest -n auto # Build the documentation locally and check for broken links poetry doc ``` + +### Nix Users + +If you are using Nix, you can install poetry locally by running: + +```sh +python -m venv .venv +. .venv/bin/activate +pip install -U pip && pip install poetry +poetry install +``` diff --git a/docs/images/cli_help/cz_version___help.svg b/docs/images/cli_help/cz_version___help.svg index c7777db4df..7ddec177d8 100644 --- a/docs/images/cli_help/cz_version___help.svg +++ b/docs/images/cli_help/cz_version___help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + - + - + - - $ cz version --help -usage: cz version [-h][-r | -p | -c | -v] - -get the version of the installed commitizen or the current project (default: -installed commitizen) - -options: -  -h, --help        show this help message and exit -  -r, --report      get system information for reporting bugs -  -p, --project     get the version of the current project -  -c, --commitizen  get the version of the installed commitizen -  -v, --verbose     get the version of both the installed commitizen and the -                    current project - + + $ cz version --help +usage: cz version [-h][-r | -p | -c | -v][--major | --minor] + +get the version of the installed commitizen or the current project (default: +installed commitizen) + +options: +  -h, --help        show this help message and exit +  -r, --report      get system information for reporting bugs +  -p, --project     get the version of the current project +  -c, --commitizen  get the version of the installed commitizen +  -v, --verbose     get the version of both the installed commitizen and the +                    current project +  --major           get just the major version +  --minor           get just the minor version + diff --git a/tests/commands/test_version_command.py b/tests/commands/test_version_command.py index 3dcbed168b..cd2e7f77e0 100644 --- a/tests/commands/test_version_command.py +++ b/tests/commands/test_version_command.py @@ -119,3 +119,40 @@ def test_version_command_shows_description_when_use_help_option( out, _ = capsys.readouterr() file_regression.check(out, extension=".txt") + + +@pytest.mark.parametrize( + "version, expected_version", (("1.0.0", "1\n"), ("2.1.3", "2\n"), ("0.0.1", "0\n")) +) +def test_version_just_major(config, capsys, version: str, expected_version: str): + config.settings["version"] = version + commands.Version( + config, + { + "report": False, + "project": True, + "verbose": False, + "major": True, + }, + )() + captured = capsys.readouterr() + assert expected_version == captured.out + + +@pytest.mark.parametrize( + "version, expected_version", + (("1.0.0", "0\n"), ("2.1.3", "1\n"), ("0.0.1", "0\n"), ("0.1.0", "1\n")), +) +def test_version_just_minor(config, capsys, version: str, expected_version: str): + config.settings["version"] = version + commands.Version( + config, + { + "report": False, + "project": True, + "verbose": False, + "minor": True, + }, + )() + captured = capsys.readouterr() + assert expected_version == captured.out diff --git a/tests/commands/test_version_command/test_version_command_shows_description_when_use_help_option.txt b/tests/commands/test_version_command/test_version_command_shows_description_when_use_help_option.txt index c461b10bcd..b1ed94124e 100644 --- a/tests/commands/test_version_command/test_version_command_shows_description_when_use_help_option.txt +++ b/tests/commands/test_version_command/test_version_command_shows_description_when_use_help_option.txt @@ -1,4 +1,4 @@ -usage: cz version [-h] [-r | -p | -c | -v] +usage: cz version [-h] [-r | -p | -c | -v] [--major | --minor] get the version of the installed commitizen or the current project (default: installed commitizen) @@ -10,3 +10,5 @@ options: -c, --commitizen get the version of the installed commitizen -v, --verbose get the version of both the installed commitizen and the current project + --major get just the major version + --minor get just the minor version