11"use strict" ;
2- var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
3- function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
4- return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
5- function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
6- function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
7- function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
8- step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
9- } ) ;
10- } ;
112Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
123exports . cancelWorkflowRun = exports . getWorkflowRuns = exports . getWorkflowRunNumber = exports . getWorkflowRunCreatedAt = exports . getWorkflowId = exports . getWorkflowRun = void 0 ;
4+ const github_action_helper_1 = require ( "@technote-space/github-action-helper" ) ;
135const misc_1 = require ( "./misc" ) ;
14- const getWorkflowRun = ( octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
15- return ( yield octokit . actions . getWorkflowRun ( {
6+ const getWorkflowRun = async ( octokit , context ) => {
7+ return ( await octokit . actions . getWorkflowRun ( {
168 owner : context . repo . owner ,
179 repo : context . repo . repo ,
1810 'run_id' : Number ( process . env . GITHUB_RUN_ID ) ,
1911 } ) ) . data ;
20- } ) ;
12+ } ;
2113exports . getWorkflowRun = getWorkflowRun ;
2214const getWorkflowId = ( run ) => {
2315 const matches = run . workflow_url . match ( / \d + $ / ) ;
@@ -27,28 +19,33 @@ const getWorkflowId = (run) => {
2719 return Number ( matches [ 0 ] ) ;
2820} ;
2921exports . getWorkflowId = getWorkflowId ;
30- const getWorkflowRunCreatedAt = ( run ) => run . created_at ;
22+ const getWorkflowRunCreatedAt = ( run ) => github_action_helper_1 . Utils . ensureNotNull ( run . created_at ) ;
3123exports . getWorkflowRunCreatedAt = getWorkflowRunCreatedAt ;
3224const getWorkflowRunNumber = ( run ) => run . run_number ;
3325exports . getWorkflowRunNumber = getWorkflowRunNumber ;
34- const getWorkflowRuns = ( workflowId , logger , octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
35- const options = Object . assign ( Object . assign ( { } , context . repo ) , { 'workflow_id' : workflowId , status : 'in_progress' } ) ;
36- const branch = yield misc_1 . getTargetBranch ( octokit , context ) ;
26+ const getWorkflowRuns = async ( workflowId , logger , octokit , context ) => {
27+ const options = {
28+ ...context . repo ,
29+ 'workflow_id' : workflowId ,
30+ status : 'in_progress' ,
31+ } ;
32+ const branch = await misc_1 . getTargetBranch ( octokit , context ) ;
3733 logger . log ( 'target event: %s' , logger . c ( context . eventName , { color : 'green' } ) ) ;
3834 if ( branch ) {
3935 logger . log ( 'target branch: %s' , logger . c ( branch , { color : 'green' } ) ) ;
4036 options . branch = branch ;
4137 }
42- return ( yield octokit . paginate ( octokit . actions . listWorkflowRuns ,
38+ return ( await octokit . paginate ( octokit . actions . listWorkflowRuns ,
4339 // eslint-disable-next-line no-warning-comments
4440 // TODO: remove ts-ignore after fixed types (https://github.com/octokit/types.ts/issues/122)
4541 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4642 // @ts -ignore
4743 options ) ) . map ( run => run ) . filter ( run => run . event === context . eventName ) . filter ( misc_1 . isNotExcludeRun ) ;
48- } ) ;
44+ } ;
4945exports . getWorkflowRuns = getWorkflowRuns ;
5046// eslint-disable-next-line @typescript-eslint/no-explicit-any
51- const cancelWorkflowRun = ( runId , octokit , context ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
52- return octokit . actions . cancelWorkflowRun ( Object . assign ( Object . assign ( { } , context . repo ) , { 'run_id' : runId } ) ) ;
47+ const cancelWorkflowRun = async ( runId , octokit , context ) => octokit . actions . cancelWorkflowRun ( {
48+ ...context . repo ,
49+ 'run_id' : runId ,
5350} ) ;
5451exports . cancelWorkflowRun = cancelWorkflowRun ;
0 commit comments