Skip to content

Instantly share code, notes, and snippets.

@jfriedlaender
Created February 21, 2013 11:52
Show Gist options
  • Save jfriedlaender/5004242 to your computer and use it in GitHub Desktop.
Save jfriedlaender/5004242 to your computer and use it in GitHub Desktop.
Restart your Heroku app with a Hubot script.
# Description:
# Ask Hubot to perform actions on Heroku
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot heroku restart -a <application name>
#
# Author:
# jfriedlaender
# You need to add your api key as a environment variable to hubot, also your user email address.
herokuApiKey = process.env.HEROKU_CONFIG_API_KEY
herokuUser = process.env.HEROKU_CONFIG_USER
module.exports = (robot) ->
robot.respond /heroku restart -a (.*)/i, (msg) ->
application = msg.match[1]
msg.send "Starting the restart process for #{application}..."
msg.http("https://api.heroku.com/apps/#{application}/ps/restart")
.headers(Authorization: "Basic #{new Buffer("#{herokuUser}:#{herokuApiKey}").toString("base64")}", Accept: "application/json", 'Content-Length': 0)
.post() (err, res, body) ->
try
if res.statusCode is 200
msg.send "Restarted #{application}"
return
msg.send JSON.parse(body).error
catch ex
msg.send "Oh no! Something didn't go so well... #{ex}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment