2020-12-29 08:46:46 +00:00
|
|
|
const { Toolkit } = require("actions-toolkit"),
|
|
|
|
{ join } = require("path");
|
2019-07-11 17:14:43 +00:00
|
|
|
|
|
|
|
const tools = new Toolkit();
|
2019-07-10 14:01:40 +00:00
|
|
|
|
2020-11-30 10:25:29 +00:00
|
|
|
const handlers = {
|
2020-12-29 08:46:46 +00:00
|
|
|
create: "create.js",
|
|
|
|
issues: "issues.js",
|
|
|
|
ready_for_review: "create.js",
|
|
|
|
pull_request: "pull_request.js",
|
|
|
|
};
|
2020-11-30 10:25:29 +00:00
|
|
|
|
2020-12-29 08:46:46 +00:00
|
|
|
Toolkit.run(async (tools) => {
|
2020-11-30 10:25:29 +00:00
|
|
|
const handlerRef = tools.context.event;
|
2019-07-11 17:14:43 +00:00
|
|
|
|
|
|
|
tools.log.info(`Trying to load handler: "${handlerRef}"...`);
|
|
|
|
|
|
|
|
try {
|
2020-11-30 10:25:29 +00:00
|
|
|
const file = handlers[handlerRef];
|
|
|
|
if (!file) {
|
2020-12-29 08:46:46 +00:00
|
|
|
tools.log.info(`Could not find handler for "${handlerRef}"`);
|
|
|
|
return;
|
2020-11-30 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var eventModule = require(`./lib/handlers/${file}`);
|
2019-07-11 17:14:43 +00:00
|
|
|
} catch (e) {
|
2020-12-29 08:46:46 +00:00
|
|
|
console.log(e);
|
|
|
|
return tools.exit.success(
|
|
|
|
"Failed to load module for event. No action necessary."
|
|
|
|
);
|
2019-07-11 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 08:46:46 +00:00
|
|
|
const moduleAction =
|
|
|
|
eventModule[tools.context.payload.action] ||
|
|
|
|
eventModule[tools.context.payload.ref_type];
|
2019-07-11 17:14:43 +00:00
|
|
|
|
|
|
|
console.log(tools.context.payload);
|
|
|
|
|
|
|
|
if (!moduleAction) {
|
2020-12-29 08:46:46 +00:00
|
|
|
return tools.exit.success(
|
|
|
|
"Failed to find sub handler. No action necessary."
|
|
|
|
);
|
2019-07-11 17:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await moduleAction(tools);
|
|
|
|
} catch (e) {
|
|
|
|
return tools.exit.failure(`Failed to run event handler: ${e}`);
|
|
|
|
}
|
|
|
|
|
2020-12-29 08:46:46 +00:00
|
|
|
tools.exit.success("Executed event handler.");
|
2019-07-11 17:14:43 +00:00
|
|
|
});
|