Skip to content

Commit

Permalink
Merged by Peril
Browse files Browse the repository at this point in the history
Reshuffles the routing around in Peril
  • Loading branch information
peril-staging[bot] authored Aug 28, 2018
2 parents d981dd7 + 88222e4 commit 9b835cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
40 changes: 17 additions & 23 deletions source/plugins/installationLifeCycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 12 additions & 5 deletions source/routing/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

0 comments on commit 9b835cb

Please sign in to comment.