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

Commit 59d763c

Browse files
committed
Revert "Revert "create review instead of single comments" (#187)"
This reverts commit e54dc76.
1 parent e54dc76 commit 59d763c

File tree

3 files changed

+70
-109
lines changed

3 files changed

+70
-109
lines changed

dist/index.js

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

src/commenter.ts

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,14 @@ ${tag}`
129129
}
130130
}
131131

132-
async review_comment(
133-
pull_number: number,
134-
commit_id: string,
132+
private reviewCommentsBuffer: {
133+
path: string
134+
start_line: number
135+
end_line: number
136+
message: string
137+
}[] = []
138+
139+
async buffer_review_comment(
135140
path: string,
136141
start_line: number,
137142
end_line: number,
@@ -143,66 +148,36 @@ ${tag}`
143148
${message}
144149
145150
${tag}`
146-
// replace comment made by this action
147-
try {
148-
let found = false
149-
const comments = await this.get_comments_at_range(
150-
pull_number,
151-
path,
152-
start_line,
153-
end_line
154-
)
155-
for (const comment of comments) {
156-
if (comment.body.includes(tag)) {
157-
core.info(
158-
`Updating review comment for ${path}:${start_line}-${end_line}: ${message}`
159-
)
160-
await octokit.pulls.updateReviewComment({
161-
owner: repo.owner,
162-
repo: repo.repo,
163-
comment_id: comment.id,
164-
body: message
165-
})
166-
found = true
167-
break
168-
}
169-
}
170151

171-
if (!found) {
172-
core.info(
173-
`Creating new review comment for ${path}:${start_line}-${end_line}: ${message}`
174-
)
175-
// if start_line is same as end_line, it's a single line comment
176-
// otherwise it's a multi-line comment
177-
if (start_line === end_line) {
178-
await octokit.pulls.createReviewComment({
179-
owner: repo.owner,
180-
repo: repo.repo,
181-
pull_number,
182-
body: message,
183-
commit_id,
184-
path,
185-
line: end_line
186-
})
187-
} else {
188-
await octokit.pulls.createReviewComment({
189-
owner: repo.owner,
190-
repo: repo.repo,
191-
pull_number,
192-
body: message,
193-
commit_id,
194-
path,
195-
line: end_line,
196-
start_line,
152+
this.reviewCommentsBuffer.push({
153+
path,
154+
start_line,
155+
end_line,
156+
message
157+
})
158+
}
159+
160+
async submit_review(pull_number: number, commit_id: string) {
161+
try {
162+
if (this.reviewCommentsBuffer.length > 0) {
163+
await octokit.pulls.createReview({
164+
owner: repo.owner,
165+
repo: repo.repo,
166+
pull_number,
167+
commit_id,
168+
event: 'COMMENT',
169+
comments: this.reviewCommentsBuffer.map(comment => ({
170+
path: comment.path,
171+
body: comment.message,
172+
line: comment.end_line,
173+
start_line: comment.start_line,
197174
start_side: 'RIGHT'
198-
})
199-
}
175+
}))
176+
})
177+
this.reviewCommentsBuffer = []
200178
}
201179
} catch (e) {
202-
core.warning(
203-
`Failed to post review comment, for ${path}:${start_line}-${end_line}: ${e}`
204-
)
205-
// throw error
180+
core.warning(`Failed to submit review: ${e}`)
206181
throw e
207182
}
208183
}

src/review.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,7 @@ ${comment_chain}
610610
continue
611611
}
612612
try {
613-
await commenter.review_comment(
614-
context.payload.pull_request.number,
615-
commits[commits.length - 1].sha,
613+
await commenter.buffer_review_comment(
616614
filename,
617615
review.start_line,
618616
review.end_line,
@@ -752,6 +750,12 @@ ${
752750

753751
// post the final summary comment
754752
await commenter.comment(`${summarize_comment}`, SUMMARIZE_TAG, 'replace')
753+
754+
// post the review
755+
await commenter.submit_review(
756+
context.payload.pull_request.number,
757+
commits[commits.length - 1].sha
758+
)
755759
}
756760

757761
const split_patch = (patch: string | null | undefined): string[] => {

0 commit comments

Comments
 (0)