Verdict words (#8)
The review file starts with `Approved` or `Changes requested` instead of `Yes`/`No`/`With fixes`. The match is still the whole trimmed first line; `run.ts` prepends ✅, 🛑, or 💬 when posting, so the mark never takes part in the match. Verified: `deno fmt`, `deno lint`, `deno check` pass; a scratch run of the matcher maps `Approved` → APPROVED, `Changes requested` → REQUEST_CHANGES, and `Approved, mostly`, `✅ Approved`, `Yes` → COMMENT. Reviewed-on: #8 Co-authored-by: Danny Kim <temeddix@gmail.com> Co-committed-by: Danny Kim <temeddix@gmail.com>
This commit was merged in pull request #8.
This commit is contained in:
@@ -62,12 +62,12 @@ 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; anything unexpected only comments, never approves.
|
||||
// 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, string> = {
|
||||
Yes: "APPROVED",
|
||||
No: "REQUEST_CHANGES",
|
||||
"With fixes": "REQUEST_CHANGES",
|
||||
const VERDICTS: Record<string, [event: string, mark: string]> = {
|
||||
Approved: ["APPROVED", "✅"],
|
||||
"Changes requested": ["REQUEST_CHANGES", "🛑"],
|
||||
};
|
||||
|
||||
async function postResult(body: string): Promise<void> {
|
||||
@@ -75,10 +75,11 @@ async function postResult(body: string): Promise<void> {
|
||||
const review = await Deno.readTextFile(REVIEW_PATH).catch(() => {
|
||||
throw new Error(`no review was written to ${REVIEW_PATH}`);
|
||||
});
|
||||
const [verdict] = review.split("\n", 1);
|
||||
const [verdict, ...rest] = review.split("\n");
|
||||
const [event, mark] = VERDICTS[verdict.trim()] ?? ["COMMENT", "💬"];
|
||||
await gitea(REVIEWER_TOKEN, `repos/${REPO}/pulls/${INDEX}/reviews`, {
|
||||
body: stripAnsi(review),
|
||||
event: VERDICTS[verdict.trim()] ?? "COMMENT",
|
||||
body: stripAnsi([`${mark} ${verdict.trim()}`, ...rest].join("\n")),
|
||||
event,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user