@@ -272,8 +272,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
272
272
] ;
273
273
const FASTTRACK_LABELS : string [ ] = [ 'fast-track 🚅' ] ;
274
274
275
- const failureMap = new Map ( ) ;
276
-
277
275
// There are several types of PRs which might not target main yet which are
278
276
// inherently valid; e.g roller-bot PRs. Check for and allow those here.
279
277
if ( oldPRNumbers . length === 0 ) {
@@ -309,6 +307,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
309
307
robot . log (
310
308
`#${ pr . number } has backport numbers - checking their validity now` ,
311
309
) ;
310
+ const failureMap = new Map ( ) ;
312
311
const supported = await getSupportedBranches ( context ) ;
313
312
const oldPRs = [ ] ;
314
313
@@ -319,7 +318,9 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
319
318
pull_number : oldPRNumber ,
320
319
} ) ,
321
320
) ;
321
+
322
322
oldPRs . push ( oldPR ) ;
323
+
323
324
// The current PR is only valid if the PR it is backporting
324
325
// was merged to main or to a supported release branch.
325
326
if (
@@ -337,9 +338,33 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
337
338
}
338
339
}
339
340
341
+ for ( const oldPRNumber of oldPRNumbers ) {
342
+ if ( failureMap . has ( oldPRNumber ) ) {
343
+ robot . log (
344
+ `#${ pr . number } is targeting a branch that is not ${
345
+ pr . base . repo . default_branch
346
+ } - ${ failureMap . get ( oldPRNumber ) } `,
347
+ ) ;
348
+ await updateBackportValidityCheck ( context , checkRun , {
349
+ title : 'Invalid Backport' ,
350
+ summary : `This PR is targeting a branch that is not ${
351
+ pr . base . repo . default_branch
352
+ } but ${ failureMap . get ( oldPRNumber ) } `,
353
+ conclusion : CheckRunStatus . FAILURE ,
354
+ } ) ;
355
+ } else {
356
+ robot . log ( `#${ pr . number } is a valid backport of #${ oldPRNumber } ` ) ;
357
+ await updateBackportValidityCheck ( context , checkRun , {
358
+ title : 'Valid Backport' ,
359
+ summary : `This PR is declared as backporting "#${ oldPRNumber } " which is a valid PR that has been merged into ${ pr . base . repo . default_branch } ` ,
360
+ conclusion : CheckRunStatus . SUCCESS ,
361
+ } ) ;
362
+ }
363
+ }
364
+
340
365
if ( [ 'opened' , 'edited' ] . includes ( action ) ) {
341
366
robot . log ( `Checking validity of release notes` ) ;
342
- // Check to make sure backport PR has the same release notes as at least on of the old prs
367
+ // Check to make sure backport PR has the same release notes as at least one of the old prs
343
368
const isValidReleaseNotes = await isValidManualBackportReleaseNotes (
344
369
context ,
345
370
oldPRs as WebHookPR [ ] ,
@@ -356,30 +381,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
356
381
}
357
382
}
358
383
}
359
-
360
- for ( const oldPRNumber of oldPRNumbers ) {
361
- if ( failureMap . has ( oldPRNumber ) ) {
362
- robot . log (
363
- `#${ pr . number } is targeting a branch that is not ${
364
- pr . base . repo . default_branch
365
- } - ${ failureMap . get ( oldPRNumber ) } `,
366
- ) ;
367
- await updateBackportValidityCheck ( context , checkRun , {
368
- title : 'Invalid Backport' ,
369
- summary : `This PR is targeting a branch that is not ${
370
- pr . base . repo . default_branch
371
- } but ${ failureMap . get ( oldPRNumber ) } `,
372
- conclusion : CheckRunStatus . FAILURE ,
373
- } ) ;
374
- } else {
375
- robot . log ( `#${ pr . number } is a valid backport of #${ oldPRNumber } ` ) ;
376
- await updateBackportValidityCheck ( context , checkRun , {
377
- title : 'Valid Backport' ,
378
- summary : `This PR is declared as backporting "#${ oldPRNumber } " which is a valid PR that has been merged into ${ pr . base . repo . default_branch } ` ,
379
- conclusion : CheckRunStatus . SUCCESS ,
380
- } ) ;
381
- }
382
- }
383
384
} else {
384
385
// If we're somehow targeting main and have a check run,
385
386
// we mark this check as cancelled.
0 commit comments