freeleaps-ops/apps/gitea-webhook-ambassador-python/app/handlers/webhook.py

42 lines
1.2 KiB
Python

"""
Webhook handler
Handles webhook requests from Gitea
"""
from fastapi import APIRouter, Depends, HTTPException, Request
from app.services.webhook_service import WebhookService
from app.services.dedup_service import DeduplicationService
from app.tasks.jenkins_tasks import get_celery_app
router = APIRouter()
def get_webhook_service() -> WebhookService:
"""Get webhook service instance"""
# Should get from dependency injection container
# Temporarily return None, implement properly in actual use
return None
@router.post("/gitea")
async def handle_gitea_webhook(
request: Request,
webhook_service: WebhookService = Depends(get_webhook_service)
):
"""Handle Gitea webhook request"""
if webhook_service is None:
raise HTTPException(status_code=503, detail="Webhook service not available")
try:
# Get request body
body = await request.body()
# Process webhook
result = await webhook_service.process_webhook(body, request.headers)
return {
"success": True,
"message": "Webhook processed successfully",
"data": result
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))