Taiga integration
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import get_db
|
||||
from app.projects.service import ProjectService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class GiteaBinding(BaseModel):
|
||||
gitea_owner: str = Field(min_length=1)
|
||||
gitea_repo: str = Field(min_length=1)
|
||||
default_branch: str = "main"
|
||||
|
||||
|
||||
class WorkItemCreate(BaseModel):
|
||||
text: str = Field(min_length=1)
|
||||
project_slug: str | None = None
|
||||
|
||||
|
||||
@router.get("/projects")
|
||||
def list_projects(db: Session = Depends(get_db)) -> list[dict[str, Any]]:
|
||||
return ProjectService(db).list_projects()
|
||||
|
||||
|
||||
@router.post("/projects/sync-taiga")
|
||||
def sync_taiga_projects(db: Session = Depends(get_db)) -> list[dict[str, Any]]:
|
||||
try:
|
||||
return ProjectService(db).sync_taiga_projects()
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@router.put("/projects/{taiga_slug}/gitea")
|
||||
def bind_gitea(
|
||||
taiga_slug: str,
|
||||
payload: GiteaBinding,
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return ProjectService(db).bind_gitea(
|
||||
taiga_slug,
|
||||
payload.gitea_owner,
|
||||
payload.gitea_repo,
|
||||
payload.default_branch,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@router.post("/work-items")
|
||||
async def create_work_item(
|
||||
payload: WorkItemCreate,
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return await ProjectService(db).create_work_item(
|
||||
payload.text,
|
||||
project_slug=payload.project_slug,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@router.get("/work-items")
|
||||
def list_work_items(
|
||||
limit: int = 30,
|
||||
status: str | None = None,
|
||||
db: Session = Depends(get_db),
|
||||
) -> list[dict[str, Any]]:
|
||||
return ProjectService(db).list_work_items(limit=limit, status=status)
|
||||
Reference in New Issue
Block a user