Last active
November 13, 2015 08:31
-
-
Save steel1990/882326430b8587e2440d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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