-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
45 lines (40 loc) · 1.17 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
const createProbot = require('probot-ts')
const { bot } = require('./dist')
const settings = require('./env.json')
process.env.APP_NAME = 'ci-reporter'
const probot = createProbot(settings)
// Creates a Bunyan Stackdriver Logging client
const LoggingBunyan = require('@google-cloud/logging-bunyan')
const loggingBunyan = new LoggingBunyan()
probot.logger.addStream(loggingBunyan.stream())
probot.load(bot)
/**
* Relay GitHub events to the bot
*/
exports.bot = (request, response) => {
const event = request.get('x-github-event') || request.get('X-GitHub-Event')
const id = request.get('x-github-delivery') || request.get('X-GitHub-Delivery')
console.log(`Received event ${event}${request.body.action ? ('.' + request.body.action) : ''}`)
if (event) {
try {
probot.receive({
event: event,
id: id,
payload: request.body
}).then(() => {
response.send({
statusCode: 200,
body: JSON.stringify({
message: 'Executed'
})
})
})
} catch (err) {
console.error(err)
response.sendStatus(500)
}
} else {
console.error(request)
response.sendStatus(400)
}
}