1- module . exports = async ( { github, context, core, dry } ) => {
1+ module . exports = async ( { github, context, core, dry, cherryPicks } ) => {
22 const { execFileSync } = require ( 'node:child_process' )
33 const { classify } = require ( '../supportedBranches.js' )
44 const withRateLimit = require ( './withRateLimit.js' )
5+ const { dismissReviews, postReview } = require ( './reviews.js' )
56
67 await withRateLimit ( { github, core } , async ( stats ) => {
78 stats . prs = 1
@@ -16,7 +17,7 @@ module.exports = async ({ github, context, core, dry }) => {
1617 run_id : context . runId ,
1718 per_page : 100 ,
1819 } )
19- ) . find ( ( { name } ) => name . endsWith ( 'Check / cherry-pick ' ) ) . html_url +
20+ ) . find ( ( { name } ) => name . endsWith ( 'Check / commits ' ) ) . html_url +
2021 '?pr=' +
2122 pull_number
2223
@@ -137,10 +138,14 @@ module.exports = async ({ github, context, core, dry }) => {
137138 }
138139 }
139140
140- const commits = await github . paginate ( github . rest . pulls . listCommits , {
141- ...context . repo ,
142- pull_number,
143- } )
141+ // For now we short-circuit the list of commits when cherryPicks should not be checked.
142+ // This will not run any checks, but still trigger the "dismiss reviews" part below.
143+ const commits = ! cherryPicks
144+ ? [ ]
145+ : await github . paginate ( github . rest . pulls . listCommits , {
146+ ...context . repo ,
147+ pull_number,
148+ } )
144149
145150 const extracted = await Promise . all ( commits . map ( extract ) )
146151
@@ -185,38 +190,10 @@ module.exports = async ({ github, context, core, dry }) => {
185190
186191 // Only create step summary below in case of warnings or errors.
187192 // Also clean up older reviews, when all checks are good now.
193+ // An empty results array will always trigger this condition, which is helpful
194+ // to clean up reviews created by the prepare step when on the wrong branch.
188195 if ( results . every ( ( { severity } ) => severity === 'info' ) ) {
189- if ( ! dry ) {
190- await Promise . all (
191- (
192- await github . paginate ( github . rest . pulls . listReviews , {
193- ...context . repo ,
194- pull_number,
195- } )
196- )
197- . filter ( ( review ) => review . user . login === 'github-actions[bot]' )
198- . map ( async ( review ) => {
199- if ( review . state === 'CHANGES_REQUESTED' ) {
200- await github . rest . pulls . dismissReview ( {
201- ...context . repo ,
202- pull_number,
203- review_id : review . id ,
204- message : 'All cherry-picks are good now, thank you!' ,
205- } )
206- }
207- await github . graphql (
208- `mutation($node_id:ID!) {
209- minimizeComment(input: {
210- classifier: RESOLVED,
211- subjectId: $node_id
212- })
213- { clientMutationId }
214- }` ,
215- { node_id : review . node_id } ,
216- )
217- } ) ,
218- )
219- }
196+ await dismissReviews ( { github, context, dry } )
220197 return
221198 }
222199
@@ -336,45 +313,9 @@ module.exports = async ({ github, context, core, dry }) => {
336313 const body = core . summary . stringify ( )
337314 core . summary . write ( )
338315
339- const pendingReview = (
340- await github . paginate ( github . rest . pulls . listReviews , {
341- ...context . repo ,
342- pull_number,
343- } )
344- ) . find (
345- ( review ) =>
346- review . user . login === 'github-actions[bot]' &&
347- // If a review is still pending, we can just update this instead
348- // of posting a new one.
349- ( review . state === 'CHANGES_REQUESTED' ||
350- // No need to post a new review, if an older one with the exact
351- // same content had already been dismissed.
352- review . body === body ) ,
353- )
354-
355- if ( dry ) {
356- if ( pendingReview )
357- core . info ( `pending review found: ${ pendingReview . html_url } ` )
358- else core . info ( 'no pending review found' )
359- } else {
360- // Either of those two requests could fail for very long comments. This can only happen
361- // with multiple commits all hitting the truncation limit for the diff. If you ever hit
362- // this case, consider just splitting up those commits into multiple PRs.
363- if ( pendingReview ) {
364- await github . rest . pulls . updateReview ( {
365- ...context . repo ,
366- pull_number,
367- review_id : pendingReview . id ,
368- body,
369- } )
370- } else {
371- await github . rest . pulls . createReview ( {
372- ...context . repo ,
373- pull_number,
374- event : 'REQUEST_CHANGES' ,
375- body,
376- } )
377- }
378- }
316+ // Posting a review could fail for very long comments. This can only happen with
317+ // multiple commits all hitting the truncation limit for the diff. If you ever hit
318+ // this case, consider just splitting up those commits into multiple PRs.
319+ await postReview ( { github, context, core, dry, body } )
379320 } )
380321}
0 commit comments