1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const color_1 = require("@heroku-cli/color");
|
4 | const command_1 = require("@heroku-cli/command");
|
5 | const cli_ux_1 = require("cli-ux");
|
6 | const distanceInWordsToNow = require("date-fns/distance_in_words_to_now");
|
7 | const http_call_1 = require("http-call");
|
8 | const util_1 = require("../util");
|
9 | class Status extends command_1.Command {
|
10 | async run() {
|
11 | const { flags } = this.parse(Status);
|
12 | const apiPath = '/api/v4/current-status';
|
13 | const capitalize = (str) => str.substr(0, 1).toUpperCase() + str.substr(1);
|
14 | const printStatus = (status) => {
|
15 | const colorize = color_1.default[status];
|
16 | let message = capitalize(status);
|
17 | if (status === 'green') {
|
18 | message = 'No known issues at this time.';
|
19 | }
|
20 | return colorize(message);
|
21 | };
|
22 | let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com';
|
23 | let { body } = await http_call_1.default.get(host + apiPath);
|
24 | if (flags.json) {
|
25 | cli_ux_1.default.styledJSON(body);
|
26 | return;
|
27 | }
|
28 | for (let item of body.status) {
|
29 | let message = printStatus(item.status);
|
30 | this.log(`${(item.system + ':').padEnd(11)}${message}`);
|
31 | }
|
32 | for (let incident of body.incidents) {
|
33 | cli_ux_1.default.log();
|
34 | cli_ux_1.default.styledHeader(`${incident.title} ${color_1.default.yellow(incident.created_at)} ${color_1.default.cyan(incident.full_url)}`);
|
35 | let padding = util_1.maxBy(incident.updates, (i) => i.update_type.length).update_type.length + 0;
|
36 | for (let u of incident.updates) {
|
37 | cli_ux_1.default.log(`${color_1.default.yellow(u.update_type.padEnd(padding))} ${new Date(u.updated_at).toISOString()} (${distanceInWordsToNow(new Date(u.updated_at))} ago)`);
|
38 | cli_ux_1.default.log(`${u.contents}\n`);
|
39 | }
|
40 | }
|
41 | }
|
42 | }
|
43 | Status.description = 'display current status of the Heroku platform';
|
44 | Status.flags = {
|
45 | json: command_1.flags.boolean({ description: 'output in json format' }),
|
46 | };
|
47 | exports.default = Status;
|