Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support heroku status via '/current-status' API endpoint #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/scripts/heroku-commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,35 @@ module.exports = (robot) ->

heroku.apps(appName).configVars().update keyPair, (error, response) ->
respondToUser(msg, error, "Heroku: #{key} has been unset")

# Status
robot.respond /heroku status/i, (msg) ->
msg.reply "Checking Heroku Status..."

heroku.get "/current-status", (err, response) ->
msg.reply "Production: #{response.status.Production}" +
"Development: #{response.status.Development}"

if (response.status.Production != "green" || response.status.Development != "green")
issuesText = ""

for issue in response.issues
issueText = "========="
issueText += "\n"

issueText += issue.title
issueText += "\n"

issueText += "Resolved: #{issue.resolved}"
issueText += "\n"

issueText += "Created: #{moment().format(issue.created_at)}"
issueText += "\n"

issueText += "Updated: #{moment().format(issue.updated_at)}"
issueText += "\n"

issueText += issue.full_url

issuesText += issueText
msg.reply issuesText
1 change: 1 addition & 0 deletions test/fixtures/status-green.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"status":{"Production":"green","Development":"green"},"issues":[]}
4 changes: 4 additions & 0 deletions test/fixtures/status-red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"status":{"Production":"red", "Development":"red"},
"issues":
[{"created_at":"2014-04-01T17:16:00Z","id":604,"resolved":true,"status_dev":"green","status_prod":"green","title":"Error when deploying certain apps","upcoming":false,"updated_at":"2014-04-02T06:03:49Z","href":"https://status.heroku.com/api/v3/issues/604","full_url":"https://status.heroku.com/incidents/604","updates":[{"contents":"This change was reverted at 7:26 PM PDT (02:26 UTC).","created_at":"2014-04-01T19:26:00Z","id":1961,"incident_id":604,"status_dev":"green","status_prod":"green","title":"Error when deploying certain apps","update_type":"resolved","updated_at":"2014-04-02T06:03:55Z"},{"contents":"At 5:16 PM PDT (00:16 UTC), we deployed a change which validated the list of add-ons being returned from buildpacks. Buildpacks failing this validation would fail with the following error:\r\n\r\n```\r\nInvalid add-on specification. Buildpacks must inform addons as a string.\r\n```\r\n\r\nThis impacted some of our own buildpacks, such as Python, Clojure, and PHP, when these buildpacks did not specify any add-ons to install.","created_at":"2014-04-01T17:16:00Z","id":1960,"incident_id":604,"status_dev":"yellow","status_prod":"green","title":"Error when deploying certain apps","update_type":"issue","updated_at":"2014-04-02T06:04:32Z"}]}]
}
35 changes: 35 additions & 0 deletions test/heroku-commands-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HubotHelper = require("hubot-test-helper")
path = require("path")
chai = require("chai")
nock = require("nock")
moment = require("moment")

process.env.HUBOT_HEROKU_API_KEY = 'fake_key'
{ expect } = chai
Expand Down Expand Up @@ -309,3 +310,37 @@ describe "Heroku Commands", ->
expect(room.messages[2][1]).to.equal("@Damon Heroku: CLOAK_ID has been unset")

done()

describe "heroku status", ->
it "responds with basic info if all services are green", (done) ->
mockHeroku
.get("/current-status")
.replyWithFile(200, __dirname + "/fixtures/status-green.json")

room.user.say "Damon", "hubot heroku status"

waitForReplies 3, room, ->
expect(room.messages[1][1]).to.equal("@Damon Checking Heroku Status...")

expect(room.messages[2][1]).to.contain("Production: green")
expect(room.messages[2][1]).to.contain("Development: green")
done()

it "responds with additional info if any of the services are not green", (done) ->
mockHeroku
.get("/current-status")
.replyWithFile(200, __dirname + "/fixtures/status-red.json")

room.user.say "Damon", "hubot heroku status"

waitForReplies 3, room, ->
expect(room.messages[1][1]).to.equal("@Damon Checking Heroku Status...")

expect(room.messages[2][1]).to.contain("Production: red")
expect(room.messages[2][1]).to.contain("Development: red")
expect(room.messages[3][1]).to.contain("Error when deploying certain apps")
expect(room.messages[3][1]).to.contain("Created: #{moment().format('2014-04-01T17:16:00Z')}")
expect(room.messages[3][1]).to.contain("Updated: #{moment().format('2014-04-02T06:03:49Z')}")
expect(room.messages[3][1]).to.contain("Resolved: true")
expect(room.messages[3][1]).to.contain("https://") # should have link to more details
done()