Skip to content

Commit 0109952

Browse files
fix: Update for Commitizen v4 (#123)
1 parent daaffec commit 0109952

9 files changed

Lines changed: 1014 additions & 935 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "pip"
8+
- package-ecosystem: "uv"
99
directory: "/"
1010
schedule:
1111
interval: "weekly"

.github/workflows/resources/constraints.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/test.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,43 @@ on:
66
pull_request:
77
workflow_dispatch:
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
FORCE_COLOR: "1"
15+
916
jobs:
1017
pytest:
1118
name: Pytest
1219
runs-on: ubuntu-latest
1320
strategy:
1421
matrix:
1522
python-version:
16-
- "3.9"
1723
- "3.10"
1824
- "3.11"
1925
- "3.12"
2026
- "3.13"
27+
- "3.14"
28+
- "3.15"
2129
steps:
22-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23-
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
30+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
31+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
32+
id: setup-python
2433
with:
2534
python-version: ${{ matrix.python-version }}
2635
allow-prereleases: true
27-
- name: Install Poetry
28-
env:
29-
PIP_CONSTRAINT: ${{ github.workspace }}/.github/workflows/resources/constraints.txt
30-
run: |
31-
pipx install poetry
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@5a7eac68fb9809dea845d802897dc5c723910fa3 # v7.1.3
38+
with:
39+
version: ">=0.9.0"
3240
- name: Install dependencies
41+
env:
42+
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
3343
run: |
34-
poetry env use ${{ matrix.python-version }}
35-
poetry install
44+
uv sync
3645
3746
- name: Run tests
3847
run: |
39-
poetry run pytest
48+
uv run pytest

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,30 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# General
132+
.DS_Store
133+
__MACOSX/
134+
.AppleDouble
135+
.LSOverride
136+
Icon[
137+
]
138+
139+
# Thumbnails
140+
._*
141+
142+
# Files that might appear in the root of a volume
143+
.DocumentRevisions-V100
144+
.fseventsd
145+
.Spotlight-V100
146+
.TemporaryItems
147+
.Trashes
148+
.VolumeIcon.icns
149+
.com.apple.timemachine.donotpresent
150+
151+
# Directories potentially created on remote AFP share
152+
.AppleDB
153+
.AppleDesktop
154+
Network Trash Folder
155+
Temporary Items
156+
.apdisk

cz_version_bump/__init__.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22

33
import os
44
import re
5-
import typing as t
5+
import sys
66
from collections import OrderedDict
77
from textwrap import dedent
8-
9-
try:
10-
from jinja2 import Template
11-
except ImportError:
12-
from string import Template
8+
from typing import TYPE_CHECKING, Any, ClassVar
139

1410
from commitizen import defaults, git
1511
from commitizen.cz.base import BaseCommitizen
12+
from jinja2 import Template
1613

1714
from cz_version_bump.git import repo_name_from_git_remote
1815
from cz_version_bump.thanks import Thanker
1916

20-
if t.TYPE_CHECKING:
17+
if sys.version_info >= (3, 12):
18+
from typing import override
19+
else:
20+
from typing_extensions import override
21+
22+
if TYPE_CHECKING:
2123
from commitizen.defaults import Questions
2224

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

2527

2628
class MeltanoCommitizen(BaseCommitizen):
2729
bump_pattern = r"^(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(\(.+\))?(!)?" # noqa: E501
28-
bump_map: t.ClassVar = OrderedDict(
30+
bump_map: ClassVar = OrderedDict(
2931
(
3032
(
3133
r"^break",
@@ -75,13 +77,16 @@ class MeltanoCommitizen(BaseCommitizen):
7577
"packaging": "📦 Packaging changes",
7678
}
7779

78-
def __init__(self: MeltanoCommitizen, *args: t.Any, **kwargs: t.Any) -> None:
80+
@override
81+
def __init__(self: MeltanoCommitizen, *args: Any, **kwargs: Any) -> None:
7982
super().__init__(*args, **kwargs)
8083
self.repo_name = os.environ.get(
81-
"GITHUB_REPOSITORY", repo_name_from_git_remote()
84+
"GITHUB_REPOSITORY",
85+
repo_name_from_git_remote(),
8286
)
8387
self.thanker = Thanker(self.repo_name)
8488

89+
@override
8590
def questions(self: MeltanoCommitizen) -> Questions:
8691
"""Questions regarding the commit message."""
8792
return [
@@ -124,16 +129,16 @@ def questions(self: MeltanoCommitizen) -> Questions:
124129
},
125130
]
126131

132+
@override
127133
def message(self: MeltanoCommitizen, answers: dict) -> str:
128134
"""Format the git message."""
129135
message_template = Template("{{change_type}}: {{message}}")
130-
if getattr(Template, "substitute", None):
131-
return message_template.substitute(**answers)
132136
return message_template.render(**answers)
133137

138+
@override
134139
def changelog_message_builder_hook(
135140
self: MeltanoCommitizen,
136-
parsed_message: dict[str, str],
141+
parsed_message: dict[str, Any],
137142
commit: git.GitCommit,
138143
) -> dict:
139144
"""Alter each git log line of the changelog.
@@ -176,6 +181,7 @@ def changelog_message_builder_hook(
176181

177182
return parsed_message
178183

184+
@override
179185
def changelog_hook(
180186
self: MeltanoCommitizen,
181187
full_changelog: str,
@@ -190,3 +196,11 @@ def changelog_hook(
190196
The full changelog.
191197
"""
192198
return full_changelog
199+
200+
@override
201+
def example(self: MeltanoCommitizen) -> str:
202+
return "feat: Add a new feature"
203+
204+
@override
205+
def info(self: MeltanoCommitizen) -> str:
206+
return "Commitizen customized for Meltano projects (https://commitizen-tools.github.io/commitizen/customization)"

cz_version_bump/thanks.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def __init__(
3232
"thanks for first-party contributors",
3333
stacklevel=2,
3434
)
35-
self.agent = Github(auth=Auth.Token(github_token), base_url=base_url)
35+
auth = None
36+
else:
37+
auth = Auth.Token(github_token)
38+
39+
self.agent = Github(auth=auth, base_url=base_url)
3640
self.repo = self.agent.get_repo(repo_name)
3741
# NOTE: The org object obtained from `self.repo.organization` has the wrong URL,
3842
# so we retrieve it using `get_organization` instead to get one that isn't
@@ -74,9 +78,8 @@ def co_authors(self: Thanker, commit_message: str) -> Iterable[str]:
7478
if line.startswith("Co-authored-by: ")
7579
}
7680
for line in co_author_lines:
77-
yield self.email_to_github_username(
78-
self.co_author_pattern.search(line).group(1)
79-
)
81+
if match := self.co_author_pattern.search(line):
82+
yield self.email_to_github_username(match.group(1))
8083

8184
# TODO: This method should use memoization - https://pypi.org/project/methodtools/
8285
def email_to_github_username(self: Thanker, email: str) -> str:

0 commit comments

Comments
 (0)