forked from servo/crowbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomu.js
63 lines (56 loc) · 1.91 KB
/
homu.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
var request = require("request");
function anyBuildersBuilding(builders) {
for (var builder in builders) {
var builderData = builders[builder];
if ('currentBuilds' in builderData && builderData['currentBuilds'].length) {
return true;
}
}
return false;
}
function checkHomuQueue(cb) {
// First check if any buildbot builders report an ongoing build.
retrieveBuildbotBuilders(function(builders) {
if (anyBuildersBuilding(builders)) {
return;
}
// Next see if homu thinks that any PRs are ready to be built.
queueLength(function(numPending, numApproved) {
if (numApproved) {
cb(numPending + numApproved);
}
});
})
}
function queueLength(cb) {
retrieveHomuQueue(function(body) {
var numPending = (body.match(/<td class="pending">/g) || []).length;
var numApproved = (body.match(/<td class="approved">/g) || []).length;
cb(numPending, numApproved);
});
}
function retrieveHomuQueue(cb) {
request("http://build.servo.org/homu/queue/servo", function(err, response, body) {
if (!err && response.statusCode >= 200 && response.statusCode < 300) {
cb(body);
}
});
}
function retrieveBuildbotBuilders(cb) {
request("http://build.servo.org/json/builders/", function(err, response, body) {
if (!err && response.statusCode >= 200 && response.statusCode < 300) {
cb(JSON.parse(body));
}
});
}
function retrieveSlaves(cb) {
request("http://build.servo.org/json/slaves/", function(err, response, body) {
if (!err && response.statusCode >= 200 && response.statusCode < 300) {
cb(JSON.parse(body));
}
});
}
exports.checkHomuQueue = checkHomuQueue;
exports.queueLength = queueLength;
exports._anyBuildersBuilding = anyBuildersBuilding;
exports.retrieveSlaves = retrieveSlaves;