From 4ea56ca39148cc183fcae255b0b2b5c873546c21 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 29 Nov 2024 08:41:28 -0800 Subject: [PATCH] subtleSubmitReview.js: fix a race condition --- src/subtleSubmitReview.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/subtleSubmitReview.js b/src/subtleSubmitReview.js index 1a731de..4bd0bc5 100644 --- a/src/subtleSubmitReview.js +++ b/src/subtleSubmitReview.js @@ -49,10 +49,10 @@ export default async function subtleSubmitReview ({ name: repo, prnumber: prnum } - const msg = (await github.graphql(query, variables)).repository.pullRequest + const msgPre = (await github.graphql(query, variables)).repository.pullRequest // debounce if the PR description contains a watermark and the debounce time is not expired yet - if (msg.body.includes(watermark) && !isOlderThanXHours(msg.updatedAt, debounceTime)) { + if (msgPre.body.includes(watermark) && !isOlderThanXHours(msgPre.updatedAt, debounceTime)) { throw new Error('debounce') } @@ -65,6 +65,8 @@ export default async function subtleSubmitReview ({ const newExplaination = '
AI Review' + '\n\n' + watermark + '\n\n' + await explainPatch() + '
' + // fetch the message twice, to decrease the chances of race condition, but still debounce + const msg = (await github.graphql(query, variables)).repository.pullRequest const newBody = msg.body.match(re) ? msg.body.replace(re, newExplaination) : msg.body + '\n\n' + newExplaination