Review on request
Check / deno (pull_request) Successful in 1m57s

This commit is contained in:
bot
2026-09-14 08:43:09 +09:00
parent 4ed8b48b7a
commit 3419e0a978
2 changed files with 13 additions and 9 deletions
+11 -8
View File
@@ -59,10 +59,10 @@ async function postComment(body: string): Promise<void> {
});
}
// A pull request event is a review request, so the review is posted instead
// of the response. It comes through a file, because a final chat message picks
// up narration while a file's first line is written on purpose. That line is
// the verdict, matched whole; anything unexpected only comments, never
// A review is posted whenever the agent wrote one, whether a review request or
// a comment asked for it. It comes through a file, because a final chat message
// picks up narration while a file's first line is written on purpose. That line
// is the verdict, matched whole; anything unexpected only comments, never
// approves. The mark in front is added here, so it is never part of the match.
const REVIEW_PATH = `${await Deno.makeTempDir()}/review.md`;
const VERDICTS: Record<string, [event: string, mark: string]> = {
@@ -71,10 +71,13 @@ const VERDICTS: Record<string, [event: string, mark: string]> = {
};
async function postResult(body: string): Promise<void> {
if (EVENT !== "pull_request") return postComment(body);
const review = await Deno.readTextFile(REVIEW_PATH).catch(() => {
throw new Error(`no review was written to ${REVIEW_PATH}`);
});
const review = await Deno.readTextFile(REVIEW_PATH).catch(() => null);
if (review === null) {
if (EVENT === "pull_request") {
throw new Error(`no review was written to ${REVIEW_PATH}`);
}
return postComment(body);
}
const [verdict, ...rest] = review.split("\n");
const [event, mark] = VERDICTS[verdict.trim()] ?? ["COMMENT", "💬"];
await gitea(REVIEWER_TOKEN, `repos/${REPO}/pulls/${INDEX}/reviews`, {