diff --git a/source/plugins/installationLifeCycle.ts b/source/plugins/installationLifeCycle.ts index e3459596..421f5943 100644 --- a/source/plugins/installationLifeCycle.ts +++ b/source/plugins/installationLifeCycle.ts @@ -5,30 +5,24 @@ import { RootObject as InstallationCreated } from "../github/events/types/integr import logger from "../logger" export const installationLifeCycle = (event: string, req: express.Request, res: express.Response, ___: any) => { - if (event !== "installation") { - return false - } - - const request = req.body as InstallationCreated - const action = request.action - const installation = request.installation + if (event === "installation") { + const request = req.body as InstallationCreated + const action = request.action + const installation = request.installation - // Create a db entry for any new installation - if (action === "created") { - logger.info("") - logger.info(`## Creating new installation for ${request.installation.account.login}`) - createInstallation(installation, req, res) - return true - } + // Create a db entry for any new installation + if (action === "created") { + logger.info("") + logger.info(`## Creating new installation for ${request.installation.account.login}`) + createInstallation(installation, req, res) + } - // Delete any integrations that have uninstalled Peril :wave: - if (action === "deleted") { - logger.info("") - logger.info(`## Deleting installation ${installation.id}`) - const db = getDB() - db.deleteInstallation(installation.id) - return true + // Delete any integrations that have uninstalled Peril :wave: + if (action === "deleted") { + logger.info("") + logger.info(`## Deleting installation ${installation.id}`) + const db = getDB() + db.deleteInstallation(installation.id) + } } - - return false } diff --git a/source/routing/router.ts b/source/routing/router.ts index 41f5a3af..1ce25b86 100644 --- a/source/routing/router.ts +++ b/source/routing/router.ts @@ -12,6 +12,14 @@ export const githubRouter = (req: Request, res: Response, next: NextFunction) => const event = req.header("X-GitHub-Event") winston.log("router", `Received ${event}:`) + // Creating / Removing installations from the DB + installationLifeCycle(event, req, res, next) + + // There are some webhook events that shouldn't be passed through to users/plugins + if (webhookSkipListForPeril.includes(event)) { + return + } + githubEventPluginHandler(event, req, res, next) // The Peril/Danger runner @@ -29,14 +37,13 @@ export const githubEventPluginHandler = (event: string, req: Request, res: Respo return } - // Creating / Removing installations from the DB - if (installationLifeCycle(event, req, res, next)) { - return - } - // Allow a dev mode recordWebhook(event, req, res, next) // Updating an install when the JSON changes installationSettingsUpdater(event, req, res, next) } + +// Installation addition/removal isn't too useful, and knowing when the repos +// have changed isn't of much value to peril considering how the JSON file is set up +export const webhookSkipListForPeril = ["integration_installation", "installation"]