Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ jobs:
- "3.15"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
id: setup-python
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install uv
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
with:
python-version: ${{ matrix.python-version }}
version: ">=0.9.0"
- name: Install dependencies
env:
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
run: |
uv sync

- name: Run tests
run: |
uv run pytest

types:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install uv
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
with:
version: ">=0.9.0"
- name: Install dependencies
run: |
uv sync
- name: Check types with mypy
run: |
uv run mypy cz_version_bump tests
- name: Check types with ty
run: |
uv run ty check
11 changes: 8 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
rev: v0.15.9
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-check
args: [ --fix, --show-fixes ]
- id: ruff-format

- repo: https://github.com/hukkin/mdformat
rev: 1.0.0
hooks:
- id: mdformat
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

Commitizen customized for Meltano projects (https://commitizen-tools.github.io/commitizen/customization)


## Usage:

Install this Python package, and set the Commitizen config option `name` to `cz_version_bump`.

If using [`commitizen-action`](https://github.com/commitizen-tools/commitizen-action), this package can be installed using the `extra_requirements` option:


```yml
- name: Version bump
uses: commitizen-tools/commitizen-action@master
Expand Down
40 changes: 25 additions & 15 deletions cz_version_bump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from collections import OrderedDict
from textwrap import dedent
from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING, Any, ClassVar # noqa: F401

from commitizen import defaults, git
from commitizen.cz.base import BaseCommitizen
Expand All @@ -20,14 +20,16 @@
from typing_extensions import override

if TYPE_CHECKING:
from commitizen.defaults import Questions
from collections.abc import Mapping

from commitizen.question import CzQuestion

issue_id_pattern = re.compile(r"\s+\(#(\d+)\)$")


class MeltanoCommitizen(BaseCommitizen):
bump_pattern = r"^(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(\(.+\))?(!)?" # noqa: E501
bump_map: ClassVar = OrderedDict(
bump_map = OrderedDict( # noqa: RUF012
(
(
r"^break",
Expand All @@ -48,16 +50,6 @@ class MeltanoCommitizen(BaseCommitizen):
)
)
commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|break|docs|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?" # noqa: E501
schema_pattern = r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)" # noqa: E501
schema = dedent(
"""
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
(BREAKING CHANGE: )<footer>
"""
).strip("\n")
change_type_order = [ # noqa: RUF012
"BREAKING CHANGES",
"✨ New",
Expand Down Expand Up @@ -87,7 +79,25 @@ def __init__(self: MeltanoCommitizen, *args: Any, **kwargs: Any) -> None:
self.thanker = Thanker(self.repo_name)

@override
def questions(self: MeltanoCommitizen) -> Questions:
def schema(self: MeltanoCommitizen) -> str:
"""Schema definition of the commit message."""
return dedent(
"""
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
(BREAKING CHANGE: )<footer>
"""
).strip("\n")

@override
def schema_pattern(self: MeltanoCommitizen) -> str:
"""Regex matching the schema used for message validation."""
return r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)" # noqa: E501

@override
def questions(self: MeltanoCommitizen) -> list[CzQuestion]:
"""Questions regarding the commit message."""
return [
{
Expand Down Expand Up @@ -130,7 +140,7 @@ def questions(self: MeltanoCommitizen) -> Questions:
]

@override
def message(self: MeltanoCommitizen, answers: dict) -> str:
def message(self: MeltanoCommitizen, answers: Mapping[str, Any]) -> str:
"""Format the git message."""
message_template = Template("{{change_type}}: {{message}}")
return message_template.render(**answers)
Expand Down
2 changes: 1 addition & 1 deletion cz_version_bump/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def repo_name_from_git_remote() -> str:
git_remote_output = subprocess.run(
("git", "remote", "-v"),
("git", "remote", "-v"), # noqa: S607
stdout=subprocess.PIPE,
text=True,
check=False,
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ cz_version_bump = "cz_version_bump:MeltanoCommitizen"

[dependency-groups]
dev = [
{ include-group = "tests" },
{ include-group = "typing" },
]
tests = [
"pytest>=9",
"pytest-httpserver>=1",
]
typing = [
"mypy>=1.20.0",
"ty>=0.0.29",
{ include-group = "tests" },
]

[tool.hatch.build.targets.sdist]
include = ["cz_version_bump", "tests"]
Expand Down
Loading