Skip to content

Instantly share code, notes, and snippets.

@steel1990
Last active November 13, 2015 08:31
Show Gist options
  • Save steel1990/882326430b8587e2440d to your computer and use it in GitHub Desktop.
Save steel1990/882326430b8587e2440d to your computer and use it in GitHub Desktop.
var http = require('http');
var createHandler = require('github-webhook-handler');
var bl = require('bl');
var shell = require('shelljs');
var PUBLISH_TAG_REG = /^refs\/tags\/(publish.*)$/i;
module.exports = function (options) {
http.createServer(function (req, res) {
req.pipe(bl(function (err, data) {
if (err) {
console.log('error', err);
res.writeHead(400, { 'content-type': 'application/json' });
res.end(JSON.stringify({ error: 'error' }));
return;
}
data = JSON.parse(data);
if (PUBLISH_TAG_REG.test(data.ref)) {
options.publish(RegExp.$1);
}
res.writeHead(200, { 'content-type': 'application/json' });
res.end('{"ok":true}');
}));
}).listen(7777);
console.log('webhook start at 7777');
};
module.exports({
publish: function (tag) {
console.log('tag is', tag);
shell.exec([
'git pull origin ' + tag,
'git tag'
]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment