Created
May 12, 2015 00:52
-
-
Save lgomez/8e7f2a543f5550128158 to your computer and use it in GitHub Desktop.
Simple node github webhook
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
#!/usr/bin/env node | |
var http = require('http'); | |
var util = require('util'); | |
var sys = require('sys'); | |
var server = http.createServer(function (request, response) { | |
console.log(util.inspect(request.url)); | |
if (request.url === "/path/to/where/you/want/your/webhook/to/be") { | |
response.writeHead(200, {'Content-Type': 'text/html'}); | |
response.end("ok"); | |
var exec = require('child_process').exec; | |
exec("git pull", {cwd: '/path/to/your/clone'}, function puts(error, stdout, stderr) { sys.puts(stdout); }); | |
} else { | |
response.writeHead(400); | |
} | |
}); | |
server.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet creates a simple server that can be used to trigger a
git pull
from a GitHub webhook. Useful for updating code automatically from GitHub.