@@ -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`, {
|
||||
|
||||
Reference in New Issue
Block a user