freeleaps-ops/apps/gitea-webhook-ambassador-python/app/handlers/webhook.py
Nicolas f6c515157c feat: 添加 Python 版本的 Gitea Webhook Ambassador
- 新增完整的 Python 实现,替代 Go 版本
- 添加 Web 登录界面和仪表板
- 实现 JWT 认证和 API 密钥管理
- 添加数据库存储功能
- 保持与 Go 版本一致的目录结构和启动脚本
- 包含完整的文档和测试脚本
2025-07-20 21:17:10 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Webhook 处理器
处理来自 Gitea 的 webhook 请求
"""
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:
"""获取 webhook 服务实例"""
# 这里应该从依赖注入容器获取
# 暂时返回 None实际使用时需要正确实现
return None
@router.post("/gitea")
async def handle_gitea_webhook(
request: Request,
webhook_service: WebhookService = Depends(get_webhook_service)
):
"""处理 Gitea webhook 请求"""
if webhook_service is None:
raise HTTPException(status_code=503, detail="Webhook service not available")
try:
# 获取请求体
body = await request.body()
# 处理 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))