/*global module*/
var cgh = function (sites, callback) {
    var self = this;
    self.callback = callback;
    self.sites = sites;
    
    return function cgh(req, res, next) {
        if (!req.body || req.method !== 'POST') {
            return next();
        }
        if (Object.keys(self.sites).indexOf(req.url) === -1 ||
            req.header('x-github-event') !== 'push') {
            return next();
        }
        var payload;
        payload = typeof req.body.payload === 'object' ?
            req.body.payload : JSON.parse(req.body.payload);
        var site_data = self.sites[req.url],
            site_url = site_data.url,
            site_branch = site_data.branch;
        if (payload.repository.url === site_url &&
            (!site_branch || payload.ref.indexOf(site_branch) != -1)) {
            res.send({ result: 'ok' }, 200);
            callback(payload.repository.name, payload);            
        } else {
            return next();
        }
    }
};

module.exports = cgh;

@@ -125,25 +125,326 @@
  sites;%0A    
+function getPayload(req) %7B%0A        var payload = req.body;%0A        if (typeof req.body.payload === 'string') %7B%0A            payload = JSON.parse(req.body.payload);%0A        %7D else if (typeof req.body.payload === 'object') %7B%0A            payload = req.body.payload;%0A        %7D%0A        return payload;%0A    %7D
 %0A
-
     return f
@@ -738,125 +738,25 @@
 load
-;%0A        payload = typeof req.body.payload === 'object' ?%0A            req.body.payload : JSON.parse(req.body.payload
+ = getPayload(req
 );%0A 

Support for body-parser module