Question

I want to make one of my Ruby script available to my teammates that are not developers (read "reluctant to setup and maintain a Ruby environment").

We're also using a Hubot within our team.

By now, I'm sure you've guessed my question: "how can i write a Hubot script (CoffeeScript, ie JS) that can call my Ruby script?"

ps: my script takes a while to complete, if you guys have an idea on how i could make my hubot give a quick feedback ("i heard you, i'm gonna run your script") and then notify my when the script is done ("your script completed successfully"), it would just be awesome.

Was it helpful?

Solution

I am sure, you have probably figured it out by now, but since this question helped me, I can go off of Sean's answer and complete the puzzle.

module.exports = (robot) ->
    robot.respond /your regex/i, (msg) ->
    cp = require "child_process" 
    cp.exec "./path/from/root/to/ruby script", (error, stdout, stderr) ->  
        if error
            msg.send "Sorry I encounted this error \n" + stderr
        else
            msg.send "Done. The output: \n" + stdout

I hope this helps.

OTHER TIPS

Can you just use exec to run your script? Something like:

module.exports = (robot) ->
  robot.hear /run my command/i, (msg) ->
    exec "cd /path/to/ruby/script && ruby yourscript.rb"
    msg.send "i heard you, i'm gonna run your script."

Hopefully this gets you going on the right path. I'm not sure what kinds of hooks you would need to put in to have it wait until after the exec finishes successfully to notify if the script ran correctly but hopefully google can help with that :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top