-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathscm-table.js
More file actions
82 lines (67 loc) · 1.73 KB
/
scm-table.js
File metadata and controls
82 lines (67 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var Table = require('cli-table2');
var moment = require('moment');
var CoreObject = require('core-object');
var RSVP = require('rsvp');
module.exports = CoreObject.extend({
init: function(plugin, revisions) {
this._super(plugin, revisions);
this._plugin = plugin;
this.revisions = revisions;
},
display: function(/* revisions */) {
var table = this._createTable();
this._tableRows(table);
this._plugin.logRaw(table.toString());
return RSVP.resolve();
},
_isWide: function() {
return process.stdout.columns >= 98;
},
_tableHeader: function() {
var head = ['RevisionKey', 'Commit', 'User', 'Branch'];
if (this._isWide()) {
head.push('Deploy time');
}
return head;
},
_createTable: function() {
var head = this._tableHeader();
return new Table({
head: head,
wordWrap: true,
chars: {
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
'mid': '',
'middle': '',
'mid-mid': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '',
'left-mid': '',
'right': '',
'right-mid': ''
}
});
},
_tableRows: function(table) {
this.revisions.forEach(function(revision) {
var data = revision.revisionData;
var row = [
((revision.active) ? '> ' : ' ') + data.revisionKey,
data.scm && data.scm.sha.substr(0,8),
data.scm && data.scm.email,
data.scm && data.scm.branch,
];
if (this._isWide()) {
var value = moment(data.timestamp).format("YYYY/MM/DD HH:mm:ss");
row.push(value);
}
table.push(row);
}.bind(this));
},
});