// TODO: Fix this in status.

// 1. The response should be lower case (Development -> development)
// 2. I should add an endpoint that returns the possible status colors (red, yellow, green...) (?)

var api = require('request').defaults({
  json: true,
  headers: { 'Accept': 'application/vnd.heroku+json;' }
});

var colors = require('colors');
var timeago = require('timeago');
var dateFormat = require('dateformat');

function printStatus(status) {
  var message;
  var color = colors.green;
  switch(status) {
    case 'green':
      message =  'No known issues at this time.';
      break;
    case 'red':
      color = colors.red;
      message = 'Red';
      break;
    case 'yellow': // ?
      color = color.yellow;
      message = 'Yellow';
      break;
  }
  return (color(message));
}

module.exports = {
  topic: '_status',
  description: 'Display current status of Heroku Platform',
  help: 'Example: heroku _status',
  needsAuth: false,
  run: function (context) {

    api = api.defaults({auth: context.auth});
    api.get({
      uri: 'https://status.heroku.com/api/v3/current-status/',
      json: true
    }, function (err, _, response) {
      if (err) { throw err; }
      console.log('=== Heroku Status');
      console.log('Development: %s', printStatus(response.status.Development));
      console.log('Production: %s', printStatus(response.status.Production));

      response.issues.forEach(function(incident) {
        console.log('\n=== %s %s', incident.title, dateFormat(incident.created_at, "UTC:h:MM:ss TT Z"));

        incident.updates.forEach(function(update) {
          var updateType = update.update_type.substr(0, 1).toUpperCase() + update.update_type.substr(1); // Capitalize first letter
          console.log('%s (%s) [%s] %s\n', dateFormat(incident.created_at, "UTC:h:MM:ss TT Z"), timeago(update.updated_at), updateType, update.contents)
        });
      });
    });
  }
}

@@ -1,203 +1,4 @@
-// TODO: Fix this in status.%0A%0A// 1. The response should be lower case (Development -%3E development)%0A// 2. I should add an endpoint that returns the possible status colors (red, yellow, green...) (?)%0A%0A
 var 
@@ -215,16 +215,103 @@
 mat');%0A%0A
+function capitalize(str) %7B%0A  return str.substr(0, 1).toUpperCase() + str.substr(1);%0A%7D%0A%0A
 function
@@ -346,16 +346,37 @@
  message
+ = capitalize(status)
 ;%0A  var 
@@ -393,51 +393,43 @@
 lors
-.green;%0A  switch(status) %7B%0A    case
+%5Bstatus%5D;%0A%0A  if (status ===
  'green'
 :%0A  
@@ -424,20 +424,20 @@
  'green'
-:%0A  
+) %7B%0A
     mess
@@ -480,190 +480,8 @@
 .';%0A
-      break;%0A    case 'red':%0A      color = colors.red;%0A      message = 'Red';%0A      break;%0A    case 'yellow': // ?%0A      color = color.yellow;%0A      message = 'Yellow';%0A      break;%0A
   %7D%0A
@@ -1182,16 +1182,21 @@
 == %25s %25s
+ (%25s)
 ', incid
@@ -1257,16 +1257,35 @@
 s TT Z%22)
+, incident.full_url
 );%0A%0A    
@@ -1336,140 +1336,8 @@
 ) %7B%0A
-          var updateType = update.update_type.substr(0, 1).toUpperCase() + update.update_type.substr(1); // Capitalize first letter%0A
     
@@ -1460,18 +1460,38 @@
 t), 
-updateT
+capitalize(update.update_t
 ype
+)
 , up

Add status url and remove redundant code