Fixed Git integration
This commit is contained in:
+2
-2
@@ -30,8 +30,8 @@ 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):
|
# Gitea webhook URL (configure in repo settings; use BACKEND_PORT from host):
|
||||||
# http://127.0.0.1:8080/api/v1/webhooks/gitea
|
# http://127.0.0.1:8202/api/v1/webhooks/gitea
|
||||||
|
|
||||||
REPOS_DIR=/data/repos
|
REPOS_DIR=/data/repos
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,11 @@ def _post_close_notice(results: list[dict[str, Any]], owner: str, repo: str) ->
|
|||||||
async def gitea_webhook(request: Request, db: Session = Depends(get_db)) -> dict[str, Any]:
|
async def gitea_webhook(request: Request, db: Session = Depends(get_db)) -> dict[str, Any]:
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
signature = request.headers.get("X-Gitea-Signature")
|
signature = (
|
||||||
|
request.headers.get("X-Gitea-Signature")
|
||||||
|
or request.headers.get("X-Gogs-Signature")
|
||||||
|
or request.headers.get("X-Hub-Signature-256")
|
||||||
|
)
|
||||||
|
|
||||||
if not _verify_gitea_signature(body, signature, settings.gitea_webhook_secret):
|
if not _verify_gitea_signature(body, signature, settings.gitea_webhook_secret):
|
||||||
raise HTTPException(status_code=401, detail="Invalid webhook signature")
|
raise HTTPException(status_code=401, detail="Invalid webhook signature")
|
||||||
|
|||||||
@@ -278,25 +278,38 @@ class ProjectService:
|
|||||||
|
|
||||||
for item in linked_items:
|
for item in linked_items:
|
||||||
if item.gitea_issue_number == gitea_num:
|
if item.gitea_issue_number == gitea_num:
|
||||||
self._close_work_item(item, taiga)
|
try:
|
||||||
results.append(
|
self._close_work_item(item, taiga)
|
||||||
{
|
results.append(
|
||||||
"commit": sha,
|
{
|
||||||
"closed": f"gitea #{gitea_num}, taiga #{item.taiga_story_ref}",
|
"commit": sha,
|
||||||
}
|
"closed": f"gitea #{gitea_num}, taiga #{item.taiga_story_ref}",
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
results.append(
|
||||||
|
{"error": f"work item {item.id} (gitea #{gitea_num}): {exc}"}
|
||||||
|
)
|
||||||
|
|
||||||
for ref in taiga_story_refs:
|
for ref in taiga_story_refs:
|
||||||
project_id = self._project_id_for_ref(owner, repo, ref, linked_items)
|
project_id = self._project_id_for_ref(owner, repo, ref, linked_items)
|
||||||
if not project_id:
|
if not project_id:
|
||||||
continue
|
continue
|
||||||
story = taiga.get_by_ref(project_id, ref, kind="userstory")
|
story = taiga.get_by_ref(project_id, ref, kind="userstory")
|
||||||
if story:
|
if story and not story.get("is_closed"):
|
||||||
taiga.close_userstory(story["id"], project_id)
|
try:
|
||||||
|
taiga.close_userstory(story["id"], project_id)
|
||||||
|
results.append({"commit": sha, "closed": f"taiga #{ref}"})
|
||||||
|
except Exception as exc:
|
||||||
|
results.append({"error": f"taiga #{ref}: {exc}"})
|
||||||
for item in linked_items:
|
for item in linked_items:
|
||||||
if item.taiga_story_ref == ref:
|
if item.taiga_story_ref == ref and item.status != "closed":
|
||||||
self._close_work_item(item, taiga, close_gitea=bool(gitea))
|
try:
|
||||||
results.append({"commit": sha, "closed": f"taiga #{ref}"})
|
self._close_work_item(item, taiga, close_gitea=bool(gitea))
|
||||||
|
except Exception as exc:
|
||||||
|
results.append(
|
||||||
|
{"error": f"work item {item.id} (taiga #{ref}): {exc}"}
|
||||||
|
)
|
||||||
|
|
||||||
for ref in taiga_task_refs:
|
for ref in taiga_task_refs:
|
||||||
binding = self.db.scalar(
|
binding = self.db.scalar(
|
||||||
@@ -313,9 +326,12 @@ class ProjectService:
|
|||||||
if not taiga_proj:
|
if not taiga_proj:
|
||||||
continue
|
continue
|
||||||
task = taiga.get_by_ref(taiga_proj.taiga_id, ref, kind="task")
|
task = taiga.get_by_ref(taiga_proj.taiga_id, ref, kind="task")
|
||||||
if task:
|
if task and not task.get("is_closed"):
|
||||||
taiga.close_task(task["id"], taiga_proj.taiga_id)
|
try:
|
||||||
results.append({"commit": sha, "closed": f"taiga task #{ref}"})
|
taiga.close_task(task["id"], taiga_proj.taiga_id)
|
||||||
|
results.append({"commit": sha, "closed": f"taiga task #{ref}"})
|
||||||
|
except Exception as exc:
|
||||||
|
results.append({"error": f"taiga task #{ref}: {exc}"})
|
||||||
|
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return results
|
return results
|
||||||
|
|||||||
Reference in New Issue
Block a user