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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: "ubuntu-22.04"
tools:
python: "3.10"
python: "3.11"

python:
install:
Expand Down
877 changes: 877 additions & 0 deletions planning/plans/2026-06-07-httpware-migration.md

Large diffs are not rendered by default.

263 changes: 263 additions & 0 deletions planning/specs/2026-06-07-httpware-migration-design.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
name = "semvertag"
description = "Auto-tag GitLab repos with semantic version tags — one tool, two strategies."
authors = [{ name = "Artur Shiriev", email = "me@shiriev.ru" }]
requires-python = ">=3.10,<4"
requires-python = ">=3.11,<4"
license = "MIT"
readme = "README.md"
keywords = ["semver", "gitlab", "ci", "auto-tag", "conventional-commits"]
classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
Expand All @@ -23,6 +22,7 @@ dependencies = [
"pydantic-settings",
"modern-di-typer",
"httpx2",
"httpware[pydantic]",
]

[project.scripts]
Expand Down
84 changes: 0 additions & 84 deletions semvertag/_transport.py

This file was deleted.

46 changes: 21 additions & 25 deletions semvertag/ioc.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import typing

import httpx2
import httpware
import modern_di
from modern_di import Scope, providers

from semvertag._errors import ConfigError
from semvertag._settings import Settings
from semvertag._transport import RetryingTransport
from semvertag._use_case import SemvertagUseCase
from semvertag.providers._http import HttpClient
from semvertag.providers.gitlab import GitLabProvider, _translate_status, gitlab_auth_headers
from semvertag.providers.gitlab import GitLabProvider
from semvertag.strategies._base import BumpStrategy
from semvertag.strategies.branch_prefix import BranchPrefixStrategy
from semvertag.strategies.conventional_commits import ConventionalCommitsStrategy


