Skip to content

Commit 1afc275

Browse files
support reported column for get agents (#424)
* support reported column for get agents
1 parent 2b78dfb commit 1afc275

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/logic/entities/Agent.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const _ = require('lodash');
22
const Entity = require('./Entity');
3+
const colors = require('colors');
34

45
class Agent extends Entity {
56
constructor(data) {
@@ -9,11 +10,27 @@ class Agent extends Entity {
910
this.name = data.name;
1011
this.runtimes = data.runtimes;
1112
this.status = _.get(data, 'status.message', 'N/A');
12-
this.defaultColumns = ['name', 'runtimes', 'status'];
13+
const lastReported = _.get(data, 'status.reportedAt', 'N/A');
14+
this.reported = this.pickStatusColor(_.get(data, 'status.healthStatus', 'N/A'))(lastReported);
15+
this.defaultColumns = ['name', 'runtimes', 'status', 'reported'];
16+
}
17+
18+
// eslint-disable-next-line class-methods-use-this
19+
pickStatusColor(healthStatus) {
20+
switch (healthStatus) {
21+
case 'N/A':
22+
return colors.red;
23+
case 'unhealthy':
24+
return colors.yellow;
25+
case 'healthy':
26+
return colors.green;
27+
default:
28+
return colors.red;
29+
}
1330
}
1431

1532
static fromResponse(response) {
16-
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status'));
33+
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status', 'lastReported'));
1734
}
1835
}
1936

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.43.14",
3+
"version": "0.43.15",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)