Skip to content

Instantly share code, notes, and snippets.

@diegodorgam
Forked from jefftriplett/invoke.coffee
Created November 13, 2017 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegodorgam/9b8d36feeb823c4ba1599cd5fde61584 to your computer and use it in GitHub Desktop.
Save diegodorgam/9b8d36feeb823c4ba1599cd5fde61584 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