Handle multiple events in your GitHub Action with ease!
npm install @mheap/action-router --save
The router will look for keys that match the event type e.g. pull_request
and the subtype e.g. opened
and execute any functions listed.
If a pull request was opened with the following configuration, pull_request
and pull_request.opened
would run.
const router = require("@mheap/action-router");
const allPrAction = require("./allPrs");
const labelAction = require("./label");
const openAction = require("./open");
router({
"pull_request": [allPrAction],
"pull_request.opened": [openAction],
"pull_request.labeled": [labelAction]
});
You can even run multiple methods in response to an event:
router({
"pull_request.opened": [
openAction,
() => { console.log("This runs too") }
]
});
If you need to pass any data to each called method, you can specify it as the second parameter in router
:
router({
"pull_request.opened": [
openAction,
() => { console.log("This runs too") }
]
}, [someVar, "strings-too"]);