forked from microadam/exso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.js
34 lines (27 loc) · 1.09 KB
/
bootstrap.js
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
module.exports = bootstrap
var express = require('express')
, createParser = require('github-webhook-handler')
, createWebhookHandler = require('./lib/webhook-handler')
, GhApi = require('github4')
, gh = new GhApi({ version: '3.0.0' })
, createRepoManager = require('./lib/repo-manager')
function bootstrap (serviceLocator, actions, cb) {
var server = express()
, repoManager = createRepoManager(serviceLocator)
, webhookOptions =
{ path: '/github/webhook'
, secret: serviceLocator.secrets.webhookSecret
}
, webhookParser = createParser(webhookOptions)
, handleWebhook = createWebhookHandler(serviceLocator, actions)
gh.authenticate({ type: 'token', token: serviceLocator.secrets.githubToken })
server.use(webhookParser)
webhookParser.on('*', handleWebhook)
webhookParser.on('error', function (error) {
serviceLocator.logger.error(error, 'github-webhook-handler error')
})
serviceLocator.register('server', server)
serviceLocator.register('ghApi', gh)
serviceLocator.register('repoManager', repoManager)
cb(null, serviceLocator)
}