Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 954909d

Browse files
authored
submit review in batches (#191)
1 parent 39d68ca commit 954909d

File tree

4 files changed

+70
-12
lines changed

4 files changed

+70
-12
lines changed

dist/index.js

Lines changed: 32 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commenter.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import {retry} from '@octokit/plugin-retry'
77
const token = core.getInput('token') || process.env.GITHUB_TOKEN
88

99
const RetryOctokit = Octokit.plugin(retry)
10-
const octokit = new RetryOctokit({auth: `token ${token}`})
10+
const octokit = new RetryOctokit({
11+
auth: `token ${token}`,
12+
request: {
13+
retries: 10,
14+
retryAfter: 30
15+
}
16+
})
1117

1218
const context = github.context
1319
const repo = context.repo
@@ -157,15 +163,24 @@ ${tag}`
157163
}
158164

159165
async submit_review(pull_number: number, commit_id: string) {
166+
core.info(
167+
`Submitting review for PR #${pull_number}, total comments: ${this.reviewCommentsBuffer.length}`
168+
)
160169
try {
161-
if (this.reviewCommentsBuffer.length > 0) {
170+
let batchNumber = 1
171+
while (this.reviewCommentsBuffer.length > 0) {
172+
const commentsBatch = this.reviewCommentsBuffer.splice(0, 30)
173+
core.info(
174+
`Posting batch #${batchNumber} with ${commentsBatch.length} comments`
175+
)
176+
162177
await octokit.pulls.createReview({
163178
owner: repo.owner,
164179
repo: repo.repo,
165180
pull_number,
166181
commit_id,
167182
event: 'COMMENT',
168-
comments: this.reviewCommentsBuffer.map(comment => {
183+
comments: commentsBatch.map(comment => {
169184
const commentData: any = {
170185
path: comment.path,
171186
body: comment.message,
@@ -180,7 +195,12 @@ ${tag}`
180195
return commentData
181196
})
182197
})
183-
this.reviewCommentsBuffer = []
198+
199+
if (this.reviewCommentsBuffer.length > 0) {
200+
core.info(`Waiting 10 seconds before posting next batch`)
201+
await new Promise(resolve => setTimeout(resolve, 10000))
202+
}
203+
batchNumber++
184204
}
185205
} catch (e) {
186206
core.warning(`Failed to submit review: ${e}`)

src/review-comment.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ const token = core.getInput('token')
1818
: process.env.GITHUB_TOKEN
1919

2020
const RetryOctokit = Octokit.plugin(retry)
21-
const octokit = new RetryOctokit({auth: `token ${token}`})
21+
const octokit = new RetryOctokit({
22+
auth: `token ${token}`,
23+
request: {
24+
retries: 10,
25+
retryAfter: 30
26+
}
27+
})
2228

2329
const context = github.context
2430
const repo = context.repo

src/review.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ const token = core.getInput('token')
1818
: process.env.GITHUB_TOKEN
1919

2020
const RetryOctokit = Octokit.plugin(retry)
21-
const octokit = new RetryOctokit({auth: `token ${token}`})
21+
const octokit = new RetryOctokit({
22+
auth: `token ${token}`,
23+
request: {
24+
retries: 10,
25+
retryAfter: 30
26+
}
27+
})
2228

2329
const context = github.context
2430
const repo = context.repo

0 commit comments

Comments
 (0)