-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
76 lines (65 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* External dependencies
*/
const { setFailed, getInput, debug: coreDebug } = require( '@actions/core' );
const GitHub = require( '@actions/github' );
const context = GitHub.context;
/**
* Internal dependencies
*/
const debug = require( './debug' );
const ifNotFork = require( './if-not-fork' );
const automations = require( './automations' );
/**
* @typedef {import('./typedefs').AutomationTaskRunner} AutomationTaskRunner
*/
( async function initialize() {
const types = getInput( 'automations' ).split( ',' );
debug( `The types value is ${ types }` );
if ( types && ! Array.isArray( types ) ) {
setFailed(
'initialize: The provided `automations` configuration object must be a list.'
);
return;
}
const token = getInput( 'github_token' );
if ( ! token ) {
setFailed( 'initialize: Input `github_token` is required' );
return;
}
const octokit = GitHub.getOctokit( token );
debug(
`initialize: Received event = '${ context.eventName }', action = '${ context.payload.action }'`
);
for ( const {
name,
events,
actions,
runner,
getConfig = () => void null,
} of automations ) {
if (
events.includes( context.eventName ) &&
( actions === undefined ||
actions.includes( context.payload.action ) )
) {
try {
debug( `initialize: Starting runner ${ name }` );
/**
* @type {AutomationTaskRunner}
*/
const task = ifNotFork( runner );
const config = await getConfig( context, octokit );
coreDebug(
`Created config: ${ config } : ` + JSON.stringify( config )
);
await task( context, octokit, config );
} catch ( error ) {
setFailed(
`initialize: Runner ${ name } failed with error: ${ error }`
);
}
}
}
debug( 'initialize: All done!' );
} )();