def _build_gitlab_provider(settings: Settings, transport: httpx2.BaseTransport) -> GitLabProvider:
if settings.project_id is None:
msg = "Project id missing. Set CI_PROJECT_ID or pass --project-id."
raise ConfigError(msg)
project_id: typing.Final = settings.project_id
client: typing.Final = httpx2.Client(
transport=transport,
_TOKEN_HEADER: typing.Final = "PRIVATE-TOKEN"
_RETRY_STATUS_CODES: typing.Final = frozenset({408, 429, 500, 502, 503, 504})


def _build_gitlab_client(settings: Settings) -> httpware.Client:
return httpware.Client(
base_url=settings.gitlab.endpoint,
timeout=settings.request_timeout,
headers={_TOKEN_HEADER: settings.gitlab.token.get_secret_value()},
middleware=[httpware.Retry(retry_status_codes=_RETRY_STATUS_CODES)],
)
http: typing.Final = HttpClient(
client=client,
auth_headers=lambda: gitlab_auth_headers(settings.gitlab.token),
status_translator=lambda status: _translate_status(status, project_id),
)


def _build_gitlab_provider(settings: Settings, client: httpware.Client) -> GitLabProvider:
if settings.project_id is None:
msg = "Project id missing. Set CI_PROJECT_ID or pass --project-id."
raise ConfigError(msg)
return GitLabProvider(
config=settings.gitlab,
project_id=project_id,
http=http,
project_id=settings.project_id,
http=client,
)


Expand All @@ -52,22 +52,19 @@ def _build_current_strategy(settings: Settings) -> BumpStrategy:


def _close_provider_client(provider: GitLabProvider) -> None:
provider.http.client.close()
provider.http.close()


class SettingsGroup(modern_di.Group):
settings = providers.ContextProvider(scope=Scope.APP, context_type=Settings)


class TransportsGroup(modern_di.Group):
transport = providers.Factory(scope=Scope.APP, creator=RetryingTransport)


class ProvidersGroup(modern_di.Group):
gitlab_client = providers.Factory(scope=Scope.APP, creator=_build_gitlab_client)
gitlab_provider = providers.Factory(
scope=Scope.APP,
creator=_build_gitlab_provider,
kwargs={"transport": TransportsGroup.transport},
kwargs={"client": gitlab_client},
cache_settings=providers.CacheSettings(finalizer=_close_provider_client),
)

Expand All @@ -91,7 +88,6 @@ class UseCasesGroup(modern_di.Group):

ALL_GROUPS: typing.Final[list[type[modern_di.Group]]] = [
SettingsGroup,
TransportsGroup,
ProvidersGroup,
StrategiesGroup,
UseCasesGroup,
Expand Down
68 changes: 68 additions & 0 deletions semvertag/providers/_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import typing

import httpware

from semvertag._errors import AuthError, ConfigError, ProviderAPIError


_TAG_EXISTS_FRAGMENT: typing.Final = "already exists"


def _translate_gitlab_auth(exc: httpware.StatusError) -> Exception:
if isinstance(exc, httpware.UnauthorizedError):
return AuthError("Token rejected: 401. Verify SEMVERTAG_TOKEN is valid and has 'api' scope.")
return AuthError(
"Token missing scope or insufficient permission: 403. "
"Add 'api' or 'write_repository' to the SEMVERTAG_TOKEN scopes on GitLab."
)


def _translate_gitlab_status(exc: httpware.StatusError, *, project_id: int) -> Exception:
if isinstance(exc, (httpware.UnauthorizedError, httpware.ForbiddenError)):
return _translate_gitlab_auth(exc)
if isinstance(exc, httpware.NotFoundError):
return ConfigError(f"GitLab project not found: project_id={project_id}. Verify CI_PROJECT_ID or --project-id.")
if isinstance(exc, httpware.UnprocessableEntityError):
return ConfigError(
"Request rejected by GitLab: 422. Check tag name format and that the referenced commit exists."
)
if isinstance(exc, httpware.RateLimitedError):
return ProviderAPIError("GitLab rate limit: 429. Retries exhausted after 3 attempts; try again later.")
if isinstance(exc, httpware.ServerStatusError):
return ProviderAPIError(
f"GitLab API failure: {exc.response.status_code}. "
"Retries exhausted after 3 attempts. Try again or check GitLab status."
)
return ProviderAPIError(f"Unexpected GitLab response: {exc.response.status_code}. Please file an issue.")


def _translate_gitlab_transport(exc: httpware.ClientError) -> Exception:
if isinstance(exc, httpware.TimeoutError):
return ProviderAPIError("GitLab request timed out. Try again or increase SEMVERTAG_REQUEST_TIMEOUT.")
if isinstance(exc, httpware.RetryBudgetExhaustedError):
return ProviderAPIError(f"GitLab retries exhausted after {exc.attempts} attempts. Try again later.")
if isinstance(exc, httpware.NetworkError):
return ProviderAPIError("GitLab unreachable. Check network connectivity.")
return ProviderAPIError(f"GitLab request failed: {type(exc).__name__}")


def translate_gitlab(exc: httpware.ClientError, *, project_id: int) -> Exception:
"""
Translate an httpware ClientError into the semvertag domain error for GitLab.

Handles both status errors (4xx/5xx) and transport-layer failures
(network, timeout, retry budget exhaustion).
"""
if isinstance(exc, httpware.StatusError):
return _translate_gitlab_status(exc, project_id=project_id)
return _translate_gitlab_transport(exc)


def translate_create_tag_bad_request(exc: httpware.BadRequestError, *, tag_name: str) -> Exception:
"""create_tag's 400 has an 'already exists' special case; everything else is a generic 400."""
body = exc.response.text
if _TAG_EXISTS_FRAGMENT in body.lower():
return ConfigError(
f"Tag already exists: '{tag_name}'. The tag was created by a concurrent run or previous invocation."
)
return ConfigError("Request rejected by GitLab: 400. Check tag name format and that the referenced commit exists.")
62 changes: 0 additions & 62 deletions semvertag/providers/_http.py

This file was deleted.

Loading
Loading