@@ -129,9 +129,14 @@ ${tag}`
129
129
}
130
130
}
131
131
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 (
135
140
path : string ,
136
141
start_line : number ,
137
142
end_line : number ,
@@ -143,66 +148,36 @@ ${tag}`
143
148
${ message }
144
149
145
150
${ 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
- }
170
151
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 ,
197
174
start_side : 'RIGHT'
198
- } )
199
- }
175
+ } ) )
176
+ } )
177
+ this . reviewCommentsBuffer = [ ]
200
178
}
201
179
} 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 } ` )
206
181
throw e
207
182
}
208
183
}
0 commit comments