Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/logic/entities/Agent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash');
const Entity = require('./Entity');
const colors = require('colors');

class Agent extends Entity {
constructor(data) {
Expand All @@ -9,11 +10,27 @@ class Agent extends Entity {
this.name = data.name;
this.runtimes = data.runtimes;
this.status = _.get(data, 'status.message', 'N/A');
this.defaultColumns = ['name', 'runtimes', 'status'];
const lastReported = _.get(data, 'status.reportedAt', 'N/A');
this.reported = this.pickStatusColor(_.get(data, 'status.healthStatus', 'N/A'))(lastReported);
this.defaultColumns = ['name', 'runtimes', 'status', 'reported'];
}

// eslint-disable-next-line class-methods-use-this
pickStatusColor(healthStatus) {
switch (healthStatus) {
case 'N/A':
return colors.red;
case 'unhealthy':
return colors.yellow;
case 'healthy':
return colors.green;
default:
return colors.red;
}
}

static fromResponse(response) {
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status'));
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status', 'lastReported'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.43.14",
"version": "0.43.15",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down