Skip to content

Commit

Permalink
Add basic heroku ps
Browse files Browse the repository at this point in the history
  • Loading branch information
vongrippen committed Mar 26, 2013
1 parent 9cebae6 commit ec6b159
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion heroku.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# hubot heroku <app> config - Display the config vars for an app
# hubot heroku <app> config:set <variable>=<value> - Set a config var for an app
# hubot heroku <app> config:unset <variable> - Delete a config var for an app
# hubot heroku <app> ps - List running Heroku processes for an app
heroku = new (require("heroku")).Heroku({key: process.env.HUBOT_HEROKU_API_KEY})

nodelog = (error, result)->
Expand All @@ -27,6 +28,11 @@ nodelog = (error, result)->
module.exports = (robot)->


###
#
# heroku config
#
###
robot.respond /heroku (.*) config:set (.*)=(.*)/i, configSet
robot.respond /heroku (.*) config:add (.*)=(.*)/i, configSet
configSet = (msg)->
Expand All @@ -50,4 +56,33 @@ module.exports = (robot)->
output = []
for key, value of result
output.push "#{key}: #{value}"
msg.send output.join("\n")
msg.send output.join("\n")

###
#
# herok ps
#
###
robot.respond /heroku (.*) ps$/i, (msg)->
heroku.get_ps msg.match[1], (error, result)->
nodelog error, result
processes = {}

for p in result
processes[p.process.split('.')[0]] ?=
command: p.command
processes: []

processes[p.process.split('.')[0]].processes.push [
"#{p.process}: #{p.state}"
p.transitioned_at.split(' ')[0]
p.transitioned_at.split(' ')[1]
"(~ #{p.pretty_state.split(' ')[2]} ago)"
].join ' '
output = []
for k, v of processes
output.push "== #{k}: `#{v.command}`"
for p in v.processes
output.push p
output.push ''
msg.send output.join "\n"

0 comments on commit ec6b159

Please sign in to comment.