From 3070c83a862b1a782ce129fffcc714ffa6d04e2d Mon Sep 17 00:00:00 2001 From: Stanislav Antic Date: Tue, 4 Sep 2018 17:13:55 +0200 Subject: [PATCH] fix bitbucket webhook handler to work with bitbucket >v5.4 --- lib/git/hooks/webhook.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/git/hooks/webhook.js b/lib/git/hooks/webhook.js index bcdb29a..a74e4e4 100644 --- a/lib/git/hooks/webhook.js +++ b/lib/git/hooks/webhook.js @@ -187,15 +187,8 @@ exports.bitbucket = { type: 'bitbucket', isValid: function(req) { - - if (req && req.body && req.body.payload) { - try { - req.body = JSON.parse(req.body.payload); - return req.body && req.body.commits && req.body.commits.length; - /* istanbul ignore next */ - } catch(e) { - // We don't care about a busted message. - } + if (req && req.body && req.body.changes && req.body.eventKey && req.body.eventKey === "repo:refs_changed") { + return req.body && req.body.changes && req.body.changes.length; } return false; @@ -203,15 +196,13 @@ exports.bitbucket = { getHeadChanges: function(req) { var changes = []; - for (var i=0; i