Taiga integration

This commit is contained in:
2026-06-09 12:47:13 +03:00
parent c8599b3d13
commit 1f83dcb574
30 changed files with 1543 additions and 115 deletions
+54
View File
@@ -0,0 +1,54 @@
from typing import Any
import httpx
from app.config import get_settings
class GiteaClient:
def __init__(self) -> None:
settings = get_settings()
self.base_url = settings.gitea_base_url.rstrip("/")
self.public_url = settings.gitea_public_url.rstrip("/")
self.token = settings.gitea_token
def _client(self) -> httpx.Client:
return httpx.Client(
base_url=self.base_url,
timeout=30.0,
headers={
"Authorization": f"token {self.token}",
"Content-Type": "application/json",
},
)
def create_issue(
self,
owner: str,
repo: str,
title: str,
body: str,
labels: list[str] | None = None,
) -> dict[str, Any]:
payload: dict[str, Any] = {"title": title, "body": body}
if labels:
payload["labels"] = labels
with self._client() as client:
response = client.post(
f"/api/v1/repos/{owner}/{repo}/issues",
json=payload,
)
response.raise_for_status()
return response.json()
def close_issue(self, owner: str, repo: str, issue_number: int) -> dict[str, Any]:
with self._client() as client:
response = client.patch(
f"/api/v1/repos/{owner}/{repo}/issues/{issue_number}",
json={"state": "closed"},
)
response.raise_for_status()
return response.json()
def issue_url(self, owner: str, repo: str, issue_number: int) -> str:
return f"{self.public_url}/{owner}/{repo}/issues/{issue_number}"