1 | 'use strict';
|
2 |
|
3 | var api = require('request').defaults({
|
4 | json: true,
|
5 | headers: { 'Accept': 'application/vnd.heroku+json;' }
|
6 | });
|
7 |
|
8 | let cli = require('heroku-cli-util');
|
9 | var timeago = require('timeago');
|
10 | var dateFormat = require('dateformat');
|
11 |
|
12 | function capitalize(str) {
|
13 | return str.substr(0, 1).toUpperCase() + str.substr(1);
|
14 | }
|
15 |
|
16 | function printStatus(status) {
|
17 | var message = capitalize(status);
|
18 | var colorize = cli.color[status];
|
19 |
|
20 | if (status === 'green') {
|
21 | message = 'No known issues at this time.';
|
22 | }
|
23 | return (colorize(` ${message} `));
|
24 | }
|
25 |
|
26 | module.exports = {
|
27 | topic: 'status',
|
28 | description: 'Display current status of Heroku Platform',
|
29 | help: 'Example: heroku status',
|
30 | run: cli.command(function () {
|
31 | let host = process.env.HEROKU_STATUS_HOST || 'status.heroku.com';
|
32 | api.get(`https://${host}/api/v3/current-status/`,
|
33 | function (err, _, response) {
|
34 | if (err) { throw err; }
|
35 | console.log('=== Heroku Status');
|
36 | console.log(`Production: ${printStatus(response.status.Production)}`);
|
37 | console.log(`Development: ${printStatus(response.status.Development)}`);
|
38 |
|
39 | response.issues.forEach(function(incident) {
|
40 | console.log(`\n=== ${incident.title} ${dateFormat(incident.created_at, "UTC:h:MM:ss TT Z")} (${incident.full_url})`);
|
41 |
|
42 | incident.updates.forEach(function(update) {
|
43 | console.log(`[${capitalize(update.update_type)}] ${dateFormat(incident.created_at, "UTC:h:MM:ss TT Z")} (${timeago(update.updated_at)}) \n${update.contents}\n `);
|
44 | });
|
45 | });
|
46 | });
|
47 | })
|
48 | };
|