feat: add integrations API endpoint with Gitea support

This commit is contained in:
Ricel Leite 2026-02-19 00:46:37 -03:00
parent 25e5ac36c6
commit 5a18ddd836
2 changed files with 70 additions and 1 deletions

View File

@ -8,7 +8,7 @@ from fastapi.responses import HTMLResponse
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
import os 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 from app.services.database import init_db
@asynccontextmanager @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(projects.router, prefix="/api/projects", tags=["projects"])
app.include_router(tickets.router, prefix="/api/tickets", tags=["tickets"]) app.include_router(tickets.router, prefix="/api/tickets", tags=["tickets"])
app.include_router(webhooks.router, prefix="/api/webhooks", tags=["webhooks"]) app.include_router(webhooks.router, prefix="/api/webhooks", tags=["webhooks"])
app.include_router(integrations.router, prefix="/api/integrations", tags=["integrations"])
# Professional Frontend # Professional Frontend
HTML = """<!DOCTYPE html> HTML = """<!DOCTYPE html>

View File

@ -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"}