post 'working on it' placeholder, edit with response when done

This commit is contained in:
Fam Zheng 2026-04-07 10:30:12 +01:00
parent c3bb4ad2f9
commit 3fb234b2cd
2 changed files with 23 additions and 9 deletions

View File

@ -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(

22
main.py
View File

@ -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")