-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch-dashboard.js
231 lines (201 loc) · 6.36 KB
/
branch-dashboard.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
Router.configure({
before: function() {
//console.log('Before All')
}
});
function Branch() {
// Everything prefixed with 'r_' denotes
// some branch property that had values
// which follows the pattern of:
// '' => unknown
// '0' => bad
// '1' => good
// These are pre-set branch attributes
// which must be good for the BranchStatus
// to be 'ready'
this.r_deps = '';
this.r_lint = '';
this.r_style = '';
this.r_mocha = '';
this.r_jasmine = '';
this.r_smoke = '';
this.r_visdiff = '';
this.r_selenium = '';
this.r_nightwatch = '';
this.r_teardown = '';
// Concatonated Title Case to denote that
// this is derived information
this.BranchStatus = function() {
// TODO: Refactor this functionality to set a value
// on the model and only do this calculation if the
// attributes this value depends on have changed
// Right now BranchStatus is only called once per branch so it's
// kinda sorta acceptable.
var checkedAttributes = _.filter(this, function(value, key) {
// We're checking for all attributes beginning with 'r_'
// to allow for checking of branch attributes that aren't
// defined in ths Branch object
return key.substring(0, 2) == "r_";
});
var inProgress = [];
_.each(this, function(value, key) {
// TODO: Definitely want to get some consistency between magic numbers
// that mean stuff here and magic strings that get returned :(
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "2") {
inProgress.push(key);
}
});
var goodShit = [];
_.each(this, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "1") {
goodShit.push(key);
}
});
var badShit = [];
_.each(this, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "0") {
badShit.push(key);
}
});
if (goodShit.length == checkedAttributes.length) {
return 'ready';
} else if (badShit.length > 0) {
return 'broken';
} else if (inProgress.length > 0) {
return 'inProgress';
} else {
return 'unknown';
}
};
}
Branches = new Meteor.Collection('branches', {
transform: function(branch) {
var newBranch = new Branch();
var mergedBranch = _.extend(newBranch, branch);
// TODO: This can be removed after some time that
// mergeable status aren't on any branch objects
delete mergedBranch.r_mergeable;
return mergedBranch;
}
});
Router.map(function() {
this.route('home', {
path: '/',
onRun: function() {
//console.log('load one')
},
onBeforeAction: function() {
//console.log('before one')
}
});
this.route('branchAPI', {
where: 'server',
path: '/api/branch/:remoteName/:branchName',
action: function() {
var request = this.request;
var response = this.response;
var requestData = this.request.body;
//console.log('request', request);
//console.log('response', response);
//console.log('params', this.params, requestData);
var branchName = this.params.branchName;
var TSModified = new Date();
TSModified = TSModified.toUTCString();
requestData.TSModified = TSModified;
response.writeHead(200, {'Content-Type': 'text/html'});
if (request.method === 'POST') {
Branches.upsert({branchName: branchName}, {$set: requestData});
response.end('updated:' + branchName + JSON.stringify(requestData));
} else if (request.method === 'DELETE') {
Branches.remove({branchName: branchName});
response.end('deleted:' + branchName + JSON.stringify(requestData));
}
response.end('Error!'); //TODO: Return proper Error Code
}
});
this.route('branchesAPI', {
where: 'server',
path: '/api/branches',
action: function() {
var request = this.request;
var response = this.response;
var requestData = this.request.body;
//console.log('request', request);
//console.log('response', response);
//console.log('params', this.params, requestData);
response.writeHead(200, {'Content-Type': 'text/html'});
if (request.method === 'POST') {
if (requestData['branchesToKeep']) {
var branchesToKeep = requestData.branchesToKeep.split(',');
branchesToKeep.push("master"); //no need to prune these guys
Branches.remove({branchName: { $nin: branchesToKeep }});
response.end('set tracked branches:' + JSON.stringify(branchesToKeep));
}
}
response.end('Error!'); //TODO: Return proper Error Code
}
});
})
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
/*
Branches.find({}).observe({
added: function(newBranch) {
//console.log('added', newBranch);
},
changed: function(updatedBranch, oldBranch) {
//console.log('changed', updatedBranch);
//Branches.findOne({_id: id}).setBranchStatus;
}
});
*/
}
if (Meteor.isClient) {
Template.branch.helpers({
successes: function() {
var branch = this;
var goodShit = [];
_.each(branch, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "1") {
goodShit.push(key.substring(2));
}
});
return goodShit.sort();
},
inProgress: function() {
var branch = this;
var progressShit = [];
_.each(branch, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "2") {
progressShit.push(key.substring(2));
}
});
return progressShit.sort();
},
unknowns: function() {
var branch = this;
var unknownShit = [];
_.each(branch, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value.length == 0) {
unknownShit.push(key.substring(2));
}
});
return unknownShit.sort();
},
failures: function() {
var branch = this;
var badShit = [];
_.each(branch, function(value, key) {
if (key.substring(0, 2) == "r_" && _.isString(value) && value === "0") {
badShit.push(key.substring(2));
}
});
return badShit.sort();
}
});
Template.branches.allBranches = function () {
return Branches.find({});
};
}