Skip to content

Commit

Permalink
chore: Update from upstream, v3.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sandzhaj committed Dec 16, 2023
2 parents 04285c0 + 06e3b4c commit 6a67de8
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@woile
@Lee-W
@noirbizarre
8 changes: 3 additions & 5 deletions .github/workflows/bumpversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ jobs:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
changelog_increment_filename: body.md
- name: Release
uses: softprops/action-gh-release@v1
uses: ncipollo/release-action@v1
with:
body_path: "body.md"
tag_name: ${{ env.REVISION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ env.REVISION }}
bodyFile: "body.md"
2 changes: 1 addition & 1 deletion .github/workflows/label_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
issues: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
- uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
exclude: "poetry.lock"

- repo: https://github.com/czplus-tools/commitizen-plus
rev: v0.1.0 # automatically updated by Commitizen
rev: v0.2.0 # automatically updated by Commitizen
hooks:
- id: commitizen
- id: commitizen-branch
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@

## v3.13.0 (2023-12-03)

### Feat

- **commands-bump**: automatically create annotated tag if message is given
- add tag message argument to cli
- **git**: add get tag message function
- add custom message to annotated git tag

### Fix

- **test-bump-command**: typo in --annotated-tag option inside test
- **commitizen-git**: add quotes for tag message

### Refactor

- **commands-bump**: make changelog variable in 1 line
- **commands-bump**: cast str to bool

## v3.12.0 (2023-10-18)

### Feat
Expand Down
2 changes: 1 addition & 1 deletion commitizen/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.2.0"
5 changes: 5 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ def __call__(
"help": "create annotated tag instead of lightweight one",
"action": "store_true",
},
{
"name": ["--annotated-tag-message", "-atm"],
"help": "create annotated tag message",
"type": str,
},
{
"name": ["--gpg-sign", "-s"],
"help": "sign tag instead of lightweight one",
Expand Down
9 changes: 6 additions & 3 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
"bump_message",
"gpg_sign",
"annotated_tag",
"annotated_tag_message",
"major_version_zero",
"prerelease_offset",
"template",
Expand Down Expand Up @@ -197,8 +198,7 @@ def __call__(self): # noqa: C901

# If user specified changelog_to_stdout, they probably want the
# changelog to be generated as well, this is the most intuitive solution
if not self.changelog and self.changelog_to_stdout:
self.changelog = True
self.changelog = self.changelog or bool(self.changelog_to_stdout)

# No commits, there is no need to create an empty tag.
# Unless we previously had a prerelease.
Expand Down Expand Up @@ -365,7 +365,10 @@ def __call__(self): # noqa: C901
signed=self.bump_settings.get("gpg_sign", False)
or bool(self.config.settings.get("gpg_sign", False)),
annotated=self.bump_settings.get("annotated_tag", False)
or bool(self.config.settings.get("annotated_tag", False)),
or bool(self.config.settings.get("annotated_tag", False))
or bool(self.bump_settings.get("annotated_tag_message", False)),
msg=self.bump_settings.get("annotated_tag_message", None),
# TODO: also get from self.config.settings?
)
if c.return_code != 0:
raise BumpTagFailedError(c.err)
Expand Down
17 changes: 15 additions & 2 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ def from_line(cls, line: str, inner_delimiter: str) -> GitTag:
return cls(name=name, rev=obj, date=date)


def tag(tag: str, annotated: bool = False, signed: bool = False) -> cmd.Command:
def tag(
tag: str, annotated: bool = False, signed: bool = False, msg: str | None = None
) -> cmd.Command:
_opt = ""
if annotated:
_opt = f"-a {tag} -m"
if signed:
_opt = f"-s {tag} -m"
c = cmd.run(f"git tag {_opt} {tag}")

# according to https://git-scm.com/book/en/v2/Git-Basics-Tagging,
# we're not able to create lightweight tag with message.
# by adding message, we make it a annotated tags
c = cmd.run(f'git tag {_opt} "{tag if _opt == "" or msg is None else msg}"')
return c


Expand Down Expand Up @@ -200,6 +206,13 @@ def get_latest_tag_name() -> str | None:
return c.out.strip()


def get_tag_message(tag: str) -> str | None:
c = cmd.run(f"git tag -l --format='%(contents:subject)' {tag}")
if c.err:
return None
return c.out.strip()


def get_tag_names() -> list[str | None]:
c = cmd.run("git tag --list")
if c.err:
Expand Down
38 changes: 16 additions & 22 deletions docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ Some examples of pep440:

