Skip to content

Commit ad20071

Browse files
committed
subtleSubmitReview.js: fix a race condition
1 parent 48b793d commit ad20071

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/subtleSubmitReview.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export default async function subtleSubmitReview ({
4949
name: repo,
5050
prnumber: prnum
5151
}
52-
const msg = (await github.graphql(query, variables)).repository.pullRequest
52+
const msgPre = (await github.graphql(query, variables)).repository.pullRequest
5353

5454
// debounce if the PR description contains a watermark and the debounce time is not expired yet
55-
if (msg.body.includes(watermark) && !isOlderThanXHours(msg.updatedAt, debounceTime)) {
55+
if (msgPre.body.includes(watermark) && !isOlderThanXHours(msgPre.updatedAt, debounceTime)) {
5656
throw new Error('debounce')
5757
}
5858

@@ -65,6 +65,8 @@ export default async function subtleSubmitReview ({
6565

6666
const newExplaination = '<details><summary>AI Review</summary>' + '\n\n' + watermark + '\n\n' + await explainPatch() + '</details>'
6767

68+
// fetch the message twice, to decrease the chances of race condition, but still debounce
69+
const msg = (await github.graphql(query, variables)).repository.pullRequest
6870
const newBody = msg.body.match(re)
6971
? msg.body.replace(re, newExplaination)
7072
: msg.body + '\n\n' + newExplaination

0 commit comments

Comments
 (0)