Skip to content

Instantly share code, notes, and snippets.

@olsonjeffery
Created October 28, 2010 03:15
Show Gist options
  • Save olsonjeffery/650546 to your computer and use it in GitHub Desktop.
Save olsonjeffery/650546 to your computer and use it in GitHub Desktop.
exec = require('child_process').exec
spawn = require('child_process').spawn
sha1Hash = (path, cb) ->
curr = process.cwd()
process.chdir path
bleh = ''
exec 'git log -1', (er, o, e) ->
process.chdir curr
sha1 = o.split('\n')[0].replace('commit ', '')[0..7]
cb sha1
pullOnRepo = (path, cb) ->
curr = process.cwd()
process.chdir path
exec 'git pull', (er, o, e) ->
process.chdir curr
sha1Hash path, (sha1) ->
cb sha1
postGist = (code, gistBin, cb) ->
stdout = ''
output = (d) -> stdout += if !!d then d else ''
child = spawn gistBin
child.stdout.addListener 'data', output
child.addListener 'exit', (exitCode) ->
cb stdout
child.stdin.write code
child.stdin.end()
module.exports = {sha1Hash:sha1Hash, pullOnRepo:pullOnRepo, postGist:postGist}
jeff@smoke:~/src/coffeebot$ coffee -c gitinterface.coffee
Error: In gitinterface.coffee, Parse error on line 10: Unexpected 'NUMBER'
at Object.parseError (/home/jeff/lib/coffee-script/lib/parser.js:493:11)
at Object.parse (/home/jeff/lib/coffee-script/lib/parser.js:564:71)
at Object.compile (/home/jeff/lib/coffee-script/lib/coffee-script.js:23:22)
at /home/jeff/lib/coffee-script/lib/command.js:111:33
at /home/jeff/lib/coffee-script/lib/command.js:75:24
at fs:84:13
at node.js:772:9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment