-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created smoketest verifying the bot starts (#38)
- Loading branch information
Showing
8 changed files
with
73 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ language: node_js | |
node_js: | ||
- 4 | ||
- 5 | ||
- 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
require('dotenv').load({ silent: true }) | ||
|
||
const glob = require('glob') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
const captureRaw = (req, res, buffer) => { req.raw = buffer } | ||
|
||
const app = express() | ||
app.use(bodyParser.json({ verify: captureRaw })) | ||
require('./lib/github-events')(app) | ||
|
||
// load all the files in the scripts folder | ||
glob.sync(process.argv[2] || './scripts/**/*.js').forEach((file) => { | ||
console.log('loading:', file) | ||
require(file)(app) | ||
}) | ||
|
||
module.exports = app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
module.exports = function (app) { | ||
app.get('/ping', (req, res) => { | ||
res.end('pong') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
'use strict' | ||
|
||
require('dotenv').load({ silent: true }) | ||
|
||
const glob = require('glob') | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
const captureRaw = (req, res, buffer) => { req.raw = buffer } | ||
|
||
const app = express() | ||
app.use(bodyParser.json({ verify: captureRaw })) | ||
require('./lib/github-events.js')(app) | ||
|
||
// load all the files in the scripts folder | ||
glob.sync(process.argv[2] || './scripts/**/*.js').forEach((file) => { | ||
console.log('loading:', file) | ||
require(file)(app) | ||
}) | ||
const app = require('./app') | ||
|
||
const port = process.env.PORT || 3000 | ||
app.listen(port, () => { | ||
console.log('Example app listening on port', port) | ||
console.log('Bot 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) | ||
} catch (e) { | ||
console.error('Error while receiving SSE relay message', e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const request = require('request') | ||
|
||
const app = require('../app') | ||
|
||
tap.test('GET /ping responds with status 200 / "pong"', (t) => { | ||
const server = app.listen() | ||
const port = server.address().port | ||
const url = `http://localhost:${port}/ping` | ||
|
||
t.plan(3) | ||
t.tearDown(() => server.close()) | ||
|
||
request(url, (err, res, body) => { | ||
t.equal(err, null) | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.body, 'pong') | ||
}) | ||
}) |
User blocked.