-
Notifications
You must be signed in to change notification settings - Fork 221
/
status.ts
55 lines (44 loc) · 1.74 KB
/
status.ts
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
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import cli from 'cli-ux'
import * as distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
import HTTP from 'http-call'
import {maxBy} from '../util'
export default class Status extends Command {
static description = 'display current status of the Heroku platform'
static flags = {
json: flags.boolean({description: 'output in json format'}),
}
async run() {
const {flags} = this.parse(Status)
const apiPath = '/api/v4/current-status'
const capitalize = (str: string) => str.substr(0, 1).toUpperCase() + str.substr(1)
const printStatus = (status: string) => {
const colorize = (color as any)[status]
let message = capitalize(status)
if (status === 'green') {
message = 'No known issues at this time.'
}
return colorize(message)
}
let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com'
let {body} = await HTTP.get<any>(host + apiPath)
if (flags.json) {
cli.styledJSON(body)
return
}
for (let item of body.status) {
let message = printStatus(item.status)
this.log(`${(item.system + ':').padEnd(11)}${message}`)
}
for (let incident of body.incidents) {
cli.log()
cli.styledHeader(`${incident.title} ${color.yellow(incident.created_at)} ${color.cyan(incident.full_url)}`)
let padding = maxBy(incident.updates, (i: any) => i.update_type.length).update_type.length + 0
for (let u of incident.updates) {
cli.log(`${color.yellow(u.update_type.padEnd(padding))} ${new Date(u.updated_at).toISOString()} (${distanceInWordsToNow(new Date(u.updated_at))} ago)`)
cli.log(`${u.contents}\n`)
}
}
}
}