- 新增完整的 Python 实现,替代 Go 版本 - 添加 Web 登录界面和仪表板 - 实现 JWT 认证和 API 密钥管理 - 添加数据库存储功能 - 保持与 Go 版本一致的目录结构和启动脚本 - 包含完整的文档和测试脚本
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""
|
||
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)) |