Fixed Git integration

This commit is contained in:
2026-06-09 15:57:59 +03:00
parent 19d8e50505
commit 2c86a634bb
3 changed files with 31 additions and 5 deletions
+3 -2
View File
@@ -30,8 +30,9 @@ GITEA_TOKEN=your_gitea_api_token
GITEA_PUBLIC_URL=https://git.grigowashere.ru GITEA_PUBLIC_URL=https://git.grigowashere.ru
GITEA_WEBHOOK_SECRET=generate_a_random_secret GITEA_WEBHOOK_SECRET=generate_a_random_secret
# Gitea webhook URL (configure in repo settings; use BACKEND_PORT from host): # Gitea webhook URL (repo Settings → Webhooks):
# http://127.0.0.1:8202/api/v1/webhooks/gitea # 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 REPOS_DIR=/data/repos
+6 -1
View File
@@ -132,11 +132,16 @@ curl -X PUT http://localhost:8080/api/v1/projects/home-assistant/gitea \
В репозитории: **Settings → Webhooks → Add Webhook**: В репозитории: **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` - Content type: `application/json`
- Secret: значение `GITEA_WEBHOOK_SECRET` - Secret: значение `GITEA_WEBHOOK_SECRET`
- Events: **Push** - Events: **Push**
Проверка из контейнера Gitea: `docker exec gitea wget -qO- http://172.17.0.1:8202/api/v1/health`
Test delivery в Gitea должен вернуть **200**, не **0**.
### Автозакрытие по коммиту ### Автозакрытие по коммиту
В сообщении коммита: В сообщении коммита:
+22 -2
View File
@@ -1,6 +1,7 @@
import hashlib import hashlib
import hmac import hmac
import json import json
import logging
from typing import Any from typing import Any
from fastapi import APIRouter, Depends, HTTPException, Request 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 from app.projects.service import ProjectService
router = APIRouter() router = APIRouter()
logger = logging.getLogger(__name__)
def _verify_gitea_signature(body: bytes, signature: str | None, secret: str) -> bool: 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: if not binding:
return {"ok": True, "skipped": "unknown repo"} 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) service = ProjectService(db)
results = service.process_push(owner, repo_name, commits) 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) _post_close_notice(results, owner, repo_name)
return {"ok": True, "results": results} return {"ok": True, "results": results, "commits_processed": len(commits)}