Skip to content

Login with ssh keys, better http statuses, flexible path. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/<user>/.ssh/<secret_key>"

eval $(ssh-agent -s)
ssh-add $SSH_KEY

# test login just in case.
ssh -T git@github.com

cd $REPOSITORY

git pull
24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);

});

Expand Down