@@ -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 /*
0 commit comments