-
Notifications
You must be signed in to change notification settings - Fork 96
/
statuses.js
51 lines (44 loc) · 1.05 KB
/
statuses.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
var stringifyError = require('./stringify-error');
module.exports = function (app, bundle) {
//
// Build statuses
//
app.get('/status/:module', status(bundle));
};
function status(bundle) {
return function (req, res) {
var scope,
version = 'latest',
module = req.params.module,
matches = module.match(/^(@[^/]+)?(\/)?([^@]+)@?(.+)?/);
if (matches) {
scope = matches[1];
module = matches[3] ? matches[3] : module;
version = matches[4] ? matches[4] : version;
}
var subfile = module.split('/');
if (subfile.length > 1) {
module = subfile.shift();
subfile = subfile.join('/');
}
if (scope) {
module = scope + '/' + module;
}
else {
module = module;
}
bundle.status(module, version, function (err, sts) {
if (err) {
return res.json(500, {
ok: false,
message: err.message,
hints: stringifyError.goodbye
});
}
res.json({
module: module,
builds: sts
});
});
};
}