forked from nodejs/github-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (34 loc) · 1.11 KB
/
server.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
'use strict'
const child_process = require('child_process')
if (process.env.NODE_REPO_DIR) {
const fs = require('fs')
global._node_repo_dir = fs.realpathSync(process.env.NODE_REPO_DIR)
const out = child_process.spawnSync('git', ['status'], { cwd: global._node_repo_dir })
if (out.status !== 0) {
logger.info(out.stdout)
logger.error(out.stderr)
logger.error('Bad NODE_REPO_DIR. Backport patch testing disabled.')
global._node_repo_dir = false
}
}
const app = require('./app')
const logger = require('./lib/logger')
const port = process.env.PORT || 3000
app.listen(port, () => {
logger.info('Listening on port', port)
})
// may open up an SSE relay channel helpful for local debugging
// of github repository events, wo/having to deploy changes
if (process.env.SSE_RELAY) {
const EventSource = require('eventsource')
const es = new EventSource(process.env.SSE_RELAY)
es.onmessage = (e) => {
try {
const data = JSON.parse(e.data)
if (!data.action) return
app.emitGhEvent(data, logger)
} catch (e) {
logger.error('Error while receiving SSE relay message', e)
}
}
}