UNPKG

1.8 kBJavaScriptView Raw
1'use strict'
2
3const cli = require('heroku-cli-util')
4const co = require('co')
5const sprintf = require('sprintf-js').sprintf
6
7function capitalize (str) {
8 return str.substr(0, 1).toUpperCase() + str.substr(1)
9}
10
11function printStatus (status) {
12 var message = capitalize(status)
13 var colorize = cli.color[status]
14
15 if (status === 'green') {
16 message = 'No known issues at this time.'
17 }
18 return colorize(message)
19}
20
21function * run (context) {
22 const moment = require('moment')
23 const maxBy = require('lodash.maxby')
24 const padEnd = require('lodash.padend')
25 const apiPath = '/api/v4/current-status'
26
27 let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com'
28 let response = (yield cli.got(host + apiPath, {
29 path: apiPath,
30 json: true,
31 headers: { 'Accept': 'application/vnd.heroku+json;' }
32 })).body
33
34 if (context.flags.json) {
35 cli.styledJSON(response)
36 return
37 }
38
39 response.status.forEach(function (item) {
40 var message = printStatus(item.status)
41
42 cli.log(sprintf('%-10s %s', item.system + ':', message))
43 })
44
45 response.incidents.forEach(function (incident) {
46 cli.log()
47 cli.styledHeader(`${incident.title} ${cli.color.yellow(moment(incident.created_at).format('LT'))} ${cli.color.cyan(incident.full_url)}`)
48
49 let padding = maxBy(incident.updates, 'update_type.length').update_type.length + 1
50 incident.updates.forEach((u) => {
51 cli.log(`${cli.color.yellow(padEnd(u.update_type, padding))} ${moment(u.updated_at).format('LT')} (${moment(u.updated_at).fromNow()})`)
52 cli.log(`${u.contents}
53`)
54 })
55 })
56}
57
58module.exports = {
59 topic: 'status',
60 description: 'display current status of Heroku platform',
61 flags: [
62 {name: 'json', description: 'output in json format'}
63 ],
64 run: cli.command(co.wrap(run))
65}