@@ -5,7 +5,6 @@ import simpleGit from 'simple-git';
5
5
6
6
import queue from './Queue' ;
7
7
import {
8
- CHECK_PREFIX ,
9
8
BACKPORT_REQUESTED_LABEL ,
10
9
DEFAULT_BACKPORT_REVIEW_TEAM ,
11
10
BACKPORT_LABEL ,
@@ -18,6 +17,7 @@ import { setupRemotes } from './operations/setup-remotes';
18
17
import { backportCommitsToBranch } from './operations/backport-commits' ;
19
18
import { getRepoToken } from './utils/token-util' ;
20
19
import { getSupportedBranches , getBackportPattern } from './utils/branch-util' ;
20
+ import { getCheckRun } from './utils/checks-util' ;
21
21
import { getEnvVar } from './utils/env-util' ;
22
22
import { log } from './utils/log-util' ;
23
23
import { TryBackportOptions } from './interfaces' ;
@@ -464,36 +464,21 @@ export const backportImpl = async (
464
464
const bp = `backport from PR #${ pr . number } to "${ targetBranch } "` ;
465
465
log ( 'backportImpl' , LogLevel . INFO , `Queuing ${ bp } for "${ slug } "` ) ;
466
466
467
- const getCheckRun = async ( ) => {
468
- const allChecks = await context . octokit . checks . listForRef (
469
- context . repo ( {
470
- ref : pr . head . sha ,
471
- per_page : 100 ,
472
- } ) ,
473
- ) ;
474
-
475
- return allChecks . data . check_runs . find ( ( run ) => {
476
- return run . name === `${ CHECK_PREFIX } ${ targetBranch } ` ;
477
- } ) ;
478
- } ;
479
-
480
467
let createdDir : string | null = null ;
481
468
482
469
queue . enterQueue (
483
470
`backport-${ pr . head . sha } -${ targetBranch } -${ purpose } ` ,
484
471
async ( ) => {
485
472
log ( 'backportImpl' , LogLevel . INFO , `Executing ${ bp } for "${ slug } "` ) ;
486
- if ( purpose === BackportPurpose . Check ) {
487
- const checkRun = await getCheckRun ( ) ;
488
- if ( checkRun ) {
489
- await context . octokit . checks . update (
490
- context . repo ( {
491
- check_run_id : checkRun . id ,
492
- name : checkRun . name ,
493
- status : 'in_progress' as 'in_progress' ,
494
- } ) ,
495
- ) ;
496
- }
473
+ const checkRun = await getCheckRun ( context , pr , targetBranch ) ;
474
+ if ( checkRun ) {
475
+ await context . octokit . checks . update (
476
+ context . repo ( {
477
+ check_run_id : checkRun . id ,
478
+ name : checkRun . name ,
479
+ status : 'in_progress' as 'in_progress' ,
480
+ } ) ,
481
+ ) ;
497
482
}
498
483
499
484
const repoAccessToken = await getRepoToken ( robot , context ) ;
@@ -679,22 +664,19 @@ export const backportImpl = async (
679
664
log ( 'backportImpl' , LogLevel . INFO , 'Backport process complete' ) ;
680
665
}
681
666
682
- if ( purpose === BackportPurpose . Check ) {
683
- const checkRun = await getCheckRun ( ) ;
684
- if ( checkRun ) {
685
- context . octokit . checks . update (
686
- context . repo ( {
687
- check_run_id : checkRun . id ,
688
- name : checkRun . name ,
689
- conclusion : 'success' as 'success' ,
690
- completed_at : new Date ( ) . toISOString ( ) ,
691
- output : {
692
- title : 'Clean Backport' ,
693
- summary : `This PR was checked and can be backported to "${ targetBranch } " cleanly.` ,
694
- } ,
695
- } ) ,
696
- ) ;
697
- }
667
+ if ( checkRun ) {
668
+ context . octokit . checks . update (
669
+ context . repo ( {
670
+ check_run_id : checkRun . id ,
671
+ name : checkRun . name ,
672
+ conclusion : 'success' as 'success' ,
673
+ completed_at : new Date ( ) . toISOString ( ) ,
674
+ output : {
675
+ title : 'Clean Backport' ,
676
+ summary : `This PR was checked and can be backported to "${ targetBranch } " cleanly.` ,
677
+ } ,
678
+ } ) ,
679
+ ) ;
698
680
}
699
681
700
682
await fs . remove ( createdDir ) ;
@@ -762,31 +744,29 @@ export const backportImpl = async (
762
744
] ) ;
763
745
}
764
746
765
- if ( purpose === BackportPurpose . Check ) {
766
- const checkRun = await getCheckRun ( ) ;
767
- if ( checkRun ) {
768
- const mdSep = '``````````````````````````````' ;
769
- const updateOpts = context . repo ( {
770
- check_run_id : checkRun . id ,
771
- name : checkRun . name ,
772
- conclusion : 'neutral' as 'neutral' ,
773
- completed_at : new Date ( ) . toISOString ( ) ,
774
- output : {
775
- title : 'Backport Failed' ,
776
- summary : `This PR was checked and could not be automatically backported to "${ targetBranch } " cleanly` ,
777
- text : diff
778
- ? `Failed Diff:\n\n${ mdSep } diff\n${ rawDiff } \n${ mdSep } `
779
- : undefined ,
780
- annotations : annotations ? annotations : undefined ,
781
- } ,
782
- } ) ;
783
- try {
784
- await context . octokit . checks . update ( updateOpts ) ;
785
- } catch ( err ) {
786
- // A GitHub error occurred - try to mark it as a failure without annotations.
787
- updateOpts . output ! . annotations = undefined ;
788
- await context . octokit . checks . update ( updateOpts ) ;
789
- }
747
+ const checkRun = await getCheckRun ( context , pr , targetBranch ) ;
748
+ if ( checkRun ) {
749
+ const mdSep = '``````````````````````````````' ;
750
+ const updateOpts = context . repo ( {
751
+ check_run_id : checkRun . id ,
752
+ name : checkRun . name ,
753
+ conclusion : 'neutral' as 'neutral' ,
754
+ completed_at : new Date ( ) . toISOString ( ) ,
755
+ output : {
756
+ title : 'Backport Failed' ,
757
+ summary : `This PR was checked and could not be automatically backported to "${ targetBranch } " cleanly` ,
758
+ text : diff
759
+ ? `Failed Diff:\n\n${ mdSep } diff\n${ rawDiff } \n${ mdSep } `
760
+ : undefined ,
761
+ annotations : annotations ? annotations : undefined ,
762
+ } ,
763
+ } ) ;
764
+ try {
765
+ await context . octokit . checks . update ( updateOpts ) ;
766
+ } catch ( err ) {
767
+ // A GitHub error occurred - try to mark it as a failure without annotations.
768
+ updateOpts . output ! . annotations = undefined ;
769
+ await context . octokit . checks . update ( updateOpts ) ;
790
770
}
791
771
}
792
772
} ,
0 commit comments