Skip to content

Instantly share code, notes, and snippets.

@lgomez
Created May 12, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgomez/8e7f2a543f5550128158 to your computer and use it in GitHub Desktop.
Save lgomez/8e7f2a543f5550128158 to your computer and use it in GitHub Desktop.
Simple node github webhook
#!/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);
@lgomez
Copy link
Author

lgomez commented May 12, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment