zenhub-automations/index.js

34 lines
902 B
JavaScript
Raw Normal View History

const { Toolkit } = require('actions-toolkit'),
{ join } = require('path');
const tools = new Toolkit();
2019-07-10 14:01:40 +00:00
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)
2019-10-08 16:02:55 +00:00
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) {
2019-10-08 16:02:55 +00:00
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.');
});