mirror of
https://github.com/samsonjs/ThePusher.git
synced 2026-03-25 09:15:57 +00:00
accept config filename on command line and add verbose flag
This commit is contained in:
parent
cebdca42ba
commit
51b5188a77
3 changed files with 32 additions and 26 deletions
11
Readme.md
11
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
|
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.
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
||||||
|
|
|
||||||
46
pusher.js
46
pusher.js
|
|
@ -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) })
|
||||||
}
|
}
|
||||||
|
|
@ -275,30 +277,30 @@ function spiel() {
|
||||||
, ""
|
, ""
|
||||||
, "ThePusher's config file resides at `~/.pusher` and looks like this:"
|
, "ThePusher's config file resides at `~/.pusher` and looks like this:"
|
||||||
, ""
|
, ""
|
||||||
, "host github.samhuri.net"
|
, " host github.samhuri.net"
|
||||||
, "port 6177"
|
, " port 6177"
|
||||||
, ""
|
, ""
|
||||||
, "# a unique identifier used in the receive hook url"
|
, " # a unique identifier used in the receive hook url"
|
||||||
, "token e815fb07bb390b5e47e509fd1e31e0d82e5d9c24"
|
, " token e815fb07bb390b5e47e509fd1e31e0d82e5d9c24"
|
||||||
, ""
|
, ""
|
||||||
, "# a branch named \"feature\" is created"
|
, " # a branch named \"feature\" is created"
|
||||||
, "create branch feature notify-mailing-list.sh"
|
, " create branch feature notify-mailing-list.sh"
|
||||||
, ""
|
, ""
|
||||||
, "# any branch is deleted in a repo named \"my-project\""
|
, " # any branch is deleted in a repo named \"my-project\""
|
||||||
, "delete branch my-project:* notify-mailing-list.sh"
|
, " delete branch my-project:* notify-mailing-list.sh"
|
||||||
, ""
|
, ""
|
||||||
, "# commits are pushed to any branch on samsonjs/ThePusher, fast-forward merge"
|
, " # commits are pushed to any branch on samsonjs/ThePusher, fast-forward merge"
|
||||||
, "# (e.g. https://github.com/samsonjs/ThePusher)"
|
, " # (e.g. https://github.com/samsonjs/ThePusher)"
|
||||||
, "merge branch samsonjs/ThePusher post-to-twitter.sh"
|
, " merge branch samsonjs/ThePusher post-to-twitter.sh"
|
||||||
, ""
|
, ""
|
||||||
, "# someone force pushed to master in any of my projects"
|
, " # someone force pushed to master in any of my projects"
|
||||||
, "force branch samsonjs/*:master send-an-angry-email.sh"
|
, " force branch samsonjs/*:master send-an-angry-email.sh"
|
||||||
, ""
|
, ""
|
||||||
, "# any tag is created in \"my-project\""
|
, " # any tag is created in \"my-project\""
|
||||||
, "create tag my-project:* build-tag.sh"
|
, " create tag my-project:* build-tag.sh"
|
||||||
, ""
|
, ""
|
||||||
, "# any tag is deleted in \"my-project\""
|
, " # any tag is deleted in \"my-project\""
|
||||||
, "delete tag my-project:* delete-build-for-tag.sh"
|
, " delete tag my-project:* delete-build-for-tag.sh"
|
||||||
, ""
|
, ""
|
||||||
, "Create ~/.pusher and run `thepusher` again."
|
, "Create ~/.pusher and run `thepusher` again."
|
||||||
].forEach(function(s) { console.log(s) })
|
].forEach(function(s) { console.log(s) })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue