post 'working on it' placeholder, edit with response when done
This commit is contained in:
parent
c3bb4ad2f9
commit
3fb234b2cd
10
gitea.py
10
gitea.py
@ -41,6 +41,16 @@ class GiteaClient:
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json()
|
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 def add_reaction(self, owner: str, repo: str, comment_id: int, reaction: str):
|
||||||
async with httpx.AsyncClient() as c:
|
async with httpx.AsyncClient() as c:
|
||||||
r = await c.post(
|
r = await c.post(
|
||||||
|
|||||||
22
main.py
22
main.py
@ -148,10 +148,13 @@ async def process_mention(
|
|||||||
trigger_comment: dict | None,
|
trigger_comment: dict | None,
|
||||||
comment_id: int | None,
|
comment_id: int | None,
|
||||||
):
|
):
|
||||||
|
wip_comment_id = None
|
||||||
try:
|
try:
|
||||||
# React to acknowledge
|
# Post "working on it" placeholder
|
||||||
if comment_id:
|
wip = await gitea.create_comment(
|
||||||
await gitea.add_reaction(owner, repo, comment_id, "eyes")
|
owner, repo, issue_number, "⏳ Working on it…"
|
||||||
|
)
|
||||||
|
wip_comment_id = wip["id"]
|
||||||
|
|
||||||
# Set up workspace
|
# Set up workspace
|
||||||
rp = await ensure_repo(owner, repo, issue_number)
|
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)
|
prompt = build_prompt(owner, repo, issue, comments, trigger_comment, attachments, pr_info)
|
||||||
response = await run_claude(prompt, str(rp))
|
response = await run_claude(prompt, str(rp))
|
||||||
|
|
||||||
# Post response
|
# Edit placeholder with actual response
|
||||||
await gitea.create_comment(owner, repo, issue_number, response)
|
await gitea.edit_comment(owner, repo, wip_comment_id, response)
|
||||||
log.info(f"Responded to {owner}/{repo}#{issue_number}")
|
log.info(f"Responded to {owner}/{repo}#{issue_number}")
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception(f"Error processing {owner}/{repo}#{issue_number}")
|
log.exception(f"Error processing {owner}/{repo}#{issue_number}")
|
||||||
|
error_msg = "*An error occurred while processing this request. Check bot logs for details.*"
|
||||||
try:
|
try:
|
||||||
await gitea.create_comment(
|
if wip_comment_id:
|
||||||
owner, repo, issue_number,
|
await gitea.edit_comment(owner, repo, wip_comment_id, error_msg)
|
||||||
"*An error occurred while processing this request. Check bot logs for details.*",
|
else:
|
||||||
)
|
await gitea.create_comment(owner, repo, issue_number, error_msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.exception("Failed to post error comment")
|
log.exception("Failed to post error comment")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user