-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathinstallationLifeCycle.ts
34 lines (29 loc) · 1.1 KB
/
installationLifeCycle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as express from "express"
import { getDB } from "../db/getDB"
import { createInstallation } from "../github/events/create_installation"
import { RootObject as InstallationCreated } from "../github/events/types/integration_installation_created.types"
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
// 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
}
// 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
}
return false
}