From 5a18ddd8363ce57500581eea2be7ffb3af971e48 Mon Sep 17 00:00:00 2001 From: Ricel Leite Date: Thu, 19 Feb 2026 00:46:37 -0300 Subject: [PATCH] feat: add integrations API endpoint with Gitea support --- backend/app/main.py | 3 +- backend/app/routers/integrations.py | 68 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 backend/app/routers/integrations.py diff --git a/backend/app/main.py b/backend/app/main.py index 344a2c5..24bd753 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -8,7 +8,7 @@ from fastapi.responses import HTMLResponse from contextlib import asynccontextmanager import os -from app.routers import tickets, projects, webhooks, health +from app.routers import tickets, projects, webhooks, health, integrations from app.services.database import init_db @asynccontextmanager @@ -36,6 +36,7 @@ app.include_router(health.router, prefix="/api", tags=["health"]) app.include_router(projects.router, prefix="/api/projects", tags=["projects"]) app.include_router(tickets.router, prefix="/api/tickets", tags=["tickets"]) app.include_router(webhooks.router, prefix="/api/webhooks", tags=["webhooks"]) +app.include_router(integrations.router, prefix="/api/integrations", tags=["integrations"]) # Professional Frontend HTML = """ diff --git a/backend/app/routers/integrations.py b/backend/app/routers/integrations.py new file mode 100644 index 0000000..feccda6 --- /dev/null +++ b/backend/app/routers/integrations.py @@ -0,0 +1,68 @@ +"""Integration management endpoints.""" +from typing import List, Dict, Any +from fastapi import APIRouter, HTTPException +from pydantic import BaseModel + +router = APIRouter() + +class IntegrationCreate(BaseModel): + name: str + type: str # gitea, jira_fixer, github, etc + base_url: str + api_token: str + enabled: bool = True + +class IntegrationRead(BaseModel): + id: int + name: str + type: str + base_url: str + enabled: bool + last_sync: str = None + +# Mock data for now (will use database later) +INTEGRATIONS: List[Dict[str, Any]] = [ + { + "id": 1, + "name": "JIRA AI Fixer", + "type": "jira_fixer", + "base_url": "https://jira-fixer.startdata.com.br", + "enabled": True, + "last_sync": None + } +] + +@router.get("/", response_model=List[IntegrationRead]) +async def list_integrations(): + """List all integrations.""" + return INTEGRATIONS + +@router.post("/", response_model=IntegrationRead, status_code=201) +async def create_integration(integration: IntegrationCreate): + """Create new integration.""" + new_id = max([i["id"] for i in INTEGRATIONS], default=0) + 1 + new_integration = { + "id": new_id, + "name": integration.name, + "type": integration.type, + "base_url": integration.base_url, + "enabled": integration.enabled, + "last_sync": None + } + INTEGRATIONS.append(new_integration) + return new_integration + +@router.get("/{integration_id}", response_model=IntegrationRead) +async def get_integration(integration_id: int): + """Get integration by ID.""" + for integration in INTEGRATIONS: + if integration["id"] == integration_id: + return integration + raise HTTPException(status_code=404, detail="Integration not found") + +@router.delete("/{integration_id}") +async def delete_integration(integration_id: int): + """Delete integration.""" + global INTEGRATIONS + INTEGRATIONS = [i for i in INTEGRATIONS if i["id"] != integration_id] + return {"message": "Integration deleted"}