accept config filename on command line and add verbose flag

This commit is contained in:
Sami Samhuri 2011-09-27 13:57:10 -07:00
parent cebdca42ba
commit 51b5188a77
3 changed files with 32 additions and 26 deletions

View file

@ -13,15 +13,18 @@ run `npm i --global thepusher`.
Run `thepusher` from the command line. It does not daemonize itself, it only logs to 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. 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. When started, ThePusher displays 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. 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. 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`. 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 ## 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 host github.samhuri.net
port 6177 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 named `server` owned by `samsonjs` you write `samsonjs/server:staging`. If there is one
name it's the branch or tag name, effectively `*/*:name`. 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 Everything after the ref spec is the command. Commands are not quoted, just good old
terrible space splitting. terrible space splitting.

View file

@ -18,6 +18,7 @@
"homepage": "http://samhuri.net/proj/ThePusher", "homepage": "http://samhuri.net/proj/ThePusher",
"dependencies": { "dependencies": {
"batteries": "0.4.x" "batteries": "0.4.x"
, "optimist": "0.2.x"
}, },
"main": "pusher", "main": "pusher",
"bin": { "bin": {

View file

@ -37,9 +37,11 @@ function sha1(s) {
} }
function main() { function main() {
var path = require('path') var args = require('optimist').argv
, eachLine = require('batteries').fs.eachLine , 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) { fs.stat(rcFile, function(err, s) {
if (err) { if (err) {
@ -161,7 +163,7 @@ function parseRequest(req, cb) {
} }
function routeRequest(req, res) { 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') { if (req.url === '/' + serverOptions.githubToken && req.method === 'POST') {
parseRequest(req, function(err, payload) { parseRequest(req, function(err, payload) {
if (err) { if (err) {
@ -231,7 +233,7 @@ function routeRequest(req, res) {
} }
function runCommand(options) { function runCommand(options) {
console.log('>>> running command: ' + options.command) console.log('>>> [' + new Date() + '] running command: ' + options.command)
// TODO quoting // TODO quoting
var args = options.command.split(/\s+/) var args = options.command.split(/\s+/)
, cmd = args.shift() , cmd = args.shift()
@ -242,7 +244,7 @@ function runCommand(options) {
process.env.PUSHER_BRANCH = options.branch || '' process.env.PUSHER_BRANCH = options.branch || ''
process.env.PUSHER_TAG = options.tag || '' process.env.PUSHER_TAG = options.tag || ''
var child = spawn(cmd, args) var child = spawn(cmd, args)
if (options.verbose) { if (serverOptions.verbose) {
child.stdout.on('data', function(b) { console.log('out>>> ' + b) }) child.stdout.on('data', function(b) { console.log('out>>> ' + b) })
child.stderr.on('data', function(b) { console.log('err>>> ' + b) }) child.stderr.on('data', function(b) { console.log('err>>> ' + b) })
} }