Fixed Git integration
This commit is contained in:
+3
-2
@@ -30,8 +30,9 @@ GITEA_TOKEN=your_gitea_api_token
|
||||
GITEA_PUBLIC_URL=https://git.grigowashere.ru
|
||||
GITEA_WEBHOOK_SECRET=generate_a_random_secret
|
||||
|
||||
# Gitea webhook URL (configure in repo settings; use BACKEND_PORT from host):
|
||||
# http://127.0.0.1:8202/api/v1/webhooks/gitea
|
||||
# Gitea webhook URL (repo Settings → Webhooks):
|
||||
# https://assistant.your-domain/api/v1/webhooks/gitea ← nginx → 127.0.0.1:BACKEND_PORT
|
||||
# http://172.17.0.1:8202/api/v1/webhooks/gitea ← если Gitea в Docker (не 127.0.0.1!)
|
||||
|
||||
REPOS_DIR=/data/repos
|
||||
|
||||
|
||||
@@ -132,11 +132,16 @@ curl -X PUT http://localhost:8080/api/v1/projects/home-assistant/gitea \
|
||||
|
||||
В репозитории: **Settings → Webhooks → Add Webhook**:
|
||||
|
||||
- URL: `http://127.0.0.1:8080/api/v1/webhooks/gitea`
|
||||
- URL (выбери один вариант):
|
||||
- **Рекомендуется:** `https://assistant.example.com/api/v1/webhooks/gitea` — nginx → `127.0.0.1:${BACKEND_PORT}`
|
||||
- **Если Gitea в Docker:** `http://172.17.0.1:${BACKEND_PORT}/api/v1/webhooks/gitea` — не `127.0.0.1` (это localhost контейнера Gitea)
|
||||
- Content type: `application/json`
|
||||
- Secret: значение `GITEA_WEBHOOK_SECRET`
|
||||
- Events: **Push**
|
||||
|
||||
Проверка из контейнера Gitea: `docker exec gitea wget -qO- http://172.17.0.1:8202/api/v1/health`
|
||||
Test delivery в Gitea должен вернуть **200**, не **0**.
|
||||
|
||||
### Автозакрытие по коммиту
|
||||
|
||||
В сообщении коммита:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
@@ -13,6 +14,7 @@ from app.db.models import ChatSession, Message, ProjectBinding
|
||||
from app.projects.service import ProjectService
|
||||
|
||||
router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _verify_gitea_signature(body: bytes, signature: str | None, secret: str) -> bool:
|
||||
@@ -90,9 +92,27 @@ async def gitea_webhook(request: Request, db: Session = Depends(get_db)) -> dict
|
||||
if not binding:
|
||||
return {"ok": True, "skipped": "unknown repo"}
|
||||
|
||||
commits = payload.get("commits") or []
|
||||
commits = list(payload.get("commits") or [])
|
||||
if not commits:
|
||||
head = payload.get("head_commit")
|
||||
if head:
|
||||
commits = [head]
|
||||
|
||||
logger.info(
|
||||
"Gitea push %s/%s ref=%s commits=%d",
|
||||
owner,
|
||||
repo_name,
|
||||
payload.get("ref", ""),
|
||||
len(commits),
|
||||
)
|
||||
|
||||
service = ProjectService(db)
|
||||
results = service.process_push(owner, repo_name, commits)
|
||||
if results:
|
||||
logger.info("Gitea push results: %s", results)
|
||||
else:
|
||||
logger.warning("Gitea push: no close actions for %s/%s", owner, repo_name)
|
||||
|
||||
_post_close_notice(results, owner, repo_name)
|
||||
|
||||
return {"ok": True, "results": results}
|
||||
return {"ok": True, "results": results, "commits_processed": len(commits)}
|
||||
|
||||
Reference in New Issue
Block a user