Skip to content

Instantly share code, notes, and snippets.

@seanghay
Created February 8, 2018 04:37
Show Gist options
  • Save seanghay/8cf6bbf556f640df744215c6f2afc6d5 to your computer and use it in GitHub Desktop.
Save seanghay/8cf6bbf556f640df744215c6f2afc6d5 to your computer and use it in GitHub Desktop.
const shell = require('shelljs');
const http = require('http');
const createHandler = require('node-gitlab-webhook');
const handler = createHandler([{
path: '/webhook',
secret: 'superS3cret'
}
]);
/*
You can add webhook path as much as you need.
*/
http.createServer((req, res) => {
handler(req, res, (err) => {
res.sendCode = 404;
res.end('No such location');
});
}).listen(7777); // PORT
handler.on('error', function (err) {
console.error('Error:', err.message)
})
handler.on('push', function (event) {
console.log(event.payload);
switch (event.path) {
case '/webhook':
console.log('Run Script');
shell.exec('/root/deploy.sh'); // You bash script path
break
default:
// do sth else or nothing
break
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment