Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 1a8c1a7ad4f8daef151d8518456976211e94bbde @olalonde committed Oct 19, 2012
Showing with 89 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +13 −0 bin/nodehook
  3. +5 −0 example-scripts/deploy.sh
  4. +34 −0 index.js
  5. +22 −0 package.json
@@ -0,0 +1,15 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
@@ -0,0 +1,13 @@
+#!/usr/bin/env node
+
+var nodehook = require('../');
+
+if(process.argv.length < 4) {
+ console.log('Usage: ./nodehook port cmd');
+ console.log('Example: ./nodehook 8855 ./deploy.sh');
+ console.log('Example: ./nodehook 8855 ls -al');
+ process.exit();
+}
+nodehook.port = process.argv[2];
+nodehook.cmd = process.argv[3];
+nodehook.start();
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+cd /deploy/dir
+git fetch origin
+git reset --hard origin/master
@@ -0,0 +1,34 @@
+var express = require('express')
+ , exec = require('child_process').exec;
+
+var githubIPs = ['127.0.0.1', '207.97.227.253', '50.57.128.197', '108.171.174.178'];
+
+module.exports.port = 8855;
+module.exports.cmd = '';
+
+module.exports.start = function() {
+ var app = express();
+ var port = module.exports.port;
+ var cmd = module.exports.cmd;
+ app.configure(function() {
+ app.use(express.bodyParser());
+ app.use(express.cookieParser());
+ app.use(function(req, res, next) {
+ if (githubIPs.indexOf(req.ip) === -1) {
+ return res.send('Request does not come from a known Github IP.');
+ }
+
+ exec(cmd, function(err, stdout, stderr) {
+ if(err) return next(err);
+ console.log(stdout);
+ console.log(stderr);
+ res.send('Hook executed!');
+ });
+ });
+ app.use(express.errorHandler());
+ });
+
+ app.listen(port, function() {
+ console.log('Nodehook listening on port ' + port);
+ });
+}
@@ -0,0 +1,22 @@
+{
+ "name": "nodehook",
+ "version": "0.0.1",
+ "description": "Simple WebHook server to deploy from Github.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": "",
+ "keywords": [
+ "webhook",
+ "github"
+ ],
+ "dependencies": {
+ "express" : ""
+ },
+ "bin": {
+ "nodehook": "./bin/nodehook"
+ },
+ "author": "Olivier Lalonde <olalonde@gmail.com>",
+ "license": "BSD"
+}

0 comments on commit 1a8c1a7

Please sign in to comment.