Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reshuffles the routing around in Peril #365

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]