Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Created December 22, 2014 16:33
Show Gist options
  • Save jefftriplett/9c5d08163dc3f7e0c383 to your computer and use it in GitHub Desktop.
Save jefftriplett/9c5d08163dc3f7e0c383 to your computer and use it in GitHub Desktop.
Hubot + Invoke (python)
# Description:
# Run invoke commands.
#
# Commands:
# hubot invoke <subcommand>
{spawn, exec} = require 'child_process'
module.exports = (robot) ->
# Deploy to staging
robot.respond /invoke (.*)/i, (msg) ->
send = (text, prefix='') ->
msg.send prefix+text
# Get subcommand
subcommand = msg.match[1]
# Tell the user hubot is working on the request
msg.send "Preparing to invoke now..."
# Execute a pyinvoke command
command = "invoke #{subcommand}"
invoke = exec command #, (err, stdout, stderr) ->
invoke.stderr.on 'data', (data) ->
for line in data.toString().split('\n')
send line, 'Error: '
invoke.stdout.on 'data', (data) ->
for line in data.toString().split('\n')
send line
invoke.on 'exit', (code) ->
if code == 0
send "Done #{command}."
else
send "FAILED #{command}. Returned #{code}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment