diff --git a/hook.sh b/hook.sh index 88fbdc1..8781133 100755 --- a/hook.sh +++ b/hook.sh @@ -3,6 +3,16 @@ # DIRECTORY TO THE REPOSITORY REPOSITORY="../repo" +# This deploy key must not have challenge key. +# Uncomment this, if your keys doesn't have default names. +#SSH_KEY="/home//.ssh/" + +eval $(ssh-agent -s) +ssh-add $SSH_KEY + +# test login just in case. +ssh -T git@github.com + cd $REPOSITORY git pull diff --git a/index.js b/index.js index 869438f..a2fb85e 100644 --- a/index.js +++ b/index.js @@ -5,16 +5,24 @@ var url = require('url'); var secret = 'amazingkey'; // secret key of the webhook var port = 8081; // port +var _path = '/git'; + +function resHeadJson(res,code){ + var value = {"Content-Type": "application/json"}; + res.writeHead(code, value); +} http.createServer(function(req, res){ - console.log("request received"); - res.writeHead(400, {"Content-Type": "application/json"}); - + + var path = url.parse(req.url).pathname; + console.log("request received at: ",path); + - if(path!='/push' || req.method != 'POST'){ + if(path!=_path || req.method != 'POST'){ var data = JSON.stringify({"error": "invalid request"}); + resHeadJson(res,400); return res.end(data); } @@ -29,6 +37,7 @@ http.createServer(function(req, res){ if(hash != req.headers['x-hub-signature']){ console.log('invalid key'); var data = JSON.stringify({"error": "invalid key", key: hash}); + resHeadJson(res,403) return res.end(data); } @@ -40,11 +49,10 @@ http.createServer(function(req, res){ console.log(buff.toString('utf-8')); }); - - res.writeHead(400, {"Content-Type": "application/json"}); - + resHeadJson(res,202); var data = JSON.stringify({"success": true}); - return res.end(data); + + return res.end(data); });