```bash
$ cz bump --help
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
[--check-consistency] [--annotated-tag] [--gpg-sign]
[--changelog-to-stdout] [--git-output-to-stderr] [--retry] [--major-version-zero]
[--template TEMPLATE] [--extra EXTRA]
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] [--no-verify] [--yes] [--tag-format TAG_FORMAT]
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
[--check-consistency] [--annotated-tag] [--gpg-sign] [--changelog-to-stdout] [--git-output-to-stderr] [--retry] [--major-version-zero]
[--prerelease-offset PRERELEASE_OFFSET] [--version-scheme {semver,pep440}] [--version-type {semver,pep440}]
[MANUAL_VERSION]

positional arguments:
Expand All @@ -70,24 +67,20 @@ options:
--files-only bump version in the files from the config
--local-version bump only the local version portion
--changelog, -ch generate the changelog for the newest version
--no-verify this option bypasses the pre-commit and commit-msg
hooks
--no-verify this option bypasses the pre-commit and commit-msg hooks
--yes accept automatically questions done
--tag-format TAG_FORMAT
the format used to tag the commit and read it, use it
in existing projects, wrap around simple quotes
the format used to tag the commit and read it, use it in existing projects, wrap around simple quotes
--bump-message BUMP_MESSAGE
template used to create the release commit, useful
when working with CI
template used to create the release commit, useful when working with CI
--prerelease {alpha,beta,rc}, -pr {alpha,beta,rc}
choose type of prerelease
--devrelease DEVRELEASE, -d DEVRELEASE
specify non-negative integer for dev. release
--increment {MAJOR,MINOR,PATCH}
manually specify the desired increment
--check-consistency, -cc
check consistency among versions defined in commitizen
configuration and version_files
check consistency among versions defined in commitizen configuration and version_files
--annotated-tag, -at create annotated tag instead of lightweight one
--gpg-sign, -s sign tag instead of lightweight one
--changelog-to-stdout
Expand All @@ -96,14 +89,12 @@ options:
Redirect git output to stderr
--retry retry commit if it fails the 1st time
--major-version-zero keep major version at zero, even for breaking changes
--prerelease-offset start pre-releases with this offset
--version-scheme {pep440,semver}
--prerelease-offset PRERELEASE_OFFSET
start pre-releases with this offset
--version-scheme {semver,pep440}
choose version scheme

--template TEMPLATE, -t TEMPLATE
changelog template file name (relative to the current working directory)
--extra EXTRA, -e EXTRA
a changelog extra variable (in the form 'key=value')
--version-type {semver,pep440}
Deprecated, use --version-scheme
```
### `--files-only`
Expand Down Expand Up @@ -184,6 +175,9 @@ If `--local-version` is used, it will bump only the local version `0.1.0` and ke
If `--annotated-tag` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`.
### `--annotated-tag-message`
If `--annotated-tag-message` is used, commitizen will create annotated tags with the given message.
### `--changelog-to-stdout`
If `--changelog-to-stdout` is used, the incremental changelog generated by the bump
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.commitizen]
version = "0.1.0"
version = "0.2.0"
tag_format = "v$version"
version_files = [
"pyproject.toml:version",
Expand All @@ -9,7 +9,7 @@ version_files = [

[tool.poetry]
name = "commitizen-plus"
version = "0.1.0"
version = "0.2.0"
description = "Python commitizen client tool"
authors = ["Santiago Fraire <santiwilly@gmail.com>", "Mark Minakov <maminakov@vk.ru>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def test_bump_with_git_to_stdout_arg(mocker: MockFixture, capsys, changelog_path
"bump",
"--changelog",
"--changelog-to-stdout",
"--annotated",
"--annotated-tag",
"--check-consistency",
"--yes",
),
Expand Down
15 changes: 14 additions & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import inspect
import os
import platform
import shutil

import pytest
from commitizen import cmd, exceptions, git
from pytest_mock import MockFixture

from tests.utils import FakeCommand, create_file_and_commit
from tests.utils import FakeCommand, create_file_and_commit, create_tag


def test_git_object_eq():
Expand Down Expand Up @@ -239,3 +240,15 @@ def test_eoltypes_get_eol_for_open():
assert git.EOLTypes.get_eol_for_open(git.EOLTypes.NATIVE) == os.linesep
assert git.EOLTypes.get_eol_for_open(git.EOLTypes.LF) == "\n"
assert git.EOLTypes.get_eol_for_open(git.EOLTypes.CRLF) == "\r\n"


def test_create_tag_with_message(tmp_commitizen_project):
with tmp_commitizen_project.as_cwd():
create_file_and_commit("feat(test): test")
tag_name = "1.0"
tag_message = "test message"
create_tag(tag_name, tag_message)
assert git.get_latest_tag_name() == tag_name
assert git.get_tag_message(tag_name) == (
tag_message if platform.system() != "Windows" else f"'{tag_message}'"
)
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def get_current_branch() -> str:
return c.out


def create_tag(tag: str):
c = git.tag(tag)
def create_tag(tag: str, message: str | None = None) -> None:
c = git.tag(tag, annotated=(message is not None), msg=message)
if c.return_code != 0:
raise exceptions.CommitError(c.err)

Expand Down

0 comments on commit 6a67de8

Please sign in to comment.