forked from mirrors/probot
Merge pull request #203 from anglinb/webhook_patch
Bumps webhook dep and adds webhookPath config
This commit is contained in:
commit
62eaccee71
|
@ -13,6 +13,7 @@ program
|
|||
.option('-s, --secret <secret>', 'Webhook secret of the GitHub App', process.env.WEBHOOK_SECRET)
|
||||
.option('-p, --port <n>', 'Port to start the server on', process.env.PORT || 3000)
|
||||
.option('-P, --private-key <file>', 'Path to certificate of the GitHub App', findPrivateKey)
|
||||
.option('-w, --webhook-path <path>', 'URL path which receives webhooks. Ex: `/webhook`', process.env.WEBHOOK_PATH)
|
||||
.option('-t, --tunnel <subdomain>', 'Expose your local bot to the internet', process.env.SUBDOMAIN || process.env.NODE_ENV !== 'production')
|
||||
.parse(process.argv);
|
||||
|
||||
|
@ -44,7 +45,8 @@ const probot = createProbot({
|
|||
id: program.app,
|
||||
secret: program.secret,
|
||||
cert: program.privateKey,
|
||||
port: program.port
|
||||
port: program.port,
|
||||
webhookPath: program.webhookPath
|
||||
});
|
||||
|
||||
pkgConf('probot').then(pkg => {
|
||||
|
|
2
index.js
2
index.js
|
@ -23,7 +23,7 @@ module.exports = (options = {}) => {
|
|||
serializers
|
||||
});
|
||||
|
||||
const webhook = createWebhook({path: '/', secret: options.secret || 'development'});
|
||||
const webhook = createWebhook({path: options.webhookPath || '/', secret: options.secret || 'development'});
|
||||
const app = createApp({
|
||||
id: options.id,
|
||||
cert: options.cert,
|
||||
|
|
|
@ -1680,9 +1680,7 @@
|
|||
}
|
||||
},
|
||||
"github-webhook-handler": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/github-webhook-handler/-/github-webhook-handler-0.6.0.tgz",
|
||||
"integrity": "sha1-CYHJOMFjWZBkoMVeadyp4hOTxpY=",
|
||||
"version": "github:rvagg/github-webhook-handler#7cfcb5b724a7735f132778cf15245cac8547ff60",
|
||||
"requires": {
|
||||
"bl": "1.1.2",
|
||||
"buffer-equal-constant-time": "1.0.1"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
"express": "^4.15.3",
|
||||
"github": "^9.2.0",
|
||||
"github-app": "^3.0.0",
|
||||
"github-webhook-handler": "^0.6.0",
|
||||
"github-webhook-handler": "rvagg/github-webhook-handler#v0.6.1",
|
||||
"js-yaml": "^3.8.4",
|
||||
"load-plugins": "^2.1.2",
|
||||
"pkg-conf": "^2.0.0",
|
||||
|
|
|
@ -66,6 +66,33 @@ describe('Probot', () => {
|
|||
.expect(200, 'bar')
|
||||
.expect('X-Test', 'bar');
|
||||
});
|
||||
|
||||
it('allows users to configure webhook paths', async () => {
|
||||
probot = createProbot({webhookPath: '/webhook'});
|
||||
probot.load(robot => {
|
||||
const app = robot.route();
|
||||
app.get('/webhook', (req, res) => res.end('get-webhook'));
|
||||
app.post('/webhook', (req, res) => res.end('post-webhook'));
|
||||
});
|
||||
|
||||
// GET requests should succeed
|
||||
await request(probot.server).get('/webhook')
|
||||
.expect(200, 'get-webhook');
|
||||
|
||||
// POST requests should fail b/c webhook path has precedence
|
||||
await request(probot.server).post('/webhook')
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('defaults webhook path to `/`', async () => {
|
||||
// GET requests to `/` should 404 at express level, not 400 at webhook level
|
||||
await request(probot.server).get('/')
|
||||
.expect(404);
|
||||
|
||||
// POST requests to `/` should 400 b/c webhook signature will fail
|
||||
await request(probot.server).post('/')
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('receive', () => {
|
||||
|
|
Loading…
Reference in New Issue