gitlab-radiator 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -14
- package/public/client.js +1 -1
- package/src/app.js +74 -118
- package/src/auth.js +11 -19
- package/src/config.js +29 -32
- package/src/gitlab/client.js +19 -30
- package/src/gitlab/index.js +43 -126
- package/src/gitlab/pipelines.js +99 -278
- package/src/gitlab/projects.js +43 -93
- package/src/gitlab/runners.js +15 -59
- package/src/less.js +23 -56
- package/src/index.js +0 -5
package/src/app.js
CHANGED
|
@@ -1,129 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
import {basicAuth} from './auth.js'
|
|
2
|
+
import compression from 'compression'
|
|
3
|
+
import {config} from './config.js'
|
|
4
|
+
import express from 'express'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import {fetchOfflineRunners} from './gitlab/runners.js'
|
|
7
|
+
import http from 'http'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import {serveLessAsCss} from './less.js'
|
|
10
|
+
import {Server} from 'socket.io'
|
|
11
|
+
import {update} from './gitlab/index.js'
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _compression = _interopRequireDefault(require("compression"));
|
|
9
|
-
var _config = require("./config");
|
|
10
|
-
var _express = _interopRequireDefault(require("express"));
|
|
11
|
-
var _runners = require("./gitlab/runners");
|
|
12
|
-
var _http = _interopRequireDefault(require("http"));
|
|
13
|
-
var _path = _interopRequireDefault(require("path"));
|
|
14
|
-
var _less = require("./less");
|
|
15
|
-
var _socket = _interopRequireDefault(require("socket.io"));
|
|
16
|
-
var _gitlab = require("./gitlab");
|
|
17
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
-
var app = (0, _express.default)();
|
|
20
|
-
var httpServer = _http.default.Server(app);
|
|
21
|
-
var socketIoServer = (0, _socket.default)(httpServer);
|
|
22
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
const app = express()
|
|
14
|
+
const httpServer = http.Server(app)
|
|
15
|
+
const socketIoServer = new Server(httpServer)
|
|
16
|
+
|
|
17
|
+
if (process.env.NODE_ENV !== 'production' && fs.existsSync('./src/dev-assets.js')) {
|
|
23
18
|
// eslint-disable-next-line global-require
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
bindDevAssets(app);
|
|
19
|
+
const {bindDevAssets} = await import('./dev-assets.js')
|
|
20
|
+
bindDevAssets(app)
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
app.
|
|
30
|
-
app.
|
|
31
|
-
app.use(
|
|
32
|
-
app.use((
|
|
33
|
-
|
|
22
|
+
|
|
23
|
+
app.disable('x-powered-by')
|
|
24
|
+
app.get('/client.css', serveLessAsCss)
|
|
25
|
+
app.use(express.static('public'))
|
|
26
|
+
app.use(compression())
|
|
27
|
+
app.use(basicAuth(config.auth))
|
|
28
|
+
|
|
29
|
+
httpServer.listen(config.port, () => {
|
|
34
30
|
// eslint-disable-next-line no-console
|
|
35
|
-
console.log(
|
|
36
|
-
})
|
|
37
|
-
|
|
31
|
+
console.log(`Listening on port *:${config.port}`)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const globalState = {
|
|
38
35
|
projects: null,
|
|
39
36
|
error: null,
|
|
40
|
-
zoom:
|
|
41
|
-
projectsOrder:
|
|
42
|
-
columns:
|
|
43
|
-
groupSuccessfulProjects:
|
|
44
|
-
};
|
|
45
|
-
socketIoServer.on('connection', socket => {
|
|
46
|
-
socket.emit('state', withDate(globalState));
|
|
47
|
-
});
|
|
48
|
-
function runUpdate() {
|
|
49
|
-
return _runUpdate.apply(this, arguments);
|
|
50
|
-
}
|
|
51
|
-
function _runUpdate() {
|
|
52
|
-
_runUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
53
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
54
|
-
while (1) switch (_context.prev = _context.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
_context.prev = 0;
|
|
57
|
-
_context.next = 3;
|
|
58
|
-
return (0, _gitlab.update)(_config.config);
|
|
59
|
-
case 3:
|
|
60
|
-
globalState.projects = _context.sent;
|
|
61
|
-
_context.next = 6;
|
|
62
|
-
return errorIfRunnerOffline();
|
|
63
|
-
case 6:
|
|
64
|
-
globalState.error = _context.sent;
|
|
65
|
-
socketIoServer.emit('state', withDate(globalState));
|
|
66
|
-
_context.next = 15;
|
|
67
|
-
break;
|
|
68
|
-
case 10:
|
|
69
|
-
_context.prev = 10;
|
|
70
|
-
_context.t0 = _context["catch"](0);
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.error(_context.t0.message);
|
|
73
|
-
globalState.error = "Failed to communicate with GitLab API: ".concat(_context.t0.message);
|
|
74
|
-
socketIoServer.emit('state', withDate(globalState));
|
|
75
|
-
case 15:
|
|
76
|
-
setTimeout(runUpdate, _config.config.interval);
|
|
77
|
-
case 16:
|
|
78
|
-
case "end":
|
|
79
|
-
return _context.stop();
|
|
80
|
-
}
|
|
81
|
-
}, _callee, null, [[0, 10]]);
|
|
82
|
-
}));
|
|
83
|
-
return _runUpdate.apply(this, arguments);
|
|
37
|
+
zoom: config.zoom,
|
|
38
|
+
projectsOrder: config.projectsOrder,
|
|
39
|
+
columns: config.columns,
|
|
40
|
+
groupSuccessfulProjects: config.groupSuccessfulProjects
|
|
84
41
|
}
|
|
85
|
-
|
|
86
|
-
|
|
42
|
+
|
|
43
|
+
socketIoServer.on('connection', (socket) => {
|
|
44
|
+
socket.emit('state', withDate(globalState))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
async function runUpdate() {
|
|
48
|
+
try {
|
|
49
|
+
globalState.projects = await update(config)
|
|
50
|
+
globalState.error = await errorIfRunnerOffline()
|
|
51
|
+
socketIoServer.emit('state', withDate(globalState))
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.error(error.message)
|
|
55
|
+
globalState.error = `Failed to communicate with GitLab API: ${error.message}`
|
|
56
|
+
socketIoServer.emit('state', withDate(globalState))
|
|
57
|
+
}
|
|
58
|
+
setTimeout(runUpdate, config.interval)
|
|
87
59
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
offline: [],
|
|
105
|
-
totalCount: 0
|
|
106
|
-
}), offline = _offlineRunnersPerGit.offline, totalCount = _offlineRunnersPerGit.totalCount;
|
|
107
|
-
if (!(offline.length > 0)) {
|
|
108
|
-
_context2.next = 8;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
names = offline.map(r => r.name).sort().join(', ');
|
|
112
|
-
counts = offline.length === totalCount ? 'All' : "".concat(offline.length, "/").concat(totalCount);
|
|
113
|
-
return _context2.abrupt("return", "".concat(counts, " runners offline: ").concat(names));
|
|
114
|
-
case 8:
|
|
115
|
-
return _context2.abrupt("return", null);
|
|
116
|
-
case 9:
|
|
117
|
-
case "end":
|
|
118
|
-
return _context2.stop();
|
|
119
|
-
}
|
|
120
|
-
}, _callee2);
|
|
121
|
-
}));
|
|
122
|
-
return _errorIfRunnerOffline.apply(this, arguments);
|
|
60
|
+
|
|
61
|
+
async function errorIfRunnerOffline() {
|
|
62
|
+
const offlineRunnersPerGitlab = await Promise.all(config.gitlabs.map(fetchOfflineRunners))
|
|
63
|
+
const {offline, totalCount} = offlineRunnersPerGitlab.reduce((acc, runner) => {
|
|
64
|
+
return {
|
|
65
|
+
offline: acc.offline.concat(runner.offline),
|
|
66
|
+
totalCount: acc.totalCount + runner.totalCount
|
|
67
|
+
}
|
|
68
|
+
}, {offline: [], totalCount: 0})
|
|
69
|
+
|
|
70
|
+
if (offline.length > 0) {
|
|
71
|
+
const names = offline.map(r => r.name).sort().join(', ')
|
|
72
|
+
const counts = offline.length === totalCount ? 'All' : `${offline.length}/${totalCount}`
|
|
73
|
+
return `${counts} runners offline: ${names}`
|
|
74
|
+
}
|
|
75
|
+
return null
|
|
123
76
|
}
|
|
124
|
-
|
|
77
|
+
|
|
78
|
+
runUpdate()
|
|
79
|
+
|
|
125
80
|
function withDate(state) {
|
|
126
|
-
return
|
|
81
|
+
return {
|
|
82
|
+
...state,
|
|
127
83
|
now: Date.now()
|
|
128
|
-
}
|
|
129
|
-
}
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/auth.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import authenticate from 'basic-auth'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.basicAuth = basicAuth;
|
|
8
|
-
var _basicAuth = _interopRequireDefault(require("basic-auth"));
|
|
9
|
-
function basicAuth(auth) {
|
|
3
|
+
export function basicAuth(auth) {
|
|
10
4
|
if (!auth || !auth.username || !auth.password) {
|
|
11
5
|
// eslint-disable-next-line no-console
|
|
12
|
-
console.log('No authentication configured')
|
|
13
|
-
return (req, res, next) => next()
|
|
6
|
+
console.log('No authentication configured')
|
|
7
|
+
return (req, res, next) => next()
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
// eslint-disable-next-line no-console
|
|
17
|
-
console.log('HTTP basic auth enabled')
|
|
11
|
+
console.log('HTTP basic auth enabled')
|
|
18
12
|
return (req, res, next) => {
|
|
19
|
-
|
|
20
|
-
name = _ref.name,
|
|
21
|
-
pass = _ref.pass;
|
|
13
|
+
const {name, pass} = authenticate(req) || {}
|
|
22
14
|
if (auth.username === name && auth.password === pass) {
|
|
23
|
-
next()
|
|
15
|
+
next()
|
|
24
16
|
} else {
|
|
25
|
-
res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"')
|
|
26
|
-
res.status(401).end()
|
|
17
|
+
res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"')
|
|
18
|
+
res.status(401).end()
|
|
27
19
|
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/config.js
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import os from 'os'
|
|
4
|
+
import yaml from 'js-yaml'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var config = exports.config = validate(_jsYaml.default.load(yamlContent));
|
|
15
|
-
config.interval = Number(config.interval || 10) * 1000;
|
|
16
|
-
config.port = Number(config.port || 3000);
|
|
17
|
-
config.zoom = Number(config.zoom || 1.0);
|
|
18
|
-
config.columns = Number(config.columns || 1);
|
|
19
|
-
config.groupSuccessfulProjects = config.groupSuccessfulProjects || false;
|
|
20
|
-
config.projectsOrder = config.projectsOrder || ['name'];
|
|
21
|
-
config.gitlabs = config.gitlabs.map(gitlab => {
|
|
6
|
+
const configFile = expandTilde(process.env.GITLAB_RADIATOR_CONFIG || '~/.gitlab-radiator.yml')
|
|
7
|
+
const yamlContent = fs.readFileSync(configFile, 'utf8')
|
|
8
|
+
export const config = validate(yaml.load(yamlContent))
|
|
9
|
+
|
|
10
|
+
config.interval = Number(config.interval || 10) * 1000
|
|
11
|
+
config.port = Number(config.port || 3000)
|
|
12
|
+
config.zoom = Number(config.zoom || 1.0)
|
|
13
|
+
config.columns = Number(config.columns || 1)
|
|
14
|
+
config.groupSuccessfulProjects = config.groupSuccessfulProjects || false
|
|
15
|
+
config.projectsOrder = config.projectsOrder || ['name']
|
|
16
|
+
config.gitlabs = config.gitlabs.map((gitlab) => {
|
|
22
17
|
return {
|
|
23
18
|
url: gitlab.url,
|
|
24
19
|
ignoreArchived: gitlab.ignoreArchived === undefined ? true : gitlab.ignoreArchived,
|
|
25
20
|
maxNonFailedJobsVisible: Number(gitlab.maxNonFailedJobsVisible || 999999),
|
|
26
|
-
ca: gitlab.caFile &&
|
|
21
|
+
ca: gitlab.caFile && fs.existsSync(gitlab.caFile, 'utf-8') ? fs.readFileSync(gitlab.caFile) : undefined,
|
|
27
22
|
'access-token': gitlab['access-token'] || process.env.GITLAB_ACCESS_TOKEN,
|
|
28
23
|
projects: {
|
|
29
24
|
excludePipelineStatus: (gitlab.projects || {}).excludePipelineStatus || [],
|
|
30
25
|
include: (gitlab.projects || {}).include || '',
|
|
31
26
|
exclude: (gitlab.projects || {}).exclude || ''
|
|
32
27
|
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
config.colors = config.colors || {}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
config.colors = config.colors || {}
|
|
31
|
+
|
|
36
32
|
function expandTilde(path) {
|
|
37
|
-
return path.replace(/^~($|\/|\\)/,
|
|
33
|
+
return path.replace(/^~($|\/|\\)/, `${os.homedir()}$1`)
|
|
38
34
|
}
|
|
35
|
+
|
|
39
36
|
function validate(cfg) {
|
|
40
|
-
|
|
41
|
-
cfg.gitlabs.forEach(gitlab => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
return cfg
|
|
46
|
-
}
|
|
37
|
+
assert.ok(cfg.gitlabs, 'Mandatory gitlab properties missing from configuration file')
|
|
38
|
+
cfg.gitlabs.forEach((gitlab) => {
|
|
39
|
+
assert.ok(gitlab.url, 'Mandatory gitlab url missing from configuration file')
|
|
40
|
+
assert.ok(gitlab['access-token'] || process.env.GITLAB_ACCESS_TOKEN, 'Mandatory gitlab access token missing from configuration (and none present at GITLAB_ACCESS_TOKEN env variable)')
|
|
41
|
+
})
|
|
42
|
+
return cfg
|
|
43
|
+
}
|
package/src/gitlab/client.js
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import https from 'https'
|
|
3
|
+
import url from 'url'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.gitlabRequest = gitlabRequest;
|
|
8
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
-
var _https = _interopRequireDefault(require("https"));
|
|
10
|
-
var _url = _interopRequireDefault(require("url"));
|
|
11
|
-
function gitlabRequest(path, params, gitlab) {
|
|
12
|
-
return lazyClient(gitlab).get(path, {
|
|
13
|
-
params
|
|
14
|
-
});
|
|
5
|
+
export function gitlabRequest(path, params, gitlab) {
|
|
6
|
+
return lazyClient(gitlab).get(path, {params})
|
|
15
7
|
}
|
|
16
|
-
|
|
8
|
+
|
|
9
|
+
const clients = new Map()
|
|
10
|
+
|
|
17
11
|
function lazyClient(gitlab) {
|
|
18
|
-
|
|
12
|
+
const gitlabUrl = gitlab.url
|
|
19
13
|
if (gitlabUrl === undefined) {
|
|
20
14
|
// eslint-disable-next-line no-console
|
|
21
|
-
console.log('Got undefined url for ' + JSON.stringify(gitlab))
|
|
15
|
+
console.log('Got undefined url for ' + JSON.stringify(gitlab))
|
|
22
16
|
}
|
|
23
17
|
if (!clients.get(gitlabUrl)) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ca: gitlab.ca
|
|
32
|
-
}),
|
|
33
|
-
timeout: 30 * 1000
|
|
34
|
-
});
|
|
35
|
-
clients.set(gitlabUrl, client);
|
|
18
|
+
const client = axios.create({
|
|
19
|
+
baseURL: url.resolve(gitlabUrl, '/api/v4/'),
|
|
20
|
+
headers: {'PRIVATE-TOKEN': gitlab['access-token']},
|
|
21
|
+
httpsAgent: new https.Agent({keepAlive: true, ca: gitlab.ca}),
|
|
22
|
+
timeout: 30 * 1000
|
|
23
|
+
})
|
|
24
|
+
clients.set(gitlabUrl, client)
|
|
36
25
|
}
|
|
37
|
-
return clients.get(gitlabUrl)
|
|
38
|
-
}
|
|
26
|
+
return clients.get(gitlabUrl)
|
|
27
|
+
}
|
package/src/gitlab/index.js
CHANGED
|
@@ -1,138 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
import {fetchLatestPipelines} from './pipelines.js'
|
|
2
|
+
import {fetchProjects} from './projects.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.update = update;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
var _pipelines = require("./pipelines");
|
|
14
|
-
var _projects = require("./projects");
|
|
15
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
-
function update(_x) {
|
|
18
|
-
return _update.apply(this, arguments);
|
|
4
|
+
export async function update(config) {
|
|
5
|
+
const projectsWithPipelines = await loadProjectsWithPipelines(config)
|
|
6
|
+
return projectsWithPipelines
|
|
7
|
+
.filter(project => project.pipelines.length > 0)
|
|
19
8
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, _callee);
|
|
36
|
-
}));
|
|
37
|
-
return _update.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
function loadProjectsWithPipelines(_x2) {
|
|
40
|
-
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
41
|
-
}
|
|
42
|
-
function _loadProjectsWithPipelines() {
|
|
43
|
-
_loadProjectsWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(config) {
|
|
44
|
-
var allProjectsWithPipelines;
|
|
45
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
46
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
47
|
-
case 0:
|
|
48
|
-
allProjectsWithPipelines = [];
|
|
49
|
-
_context3.next = 3;
|
|
50
|
-
return Promise.all(config.gitlabs.map( /*#__PURE__*/function () {
|
|
51
|
-
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
52
|
-
var projects, projectsWithPipelines;
|
|
53
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
54
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
_context2.next = 2;
|
|
57
|
-
return (0, _projects.fetchProjects)(gitlab);
|
|
58
|
-
case 2:
|
|
59
|
-
projects = _context2.sent;
|
|
60
|
-
projects.forEach(project => {
|
|
61
|
-
project.maxNonFailedJobsVisible = gitlab.maxNonFailedJobsVisible;
|
|
62
|
-
});
|
|
63
|
-
_context2.next = 6;
|
|
64
|
-
return Promise.all(projects.map(project => projectWithPipelines(project, gitlab)));
|
|
65
|
-
case 6:
|
|
66
|
-
projectsWithPipelines = _context2.sent;
|
|
67
|
-
allProjectsWithPipelines.push.apply(allProjectsWithPipelines, (0, _toConsumableArray2.default)(projectsWithPipelines));
|
|
68
|
-
case 8:
|
|
69
|
-
case "end":
|
|
70
|
-
return _context2.stop();
|
|
71
|
-
}
|
|
72
|
-
}, _callee2);
|
|
73
|
-
}));
|
|
74
|
-
return function (_x5) {
|
|
75
|
-
return _ref3.apply(this, arguments);
|
|
76
|
-
};
|
|
77
|
-
}()));
|
|
78
|
-
case 3:
|
|
79
|
-
return _context3.abrupt("return", allProjectsWithPipelines);
|
|
80
|
-
case 4:
|
|
81
|
-
case "end":
|
|
82
|
-
return _context3.stop();
|
|
83
|
-
}
|
|
84
|
-
}, _callee3);
|
|
85
|
-
}));
|
|
86
|
-
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
87
|
-
}
|
|
88
|
-
function projectWithPipelines(_x3, _x4) {
|
|
89
|
-
return _projectWithPipelines.apply(this, arguments);
|
|
9
|
+
|
|
10
|
+
async function loadProjectsWithPipelines(config) {
|
|
11
|
+
const allProjectsWithPipelines = []
|
|
12
|
+
await Promise.all(config.gitlabs.map(async (gitlab) => {
|
|
13
|
+
const projects = (await fetchProjects(gitlab))
|
|
14
|
+
.map(project => ({
|
|
15
|
+
...project,
|
|
16
|
+
maxNonFailedJobsVisible: gitlab.maxNonFailedJobsVisible
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
for (const project of projects) {
|
|
20
|
+
allProjectsWithPipelines.push(await projectWithPipelines(project, gitlab))
|
|
21
|
+
}
|
|
22
|
+
}))
|
|
23
|
+
return allProjectsWithPipelines
|
|
90
24
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
_context4.t1 = _context4.sent;
|
|
102
|
-
pipelines = (0, _context4.t0)(_context4.t1).filter(excludePipelineStatusFilter(config));
|
|
103
|
-
status = defaultBranchStatus(project, pipelines);
|
|
104
|
-
return _context4.abrupt("return", _objectSpread(_objectSpread({}, project), {}, {
|
|
105
|
-
pipelines,
|
|
106
|
-
status
|
|
107
|
-
}));
|
|
108
|
-
case 7:
|
|
109
|
-
case "end":
|
|
110
|
-
return _context4.stop();
|
|
111
|
-
}
|
|
112
|
-
}, _callee4);
|
|
113
|
-
}));
|
|
114
|
-
return _projectWithPipelines.apply(this, arguments);
|
|
25
|
+
|
|
26
|
+
async function projectWithPipelines(project, config) {
|
|
27
|
+
const pipelines = filterOutEmpty(await fetchLatestPipelines(project.id, config))
|
|
28
|
+
.filter(excludePipelineStatusFilter(config))
|
|
29
|
+
const status = defaultBranchStatus(project, pipelines)
|
|
30
|
+
return {
|
|
31
|
+
...project,
|
|
32
|
+
pipelines,
|
|
33
|
+
status
|
|
34
|
+
}
|
|
115
35
|
}
|
|
36
|
+
|
|
116
37
|
function defaultBranchStatus(project, pipelines) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var status = _ref2.status;
|
|
122
|
-
return status;
|
|
123
|
-
}),
|
|
124
|
-
_pipelines$filter$map2 = (0, _slicedToArray2.default)(_pipelines$filter$map, 1),
|
|
125
|
-
head = _pipelines$filter$map2[0];
|
|
126
|
-
return head;
|
|
38
|
+
const [head] = pipelines
|
|
39
|
+
.filter(({ref}) => ref === project.default_branch)
|
|
40
|
+
.map(({status}) => status)
|
|
41
|
+
return head
|
|
127
42
|
}
|
|
43
|
+
|
|
128
44
|
function filterOutEmpty(pipelines) {
|
|
129
|
-
return pipelines.filter(pipeline => pipeline.stages)
|
|
45
|
+
return pipelines.filter(pipeline => pipeline.stages)
|
|
130
46
|
}
|
|
47
|
+
|
|
131
48
|
function excludePipelineStatusFilter(config) {
|
|
132
49
|
return pipeline => {
|
|
133
50
|
if (config.projects && config.projects.excludePipelineStatus) {
|
|
134
|
-
return !config.projects.excludePipelineStatus.includes(pipeline.status)
|
|
51
|
+
return !config.projects.excludePipelineStatus.includes(pipeline.status)
|
|
135
52
|
}
|
|
136
|
-
return true
|
|
137
|
-
}
|
|
138
|
-
}
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
}
|