mirror of
https://github.com/status-im/zenhub-automations.git
synced 2025-02-20 14:18:28 +00:00
Use map of handlers
This commit is contained in:
parent
c4e3526bef
commit
0fc7ccad52
16
index.js
16
index.js
@ -3,13 +3,25 @@ const { Toolkit } = require('actions-toolkit'),
|
||||
|
||||
const tools = new Toolkit();
|
||||
|
||||
const handlers = {
|
||||
create: 'create.js',
|
||||
ready_for_review: 'create.js',
|
||||
pull_request: 'pull_request.js'
|
||||
}
|
||||
|
||||
Toolkit.run(async tools => {
|
||||
const handlerRef = `${tools.context.event}.js`;
|
||||
const handlerRef = tools.context.event;
|
||||
|
||||
tools.log.info(`Trying to load handler: "${handlerRef}"...`);
|
||||
|
||||
try {
|
||||
var eventModule = require(`./lib/handlers/${handlerRef}`);
|
||||
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)
|
||||
return tools.exit.success('Failed to load module for event. No action necessary.');
|
||||
|
@ -4,7 +4,7 @@ const zh = require('../zh-client'),
|
||||
INPUT_REVIEW_COLUMN
|
||||
} = process.env;
|
||||
|
||||
exports.opened = async function handleOpenedPR (tools) {
|
||||
async function handleOpenedPR (tools) {
|
||||
tools.log.info('Handling opened PR...');
|
||||
|
||||
const failures = [],
|
||||
@ -32,3 +32,6 @@ exports.opened = async function handleOpenedPR (tools) {
|
||||
throw new Error(`Failed to execute some actions: ${failures.map(x => x.message || x).join(', ')}`);
|
||||
}
|
||||
};
|
||||
|
||||
exports.opened = handleOpenedPR;
|
||||
exports.ready_for_review = handleOpenedPR;
|
||||
|
Loading…
x
Reference in New Issue
Block a user