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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "pip"
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/resources/constraints.txt

This file was deleted.

31 changes: 20 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,43 @@ on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: "1"

jobs:
pytest:
name: Pytest
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
- "3.15"
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
id: setup-python
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install Poetry
env:
PIP_CONSTRAINT: ${{ github.workspace }}/.github/workflows/resources/constraints.txt
run: |
pipx install poetry
- name: Install uv
uses: astral-sh/setup-uv@5a7eac68fb9809dea845d802897dc5c723910fa3 # v7.1.3
with:
version: ">=0.9.0"
- name: Install dependencies
env:
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
run: |
poetry env use ${{ matrix.python-version }}
poetry install
uv sync

- name: Run tests
run: |
poetry run pytest
uv run pytest
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,30 @@ dmypy.json

# Pyre type checker
.pyre/

# General
.DS_Store
__MACOSX/
.AppleDouble
.LSOverride
Icon[
]

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
40 changes: 27 additions & 13 deletions cz_version_bump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

import os
import re
import typing as t
import sys
from collections import OrderedDict
from textwrap import dedent

try:
from jinja2 import Template
except ImportError:
from string import Template
from typing import TYPE_CHECKING, Any, ClassVar

from commitizen import defaults, git
from commitizen.cz.base import BaseCommitizen
from jinja2 import Template

from cz_version_bump.git import repo_name_from_git_remote
from cz_version_bump.thanks import Thanker

if t.TYPE_CHECKING:
if sys.version_info >= (3, 12):
from typing import override
else:
from typing_extensions import override

if TYPE_CHECKING:
from commitizen.defaults import Questions

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: t.ClassVar = OrderedDict(
bump_map: ClassVar = OrderedDict(
(
(
r"^break",
Expand Down Expand Up @@ -75,13 +77,16 @@ class MeltanoCommitizen(BaseCommitizen):
"packaging": "📦 Packaging changes",
}

def __init__(self: MeltanoCommitizen, *args: t.Any, **kwargs: t.Any) -> None:
@override
def __init__(self: MeltanoCommitizen, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.repo_name = os.environ.get(
"GITHUB_REPOSITORY", repo_name_from_git_remote()
"GITHUB_REPOSITORY",
repo_name_from_git_remote(),
)
self.thanker = Thanker(self.repo_name)

@override
def questions(self: MeltanoCommitizen) -> Questions:
"""Questions regarding the commit message."""
return [
Expand Down Expand Up @@ -124,16 +129,16 @@ def questions(self: MeltanoCommitizen) -> Questions:
},
]

@override
def message(self: MeltanoCommitizen, answers: dict) -> str:
"""Format the git message."""
message_template = Template("{{change_type}}: {{message}}")
if getattr(Template, "substitute", None):
return message_template.substitute(**answers)
return message_template.render(**answers)

@override
def changelog_message_builder_hook(
self: MeltanoCommitizen,
parsed_message: dict[str, str],
parsed_message: dict[str, Any],
commit: git.GitCommit,
) -> dict:
"""Alter each git log line of the changelog.
Expand Down Expand Up @@ -176,6 +181,7 @@ def changelog_message_builder_hook(

return parsed_message

@override
def changelog_hook(
self: MeltanoCommitizen,
full_changelog: str,
Expand All @@ -190,3 +196,11 @@ def changelog_hook(
The full changelog.
"""
return full_changelog

@override
def example(self: MeltanoCommitizen) -> str:
return "feat: Add a new feature"

@override
def info(self: MeltanoCommitizen) -> str:
return "Commitizen customized for Meltano projects (https://commitizen-tools.github.io/commitizen/customization)"
11 changes: 7 additions & 4 deletions cz_version_bump/thanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def __init__(
"thanks for first-party contributors",
stacklevel=2,
)
self.agent = Github(auth=Auth.Token(github_token), base_url=base_url)
auth = None
else:
auth = Auth.Token(github_token)

self.agent = Github(auth=auth, base_url=base_url)
self.repo = self.agent.get_repo(repo_name)
# NOTE: The org object obtained from `self.repo.organization` has the wrong URL,
# so we retrieve it using `get_organization` instead to get one that isn't
Expand Down Expand Up @@ -74,9 +78,8 @@ def co_authors(self: Thanker, commit_message: str) -> Iterable[str]:
if line.startswith("Co-authored-by: ")
}
for line in co_author_lines:
yield self.email_to_github_username(
self.co_author_pattern.search(line).group(1)
)
if match := self.co_author_pattern.search(line):
yield self.email_to_github_username(match.group(1))

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