1
1
"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
- } ;
11
2
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
12
3
exports . 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" ) ;
13
5
const 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 ( {
16
8
owner : context . repo . owner ,
17
9
repo : context . repo . repo ,
18
10
'run_id' : Number ( process . env . GITHUB_RUN_ID ) ,
19
11
} ) ) . data ;
20
- } ) ;
12
+ } ;
21
13
exports . getWorkflowRun = getWorkflowRun ;
22
14
const getWorkflowId = ( run ) => {
23
15
const matches = run . workflow_url . match ( / \d + $ / ) ;
@@ -27,28 +19,33 @@ const getWorkflowId = (run) => {
27
19
return Number ( matches [ 0 ] ) ;
28
20
} ;
29
21
exports . getWorkflowId = getWorkflowId ;
30
- const getWorkflowRunCreatedAt = ( run ) => run . created_at ;
22
+ const getWorkflowRunCreatedAt = ( run ) => github_action_helper_1 . Utils . ensureNotNull ( run . created_at ) ;
31
23
exports . getWorkflowRunCreatedAt = getWorkflowRunCreatedAt ;
32
24
const getWorkflowRunNumber = ( run ) => run . run_number ;
33
25
exports . 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 ) ;
37
33
logger . log ( 'target event: %s' , logger . c ( context . eventName , { color : 'green' } ) ) ;
38
34
if ( branch ) {
39
35
logger . log ( 'target branch: %s' , logger . c ( branch , { color : 'green' } ) ) ;
40
36
options . branch = branch ;
41
37
}
42
- return ( yield octokit . paginate ( octokit . actions . listWorkflowRuns ,
38
+ return ( await octokit . paginate ( octokit . actions . listWorkflowRuns ,
43
39
// eslint-disable-next-line no-warning-comments
44
40
// TODO: remove ts-ignore after fixed types (https://github.com/octokit/types.ts/issues/122)
45
41
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
46
42
// @ts -ignore
47
43
options ) ) . map ( run => run ) . filter ( run => run . event === context . eventName ) . filter ( misc_1 . isNotExcludeRun ) ;
48
- } ) ;
44
+ } ;
49
45
exports . getWorkflowRuns = getWorkflowRuns ;
50
46
// 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 ,
53
50
} ) ;
54
51
exports . cancelWorkflowRun = cancelWorkflowRun ;
0 commit comments