forked from probot/probot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (51 loc) · 1.57 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const bunyan = require('bunyan');
const bunyanFormat = require('bunyan-format');
const sentryStream = require('bunyan-sentry-stream');
const cacheManager = require('cache-manager');
const createIntegration = require('github-integration');
const createWebhook = require('github-webhook-handler');
const Raven = require('raven');
const createRobot = require('./lib/robot');
const createServer = require('./lib/server');
module.exports = options => {
const cache = cacheManager.caching({
store: 'memory',
ttl: 60 * 60 // 1 hour
});
const logger = bunyan.createLogger({
name: 'PRobot',
level: process.env.LOG_LEVEL || 'debug',
stream: bunyanFormat({outputMode: process.env.LOG_FORMAT || 'short'})
});
const webhook = createWebhook({path: '/', secret: options.secret});
const integration = createIntegration({
id: options.id,
cert: options.cert,
debug: process.env.LOG_LEVEL === 'trace'
});
const server = createServer(webhook);
const robot = createRobot({integration, webhook, cache, logger});
if (process.env.SENTRY_URL) {
Raven.disableConsoleAlerts();
Raven.config(process.env.SENTRY_URL, {
captureUnhandledRejections: true,
autoBreadcrumbs: true
}).install({});
logger.addStream(sentryStream(Raven));
}
// Handle case when webhook creation fails
webhook.on('error', err => {
logger.error(err);
});
return {
server,
robot,
start() {
server.listen(options.port);
logger.trace('Listening on http://localhost:' + options.port);
},
load(plugin) {
plugin(robot);
}
};
};