From f54e124dba07791f1a2f466a6bb3a23abd313577 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 13 May 2017 15:47:35 +0200 Subject: [PATCH] Fix diverging webhook object structure No idea why, but on the server, all data is contained within a single 'payload' property, while I've never seen any such property on my machine. Could be different node or express versions, but in any case, this should fix it so that it just works no matter what. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index c4adbff..e562634 100644 --- a/index.js +++ b/index.js @@ -246,6 +246,10 @@ const Web3 = require('web3'); robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => { let evt = req.header('X-GitHub-Event'); let data = req.body; + // For some reason data is contained in a payload property on one + // machine, but directly in the root of the object on others + if (data.payload) { data = data.payload; } + robot.logger.info(`Received GitHub hook. Event: ${evt}, action: ${data.action}`); if (evt === 'pull_request' && data.action === 'closed') {