diff --git a/Readme.md b/Readme.md index fabf698..ed8162f 100644 --- a/Readme.md +++ b/Readme.md @@ -13,15 +13,18 @@ run `npm i --global thepusher`. Run `thepusher` from the command line. It does not daemonize itself, it only logs to stdout, and it doesn't run at startup. Yet. Pull requests accepted and encouraged. -When you run ThePusher it'll tell you the exact URL to use as your post-receive hook. -Add that URL to all the projects you need to on Github in the Admin panel. +When started, ThePusher displays the exact URL to use as your post-receive hook. +Head over to Github and add that URL in the admin panel of all the projects you want to handle. More specifically go to Admin -> Service Hooks -> Post-receive URLs. Your post-receive URL is `http://host:port/token`, in the config below that would be `http://github.samhuri.net:6177/e815fb07bb390b5e47e509fd1e31e0d82e5d9c24`. +If you want to see output from triggered commands pass in `-v` or `--verbose`. + ## Configuration -ThePusher's config file resides at `~/.pusher` and looks like this: +ThePusher accepts a config file as a command line parameter, and if unspecified the default +config file resides at `~/.pusher`. In either case it looks something like this: host github.samhuri.net port 6177 @@ -62,7 +65,7 @@ one of them is present. To reference the branch or tag named `staging` in the re named `server` owned by `samsonjs` you write `samsonjs/server:staging`. If there is one name it's the branch or tag name, effectively `*/*:name`. -(It's not real globbing the value `*` is just special cased.) +(It's not real globbing, the value `*` is just special cased.) Everything after the ref spec is the command. Commands are not quoted, just good old terrible space splitting. diff --git a/package.json b/package.json index e7f102e..3cc6f6f 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "homepage": "http://samhuri.net/proj/ThePusher", "dependencies": { "batteries": "0.4.x" + , "optimist": "0.2.x" }, "main": "pusher", "bin": { diff --git a/pusher.js b/pusher.js index 0f3a755..c53eb51 100755 --- a/pusher.js +++ b/pusher.js @@ -37,9 +37,11 @@ function sha1(s) { } function main() { - var path = require('path') + var args = require('optimist').argv , eachLine = require('batteries').fs.eachLine - , rcFile = require('path').join(process.env.HOME, '.pusher') + , rcFile = args._[0] || require('path').join(process.env.HOME, '.pusher') + + if (args.v || args.verbose) serverOptions.verbose = true fs.stat(rcFile, function(err, s) { if (err) { @@ -161,7 +163,7 @@ function parseRequest(req, cb) { } function routeRequest(req, res) { - console.log([req.method, req.url, req.connection.remoteAddress, req.headers['content-length'], req.headers['content-type']].join(' ')) + // console.log([req.method, req.url, req.connection.remoteAddress, req.headers['content-length'], req.headers['content-type']].join(' ')) if (req.url === '/' + serverOptions.githubToken && req.method === 'POST') { parseRequest(req, function(err, payload) { if (err) { @@ -231,7 +233,7 @@ function routeRequest(req, res) { } function runCommand(options) { - console.log('>>> running command: ' + options.command) + console.log('>>> [' + new Date() + '] running command: ' + options.command) // TODO quoting var args = options.command.split(/\s+/) , cmd = args.shift() @@ -242,7 +244,7 @@ function runCommand(options) { process.env.PUSHER_BRANCH = options.branch || '' process.env.PUSHER_TAG = options.tag || '' var child = spawn(cmd, args) - if (options.verbose) { + if (serverOptions.verbose) { child.stdout.on('data', function(b) { console.log('out>>> ' + b) }) child.stderr.on('data', function(b) { console.log('err>>> ' + b) }) } @@ -275,30 +277,30 @@ function spiel() { , "" , "ThePusher's config file resides at `~/.pusher` and looks like this:" , "" - , "host github.samhuri.net" - , "port 6177" + , " host github.samhuri.net" + , " port 6177" , "" - , "# a unique identifier used in the receive hook url" - , "token e815fb07bb390b5e47e509fd1e31e0d82e5d9c24" + , " # a unique identifier used in the receive hook url" + , " token e815fb07bb390b5e47e509fd1e31e0d82e5d9c24" , "" - , "# a branch named \"feature\" is created" - , "create branch feature notify-mailing-list.sh" + , " # a branch named \"feature\" is created" + , " create branch feature notify-mailing-list.sh" , "" - , "# any branch is deleted in a repo named \"my-project\"" - , "delete branch my-project:* notify-mailing-list.sh" + , " # any branch is deleted in a repo named \"my-project\"" + , " delete branch my-project:* notify-mailing-list.sh" , "" - , "# commits are pushed to any branch on samsonjs/ThePusher, fast-forward merge" - , "# (e.g. https://github.com/samsonjs/ThePusher)" - , "merge branch samsonjs/ThePusher post-to-twitter.sh" + , " # commits are pushed to any branch on samsonjs/ThePusher, fast-forward merge" + , " # (e.g. https://github.com/samsonjs/ThePusher)" + , " merge branch samsonjs/ThePusher post-to-twitter.sh" , "" - , "# someone force pushed to master in any of my projects" - , "force branch samsonjs/*:master send-an-angry-email.sh" + , " # someone force pushed to master in any of my projects" + , " force branch samsonjs/*:master send-an-angry-email.sh" , "" - , "# any tag is created in \"my-project\"" - , "create tag my-project:* build-tag.sh" + , " # any tag is created in \"my-project\"" + , " create tag my-project:* build-tag.sh" , "" - , "# any tag is deleted in \"my-project\"" - , "delete tag my-project:* delete-build-for-tag.sh" + , " # any tag is deleted in \"my-project\"" + , " delete tag my-project:* delete-build-for-tag.sh" , "" , "Create ~/.pusher and run `thepusher` again." ].forEach(function(s) { console.log(s) })