-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
33 lines (24 loc) · 902 Bytes
/
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
const { Toolkit } = require('actions-toolkit'),
{ join } = require('path');
const tools = new Toolkit();
Toolkit.run(async tools => {
const handlerRef = `${tools.context.event}.js`;
tools.log.info(`Trying to load handler: "${handlerRef}"...`);
try {
var eventModule = require(`./lib/handlers/${handlerRef}`);
} catch (e) {
console.log(e)
return tools.exit.success('Failed to load module for event. No action necessary.');
}
const moduleAction = eventModule[tools.context.payload.action] || eventModule[tools.context.payload.ref_type];
console.log(tools.context.payload);
if (!moduleAction) {
return tools.exit.success('Failed to find sub handler. No action necessary.');
}
try {
await moduleAction(tools);
} catch (e) {
return tools.exit.failure(`Failed to run event handler: ${e}`);
}
tools.exit.success('Executed event handler.');
});