This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
/
heroku-status.coffee
64 lines (58 loc) · 2.14 KB
/
heroku-status.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Description:
# Show current Heroku status and issues
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot heroku status - Returns the current Heroku status for app operations and tools
# hubot heroku status issues <limit> - Returns a list of recent <limit> issues (default limit is 5)
# hubot heroku status issue <id> - Returns a single issue by ID number
#
# Author:
# juno
module.exports = (robot) ->
robot.respond /heroku status$/i, (msg) ->
status msg
robot.respond /heroku status issues\s?(\d*)/i, (msg) ->
limit = msg.match[1] or 5
statusIssues msg, limit
robot.respond /heroku status issue (\d+)/i, (msg) ->
id = msg.match[1]
statusIssue msg, id
status = (msg) ->
msg.http("https://status.heroku.com/api/v3/current-status")
.get() (err, res, body) ->
try
json = JSON.parse(body)
msg.send "Production: #{json['status']['Production']}\n" +
"Development: #{json['status']['Development']}\n"
catch error
msg.send "Uh oh, I had trouble figuring out what the Heroku cloud is up to."
statusIssues = (msg, limit) ->
limit = msg.match[1] or 5
msg.http("https://status.heroku.com/api/v3/issues?limit=#{limit}")
.get() (err, res, body) ->
try
json = JSON.parse(body)
buildIssue = (issue) ->
s = "[##{issue['id']}] #{issue['title']} "
s += if issue['resolved'] then "(resolved)" else "(unresolved)"
msg.send (buildIssue issue for issue in json).join("\n")
catch error
msg.send "Uh oh, I had trouble figuring out what the Heroku cloud is up to."
statusIssue = (msg, id) ->
msg.http("https://status.heroku.com/api/v3/issues/#{id}")
.get() (err, res, body) ->
try
json = JSON.parse(body)
msg.send "Title: #{json['title']}\n" +
"Resolved: #{json['resolved']}\n" +
"Created: #{json['created_at']}\n" +
"Updated: #{json['updated_at']}\n" +
"URL: https://status.heroku.com/incidents/#{id}\n"
catch error
msg.send "Uh oh, I had trouble figuring out what the Heroku cloud is up to."