From 971f5d4864038637bb9b7c828cd64dd29866d744 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 10 Oct 2014 17:55:39 +0100 Subject: Fix problem with branch names. Branch names that contained slashes like feature/whatever were not parsed properly. --- jekyll-hook.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jekyll-hook.js b/jekyll-hook.js index 1094f07..5f2453a 100755 --- a/jekyll-hook.js +++ b/jekyll-hook.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node +//#!/usr/bin/env node var config = require('./config.json'); var fs = require('fs'); @@ -32,25 +32,30 @@ app.use(express.bodyParser({ err.status = 403; throw err; } + + req.request_verified = true; } })); // Receive webhook post -app.post('/hooks/jekyll/:branch', function(req, res) { - +app.post('/hooks/jekyll/*', function(req, res) { + // Prevent non verified request from reaching this. + if (!req.request_verified) { + return res.status(403).send('The request could not be verified.'); + } // Close connection res.send(202); // Queue request handler tasks.defer(function(req, res, cb) { var data = req.body; - var branch = req.params.branch; + var branch = req.params[0]; var params = []; // Parse webhook data for internal variables data.repo = data.repository.name; - data.branch = data.ref.split('/')[2]; + data.branch = data.ref.replace('refs/heads/', ''); data.owner = data.repository.owner.name; // End early if not permitted account -- cgit v1.2.3