zenhub-automations/index.js

47 lines
1.1 KiB
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
2020-11-30 10:25:29 +00:00
const handlers = {
create: 'create.js',
2020-12-02 08:07:06 +00:00
issues: 'issues.js',
2020-11-30 10:25:29 +00:00
ready_for_review: 'create.js',
pull_request: 'pull_request.js'
}
2019-07-10 14:01:40 +00:00
Toolkit.run(async tools => {
2020-11-30 10:25:29 +00:00
const handlerRef = tools.context.event;
tools.log.info(`Trying to load handler: "${handlerRef}"...`);
try {
2020-11-30 10:25:29 +00:00
const file = handlers[handlerRef];
if (!file) {
tools.log.info(`Could not find handler for "${handlerRef}"`);
return
}
var eventModule = require(`./lib/handlers/${file}`);
} 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.');
});