From 3fb234b2cda02ce7ade62de241669f0138d5207e Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Tue, 7 Apr 2026 10:30:12 +0100 Subject: [PATCH] post 'working on it' placeholder, edit with response when done --- gitea.py | 10 ++++++++++ main.py | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/gitea.py b/gitea.py index dd29057..ae02f5f 100644 --- a/gitea.py +++ b/gitea.py @@ -41,6 +41,16 @@ class GiteaClient: r.raise_for_status() return r.json() + async def edit_comment(self, owner: str, repo: str, comment_id: int, body: str): + async with httpx.AsyncClient() as c: + r = await c.patch( + f"{self.base}/repos/{owner}/{repo}/issues/comments/{comment_id}", + headers=self.headers, + json={"body": body}, + ) + r.raise_for_status() + return r.json() + async def add_reaction(self, owner: str, repo: str, comment_id: int, reaction: str): async with httpx.AsyncClient() as c: r = await c.post( diff --git a/main.py b/main.py index 662ecd6..724e1ed 100644 --- a/main.py +++ b/main.py @@ -148,10 +148,13 @@ async def process_mention( trigger_comment: dict | None, comment_id: int | None, ): + wip_comment_id = None try: - # React to acknowledge - if comment_id: - await gitea.add_reaction(owner, repo, comment_id, "eyes") + # Post "working on it" placeholder + wip = await gitea.create_comment( + owner, repo, issue_number, "⏳ Working on it…" + ) + wip_comment_id = wip["id"] # Set up workspace rp = await ensure_repo(owner, repo, issue_number) @@ -186,17 +189,18 @@ async def process_mention( prompt = build_prompt(owner, repo, issue, comments, trigger_comment, attachments, pr_info) response = await run_claude(prompt, str(rp)) - # Post response - await gitea.create_comment(owner, repo, issue_number, response) + # Edit placeholder with actual response + await gitea.edit_comment(owner, repo, wip_comment_id, response) log.info(f"Responded to {owner}/{repo}#{issue_number}") except Exception: log.exception(f"Error processing {owner}/{repo}#{issue_number}") + error_msg = "*An error occurred while processing this request. Check bot logs for details.*" try: - await gitea.create_comment( - owner, repo, issue_number, - "*An error occurred while processing this request. Check bot logs for details.*", - ) + if wip_comment_id: + await gitea.edit_comment(owner, repo, wip_comment_id, error_msg) + else: + await gitea.create_comment(owner, repo, issue_number, error_msg) except Exception: log.exception("Failed to post error comment")