Skip to content

Commit e847dc8

Browse files
committed
Try a different API.
1 parent 7bb88f4 commit e847dc8

File tree

2 files changed

+45
-29
lines changed

2 files changed

+45
-29
lines changed

.github/scripts/pr_comment.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,50 +69,49 @@ module.exports = async ({github, context, process, retry_delay}) => {
6969
*/
7070
var doDiffComments = async (report) => {
7171

72-
var review_id = null
73-
const existing_reviews = await octokit.rest.pulls.listReviews({
72+
// Start by deleting any previous comments.
73+
const existing_comments = await octokit.rest.pulls.listReviewComments({
7474
owner: context.repo.owner,
7575
repo: context.repo.repo,
7676
pull_number: context.payload.number,
77-
})
78-
existing_reviews.data.forEach((review) => {
79-
if (review.body.endsWith(comment_marker)) {
80-
review_id = review.id
77+
});
78+
existing_comments.data.forEach(async (comment) => {
79+
if (! comment.body.endsWith(comment_marker)) {
80+
// Not our comment.
81+
return
8182
}
83+
await octokit.rest.pulls.deleteReviewComment({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
comment_id: comment.id,
87+
})
8288
})
8389

84-
if (review_id) {
85-
// We have an existing review.
86-
// Delete it as we will replace it with a new one.
87-
88-
}
89-
9090
// Prepare inline comments.
9191
var comments = []
9292
Object.keys(report.src_stats).forEach((path) => {
93-
report.src_stats[path].violation_lines.forEach((position) => {
93+
report.src_stats[path].violation_lines.forEach((line) => {
9494
comments.push({
9595
path,
96-
position,
97-
body: 'Missing coverage.'
96+
line,
9897
})
9998
})
10099
})
101100

102-
if (!comments) {
103-
// Coverage is complete. Nothing to comment about.
104-
return
105-
}
106-
107-
await octokit.rest.pulls.createReview({
108-
owner: context.repo.owner,
109-
repo: context.repo.repo,
110-
commit_id: context.payload.after,
111-
pull_number: context.payload.number,
112-
event: "COMMENT",
113-
body: "Missing coverage report." + comment_marker,
114-
comments
101+
comments.forEach(async (comment) => {
102+
await octokit.rest.pulls.createReviewComment({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
commit_id: context.payload.after,
106+
pull_number: context.payload.number,
107+
body: 'Missing coverage.' + comment_marker,
108+
path: comment.path,
109+
line: comment.line,
110+
})
111+
// Wait 1 second to avoid the mitigate the limit.
112+
await sleep(1)
115113
})
114+
116115
}
117116

118117
/*

.github/scripts/pr_comment.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,31 @@ var github = {
4141
},
4242
pulls: {
4343
listReviews: (options) => {
44-
console.log('Listing existing revies...')
44+
console.log('Listing existing reviews...')
4545
console.log(options)
4646
return {data: [
4747
{'id': 120, 'body': 'some-other-pr-review'},
4848
// Comment the line below to trigger creating a new comment.
4949
{'id': 156, 'body': 'review marker\n<!--- comment-marker -->'},
5050
]}
5151
},
52+
listReviewComments: (options) => {
53+
console.log('Listing existing review comments...')
54+
console.log(options)
55+
return {data: [
56+
{'id': 120, 'body': 'some-other-pr-review'},
57+
// Comment the line below to trigger creating a new comment.
58+
{'id': 156, 'body': 'review marker\n<!--- comment-marker -->'},
59+
]}
60+
},
61+
createReviewComment: (options) => {
62+
console.log('Creating new review comment...')
63+
console.log(options)
64+
},
65+
deleteReviewComment: (options) => {
66+
console.log('Deleting review comment...')
67+
console.log(options)
68+
},
5269
createReview: (options) => {
5370
console.log('Creating new review...')
5471
console.log(options)

0 commit comments

Comments
 (0)