gitlab-radiator 3.4.0 → 3.4.2
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 +19 -19
- package/public/client.js +2 -0
- package/public/client.js.LICENSE.txt +38 -0
- package/src/app.js +133 -86
- package/src/auth.js +19 -11
- package/src/config.js +33 -29
- package/src/gitlab/client.js +30 -19
- package/src/gitlab/index.js +127 -41
- package/src/gitlab/pipelines.js +292 -97
- package/src/gitlab/projects.js +97 -43
- package/src/gitlab/runners.js +63 -15
- package/src/index.js +4 -2
- package/.babelrc +0 -4
- package/.eslintrc +0 -13
- package/.github/workflows/test.yml +0 -20
- package/.nvmrc +0 -1
- package/build-npm +0 -19
- package/screenshot.png +0 -0
- package/src/client/.eslintrc +0 -21
- package/src/client/arguments.ts +0 -75
- package/src/client/gitlab-types.ts +0 -54
- package/src/client/groupedProjects.tsx +0 -40
- package/src/client/groups.tsx +0 -59
- package/src/client/index.tsx +0 -95
- package/src/client/info.tsx +0 -16
- package/src/client/jobs.tsx +0 -56
- package/src/client/projects.tsx +0 -51
- package/src/client/renderTimestamp.tsx +0 -45
- package/src/client/stages.tsx +0 -18
- package/src/dev-assets.js +0 -10
- package/test/gitlab/projects.test.js +0 -75
- package/test/gitlab-integration.js +0 -434
- package/tsconfig.json +0 -28
- package/webpack.common.js +0 -25
- package/webpack.dev.js +0 -13
- package/webpack.prod.js +0 -9
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Lodash <https://lodash.com/>
|
|
4
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
5
|
+
* Released under MIT license <https://lodash.com/license>
|
|
6
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
7
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @license React
|
|
12
|
+
* react-dom.production.min.js
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @license React
|
|
22
|
+
* react.production.min.js
|
|
23
|
+
*
|
|
24
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the MIT license found in the
|
|
27
|
+
* LICENSE file in the root directory of this source tree.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @license React
|
|
32
|
+
* scheduler.production.min.js
|
|
33
|
+
*
|
|
34
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
35
|
+
*
|
|
36
|
+
* This source code is licensed under the MIT license found in the
|
|
37
|
+
* LICENSE file in the root directory of this source tree.
|
|
38
|
+
*/
|
package/src/app.js
CHANGED
|
@@ -1,100 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
import compression from 'compression'
|
|
3
|
-
import {config} from './config'
|
|
4
|
-
import express from 'express'
|
|
5
|
-
import {fetchOfflineRunners} from './gitlab/runners'
|
|
6
|
-
import http from 'http'
|
|
7
|
-
import lessMiddleware from 'less-middleware'
|
|
8
|
-
import os from 'os'
|
|
9
|
-
import path from 'path'
|
|
10
|
-
import socketIo from 'socket.io'
|
|
11
|
-
import {update} from './gitlab'
|
|
12
|
-
|
|
13
|
-
const cacheDir = path.join(os.tmpdir(), 'gitlab-radiator-css-cache')
|
|
14
|
-
|
|
15
|
-
const app = express()
|
|
16
|
-
const httpServer = http.Server(app)
|
|
17
|
-
const socketIoServer = socketIo(httpServer)
|
|
1
|
+
"use strict";
|
|
18
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
5
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
6
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
7
|
+
var _auth = require("./auth");
|
|
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 _lessMiddleware = _interopRequireDefault(require("less-middleware"));
|
|
14
|
+
var _os = _interopRequireDefault(require("os"));
|
|
15
|
+
var _path = _interopRequireDefault(require("path"));
|
|
16
|
+
var _socket = _interopRequireDefault(require("socket.io"));
|
|
17
|
+
var _gitlab = require("./gitlab");
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
|
+
var cacheDir = _path.default.join(_os.default.tmpdir(), 'gitlab-radiator-css-cache');
|
|
21
|
+
var app = (0, _express.default)();
|
|
22
|
+
var httpServer = _http.default.Server(app);
|
|
23
|
+
var socketIoServer = (0, _socket.default)(httpServer);
|
|
19
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
20
25
|
// eslint-disable-next-line global-require
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
var _require = require('./dev-assets'),
|
|
27
|
+
bindDevAssets = _require.bindDevAssets;
|
|
28
|
+
bindDevAssets(app);
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
app.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return src + colorLess
|
|
35
|
-
}
|
|
30
|
+
app.disable('x-powered-by');
|
|
31
|
+
app.use((0, _lessMiddleware.default)("".concat(__dirname, "/../public"), {
|
|
32
|
+
dest: cacheDir,
|
|
33
|
+
preprocess: {
|
|
34
|
+
less: src => {
|
|
35
|
+
var colorLess = '';
|
|
36
|
+
Object.keys(_config.config.colors).forEach(stateName => {
|
|
37
|
+
colorLess += "@".concat(stateName, "-color:").concat(_config.config.colors[stateName], ";");
|
|
38
|
+
});
|
|
39
|
+
return src + colorLess;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
))
|
|
39
|
-
app.use(
|
|
40
|
-
app.use(
|
|
41
|
-
app.use(
|
|
42
|
-
app.use(basicAuth(config.auth))
|
|
43
|
-
|
|
44
|
-
httpServer.listen(config.port, () => {
|
|
42
|
+
}));
|
|
43
|
+
app.use(_express.default.static(cacheDir));
|
|
44
|
+
app.use(_express.default.static("".concat(__dirname, "/../public")));
|
|
45
|
+
app.use((0, _compression.default)());
|
|
46
|
+
app.use((0, _auth.basicAuth)(_config.config.auth));
|
|
47
|
+
httpServer.listen(_config.config.port, () => {
|
|
45
48
|
// eslint-disable-next-line no-console
|
|
46
|
-
console.log(
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const globalState = {
|
|
49
|
+
console.log("Listening on port *:".concat(_config.config.port));
|
|
50
|
+
});
|
|
51
|
+
var globalState = {
|
|
50
52
|
projects: null,
|
|
51
53
|
error: null,
|
|
52
|
-
zoom: config.zoom,
|
|
53
|
-
projectsOrder: config.projectsOrder,
|
|
54
|
-
columns: config.columns,
|
|
55
|
-
groupSuccessfulProjects: config.groupSuccessfulProjects
|
|
54
|
+
zoom: _config.config.zoom,
|
|
55
|
+
projectsOrder: _config.config.projectsOrder,
|
|
56
|
+
columns: _config.config.columns,
|
|
57
|
+
groupSuccessfulProjects: _config.config.groupSuccessfulProjects
|
|
58
|
+
};
|
|
59
|
+
socketIoServer.on('connection', socket => {
|
|
60
|
+
socket.emit('state', withDate(globalState));
|
|
61
|
+
});
|
|
62
|
+
function runUpdate() {
|
|
63
|
+
return _runUpdate.apply(this, arguments);
|
|
56
64
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
function _runUpdate() {
|
|
66
|
+
_runUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
67
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
68
|
+
while (1) {
|
|
69
|
+
switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
_context.prev = 0;
|
|
72
|
+
_context.next = 3;
|
|
73
|
+
return (0, _gitlab.update)(_config.config);
|
|
74
|
+
case 3:
|
|
75
|
+
globalState.projects = _context.sent;
|
|
76
|
+
_context.next = 6;
|
|
77
|
+
return errorIfRunnerOffline();
|
|
78
|
+
case 6:
|
|
79
|
+
globalState.error = _context.sent;
|
|
80
|
+
socketIoServer.emit('state', withDate(globalState));
|
|
81
|
+
_context.next = 15;
|
|
82
|
+
break;
|
|
83
|
+
case 10:
|
|
84
|
+
_context.prev = 10;
|
|
85
|
+
_context.t0 = _context["catch"](0);
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
87
|
+
console.error(_context.t0.message);
|
|
88
|
+
globalState.error = "Failed to communicate with GitLab API: ".concat(_context.t0.message);
|
|
89
|
+
socketIoServer.emit('state', withDate(globalState));
|
|
90
|
+
case 15:
|
|
91
|
+
setTimeout(runUpdate, _config.config.interval);
|
|
92
|
+
case 16:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context.stop();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, _callee, null, [[0, 10]]);
|
|
98
|
+
}));
|
|
99
|
+
return _runUpdate.apply(this, arguments);
|
|
74
100
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const offlineRunnersPerGitlab = await Promise.all(config.gitlabs.map(fetchOfflineRunners))
|
|
78
|
-
const {offline, totalCount} = offlineRunnersPerGitlab.reduce((acc, runner) => {
|
|
79
|
-
return {
|
|
80
|
-
offline: acc.offline.concat(runner.offline),
|
|
81
|
-
totalCount: acc.totalCount + runner.totalCount
|
|
82
|
-
}
|
|
83
|
-
}, {offline: [], totalCount: 0})
|
|
84
|
-
|
|
85
|
-
if (offline.length > 0) {
|
|
86
|
-
const names = offline.map(r => r.name).sort().join(', ')
|
|
87
|
-
const counts = offline.length === totalCount ? 'All' : `${offline.length}/${totalCount}`
|
|
88
|
-
return `${counts} runners offline: ${names}`
|
|
89
|
-
}
|
|
90
|
-
return null
|
|
101
|
+
function errorIfRunnerOffline() {
|
|
102
|
+
return _errorIfRunnerOffline.apply(this, arguments);
|
|
91
103
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
function _errorIfRunnerOffline() {
|
|
105
|
+
_errorIfRunnerOffline = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
106
|
+
var offlineRunnersPerGitlab, _offlineRunnersPerGit, offline, totalCount, names, counts;
|
|
107
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
108
|
+
while (1) {
|
|
109
|
+
switch (_context2.prev = _context2.next) {
|
|
110
|
+
case 0:
|
|
111
|
+
_context2.next = 2;
|
|
112
|
+
return Promise.all(_config.config.gitlabs.map(_runners.fetchOfflineRunners));
|
|
113
|
+
case 2:
|
|
114
|
+
offlineRunnersPerGitlab = _context2.sent;
|
|
115
|
+
_offlineRunnersPerGit = offlineRunnersPerGitlab.reduce((acc, runner) => {
|
|
116
|
+
return {
|
|
117
|
+
offline: acc.offline.concat(runner.offline),
|
|
118
|
+
totalCount: acc.totalCount + runner.totalCount
|
|
119
|
+
};
|
|
120
|
+
}, {
|
|
121
|
+
offline: [],
|
|
122
|
+
totalCount: 0
|
|
123
|
+
}), offline = _offlineRunnersPerGit.offline, totalCount = _offlineRunnersPerGit.totalCount;
|
|
124
|
+
if (!(offline.length > 0)) {
|
|
125
|
+
_context2.next = 8;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
names = offline.map(r => r.name).sort().join(', ');
|
|
129
|
+
counts = offline.length === totalCount ? 'All' : "".concat(offline.length, "/").concat(totalCount);
|
|
130
|
+
return _context2.abrupt("return", "".concat(counts, " runners offline: ").concat(names));
|
|
131
|
+
case 8:
|
|
132
|
+
return _context2.abrupt("return", null);
|
|
133
|
+
case 9:
|
|
134
|
+
case "end":
|
|
135
|
+
return _context2.stop();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, _callee2);
|
|
139
|
+
}));
|
|
140
|
+
return _errorIfRunnerOffline.apply(this, arguments);
|
|
141
|
+
}
|
|
142
|
+
runUpdate();
|
|
95
143
|
function withDate(state) {
|
|
96
|
-
return {
|
|
97
|
-
...state,
|
|
144
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
98
145
|
now: Date.now()
|
|
99
|
-
}
|
|
100
|
-
}
|
|
146
|
+
});
|
|
147
|
+
}
|
package/src/auth.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.basicAuth = basicAuth;
|
|
8
|
+
var _basicAuth = _interopRequireDefault(require("basic-auth"));
|
|
9
|
+
function basicAuth(auth) {
|
|
4
10
|
if (!auth || !auth.username || !auth.password) {
|
|
5
11
|
// eslint-disable-next-line no-console
|
|
6
|
-
console.log('No authentication configured')
|
|
7
|
-
return (req, res, next) => next()
|
|
12
|
+
console.log('No authentication configured');
|
|
13
|
+
return (req, res, next) => next();
|
|
8
14
|
}
|
|
9
15
|
|
|
10
16
|
// eslint-disable-next-line no-console
|
|
11
|
-
console.log('HTTP basic auth enabled')
|
|
17
|
+
console.log('HTTP basic auth enabled');
|
|
12
18
|
return (req, res, next) => {
|
|
13
|
-
|
|
19
|
+
var _ref = (0, _basicAuth.default)(req) || {},
|
|
20
|
+
name = _ref.name,
|
|
21
|
+
pass = _ref.pass;
|
|
14
22
|
if (auth.username === name && auth.password === pass) {
|
|
15
|
-
next()
|
|
23
|
+
next();
|
|
16
24
|
} else {
|
|
17
|
-
res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"')
|
|
18
|
-
res.status(401).end()
|
|
25
|
+
res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"');
|
|
26
|
+
res.status(401).end();
|
|
19
27
|
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
28
|
+
};
|
|
29
|
+
}
|
package/src/config.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import os from 'os'
|
|
4
|
-
import yaml from 'js-yaml'
|
|
1
|
+
"use strict";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
config
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.config = void 0;
|
|
8
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _os = _interopRequireDefault(require("os"));
|
|
11
|
+
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
12
|
+
var configFile = expandTilde(process.env.GITLAB_RADIATOR_CONFIG || '~/.gitlab-radiator.yml');
|
|
13
|
+
var yamlContent = _fs.default.readFileSync(configFile, 'utf8');
|
|
14
|
+
var config = validate(_jsYaml.default.load(yamlContent));
|
|
15
|
+
exports.config = config;
|
|
16
|
+
config.interval = Number(config.interval || 10) * 1000;
|
|
17
|
+
config.port = Number(config.port || 3000);
|
|
18
|
+
config.zoom = Number(config.zoom || 1.0);
|
|
19
|
+
config.columns = Number(config.columns || 1);
|
|
20
|
+
config.groupSuccessfulProjects = config.groupSuccessfulProjects || false;
|
|
21
|
+
config.projectsOrder = config.projectsOrder || ['name'];
|
|
22
|
+
config.gitlabs = config.gitlabs.map(gitlab => {
|
|
17
23
|
return {
|
|
18
24
|
url: gitlab.url,
|
|
19
25
|
ignoreArchived: gitlab.ignoreArchived === undefined ? true : gitlab.ignoreArchived,
|
|
20
26
|
maxNonFailedJobsVisible: Number(gitlab.maxNonFailedJobsVisible || 999999),
|
|
21
|
-
ca: gitlab.caFile &&
|
|
27
|
+
ca: gitlab.caFile && _fs.default.existsSync(gitlab.caFile, 'utf-8') ? _fs.default.readFileSync(gitlab.caFile) : undefined,
|
|
22
28
|
'access-token': gitlab['access-token'] || process.env.GITLAB_ACCESS_TOKEN,
|
|
23
29
|
projects: {
|
|
24
30
|
excludePipelineStatus: (gitlab.projects || {}).excludePipelineStatus || [],
|
|
25
31
|
include: (gitlab.projects || {}).include || '',
|
|
26
32
|
exclude: (gitlab.projects || {}).exclude || ''
|
|
27
33
|
}
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
config.colors = config.colors || {}
|
|
31
|
-
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
config.colors = config.colors || {};
|
|
32
37
|
function expandTilde(path) {
|
|
33
|
-
return path.replace(/^~($|\/|\\)/,
|
|
38
|
+
return path.replace(/^~($|\/|\\)/, "".concat(_os.default.homedir(), "$1"));
|
|
34
39
|
}
|
|
35
|
-
|
|
36
40
|
function validate(cfg) {
|
|
37
|
-
|
|
38
|
-
cfg.gitlabs.forEach(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
-
return cfg
|
|
43
|
-
}
|
|
41
|
+
_assert.default.ok(cfg.gitlabs, 'Mandatory gitlab properties missing from configuration file');
|
|
42
|
+
cfg.gitlabs.forEach(gitlab => {
|
|
43
|
+
_assert.default.ok(gitlab.url, 'Mandatory gitlab url missing from configuration file');
|
|
44
|
+
_assert.default.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)');
|
|
45
|
+
});
|
|
46
|
+
return cfg;
|
|
47
|
+
}
|
package/src/gitlab/client.js
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
import https from 'https'
|
|
3
|
-
import url from 'url'
|
|
1
|
+
"use strict";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
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
|
+
});
|
|
7
15
|
}
|
|
8
|
-
|
|
9
|
-
const clients = new Map()
|
|
10
|
-
|
|
16
|
+
var clients = new Map();
|
|
11
17
|
function lazyClient(gitlab) {
|
|
12
|
-
|
|
18
|
+
var gitlabUrl = gitlab.url;
|
|
13
19
|
if (gitlabUrl === undefined) {
|
|
14
20
|
// eslint-disable-next-line no-console
|
|
15
|
-
console.log('Got undefined url for ' + JSON.stringify(gitlab))
|
|
21
|
+
console.log('Got undefined url for ' + JSON.stringify(gitlab));
|
|
16
22
|
}
|
|
17
23
|
if (!clients.get(gitlabUrl)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
var client = _axios.default.create({
|
|
25
|
+
baseURL: _url.default.resolve(gitlabUrl, '/api/v4/'),
|
|
26
|
+
headers: {
|
|
27
|
+
'PRIVATE-TOKEN': gitlab['access-token']
|
|
28
|
+
},
|
|
29
|
+
httpsAgent: new _https.default.Agent({
|
|
30
|
+
keepAlive: true,
|
|
31
|
+
ca: gitlab.ca
|
|
32
|
+
}),
|
|
33
|
+
timeout: 30 * 1000
|
|
34
|
+
});
|
|
35
|
+
clients.set(gitlabUrl, client);
|
|
25
36
|
}
|
|
26
|
-
return clients.get(gitlabUrl)
|
|
27
|
-
}
|
|
37
|
+
return clients.get(gitlabUrl);
|
|
38
|
+
}
|
package/src/gitlab/index.js
CHANGED
|
@@ -1,53 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
import {fetchLatestPipelines} from './pipelines'
|
|
3
|
-
import {fetchProjects} from './projects'
|
|
1
|
+
"use strict";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
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 _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
13
|
+
var _pipelines = require("./pipelines");
|
|
14
|
+
var _projects = require("./projects");
|
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
function update(_x) {
|
|
18
|
+
return _update.apply(this, arguments);
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
function _update() {
|
|
21
|
+
_update = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(config) {
|
|
22
|
+
var projectsWithPipelines;
|
|
23
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
24
|
+
while (1) {
|
|
25
|
+
switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
_context.next = 2;
|
|
28
|
+
return loadProjectsWithPipelines(config);
|
|
29
|
+
case 2:
|
|
30
|
+
projectsWithPipelines = _context.sent;
|
|
31
|
+
return _context.abrupt("return", projectsWithPipelines.filter(project => project.pipelines.length > 0));
|
|
32
|
+
case 4:
|
|
33
|
+
case "end":
|
|
34
|
+
return _context.stop();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, _callee);
|
|
38
|
+
}));
|
|
39
|
+
return _update.apply(this, arguments);
|
|
22
40
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
function loadProjectsWithPipelines(_x2) {
|
|
42
|
+
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
43
|
+
}
|
|
44
|
+
function _loadProjectsWithPipelines() {
|
|
45
|
+
_loadProjectsWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(config) {
|
|
46
|
+
var allProjectsWithPipelines;
|
|
47
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
48
|
+
while (1) {
|
|
49
|
+
switch (_context3.prev = _context3.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
allProjectsWithPipelines = [];
|
|
52
|
+
_context3.next = 3;
|
|
53
|
+
return Promise.all(config.gitlabs.map( /*#__PURE__*/function () {
|
|
54
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
55
|
+
var projects, projectsWithPipelines;
|
|
56
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
57
|
+
while (1) {
|
|
58
|
+
switch (_context2.prev = _context2.next) {
|
|
59
|
+
case 0:
|
|
60
|
+
_context2.next = 2;
|
|
61
|
+
return (0, _projects.fetchProjects)(gitlab);
|
|
62
|
+
case 2:
|
|
63
|
+
projects = _context2.sent;
|
|
64
|
+
projects.forEach(project => {
|
|
65
|
+
project.maxNonFailedJobsVisible = gitlab.maxNonFailedJobsVisible;
|
|
66
|
+
});
|
|
67
|
+
_context2.next = 6;
|
|
68
|
+
return Promise.all(projects.map(project => projectWithPipelines(project, gitlab)));
|
|
69
|
+
case 6:
|
|
70
|
+
projectsWithPipelines = _context2.sent;
|
|
71
|
+
allProjectsWithPipelines.push.apply(allProjectsWithPipelines, (0, _toConsumableArray2.default)(projectsWithPipelines));
|
|
72
|
+
case 8:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context2.stop();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}, _callee2);
|
|
78
|
+
}));
|
|
79
|
+
return function (_x5) {
|
|
80
|
+
return _ref.apply(this, arguments);
|
|
81
|
+
};
|
|
82
|
+
}()));
|
|
83
|
+
case 3:
|
|
84
|
+
return _context3.abrupt("return", allProjectsWithPipelines);
|
|
85
|
+
case 4:
|
|
86
|
+
case "end":
|
|
87
|
+
return _context3.stop();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, _callee3);
|
|
91
|
+
}));
|
|
92
|
+
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
93
|
+
}
|
|
94
|
+
function projectWithPipelines(_x3, _x4) {
|
|
95
|
+
return _projectWithPipelines.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
function _projectWithPipelines() {
|
|
98
|
+
_projectWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(project, config) {
|
|
99
|
+
var pipelines, status;
|
|
100
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
101
|
+
while (1) {
|
|
102
|
+
switch (_context4.prev = _context4.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
_context4.t0 = filterOutEmpty;
|
|
105
|
+
_context4.next = 3;
|
|
106
|
+
return (0, _pipelines.fetchLatestPipelines)(project.id, config);
|
|
107
|
+
case 3:
|
|
108
|
+
_context4.t1 = _context4.sent;
|
|
109
|
+
pipelines = (0, _context4.t0)(_context4.t1).filter(excludePipelineStatusFilter(config));
|
|
110
|
+
status = defaultBranchStatus(project, pipelines);
|
|
111
|
+
return _context4.abrupt("return", _objectSpread(_objectSpread({}, project), {}, {
|
|
112
|
+
pipelines,
|
|
113
|
+
status
|
|
114
|
+
}));
|
|
115
|
+
case 7:
|
|
116
|
+
case "end":
|
|
117
|
+
return _context4.stop();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, _callee4);
|
|
121
|
+
}));
|
|
122
|
+
return _projectWithPipelines.apply(this, arguments);
|
|
33
123
|
}
|
|
34
|
-
|
|
35
124
|
function defaultBranchStatus(project, pipelines) {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.head()
|
|
125
|
+
return (0, _lodash.default)(pipelines).filter({
|
|
126
|
+
ref: project.default_branch
|
|
127
|
+
}).map('status').head();
|
|
40
128
|
}
|
|
41
|
-
|
|
42
129
|
function filterOutEmpty(pipelines) {
|
|
43
|
-
return pipelines.filter(pipeline => pipeline.stages)
|
|
130
|
+
return pipelines.filter(pipeline => pipeline.stages);
|
|
44
131
|
}
|
|
45
|
-
|
|
46
132
|
function excludePipelineStatusFilter(config) {
|
|
47
133
|
return pipeline => {
|
|
48
134
|
if (config.projects && config.projects.excludePipelineStatus) {
|
|
49
|
-
return !config.projects.excludePipelineStatus.includes(pipeline.status)
|
|
135
|
+
return !config.projects.excludePipelineStatus.includes(pipeline.status);
|
|
50
136
|
}
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
}
|
|
137
|
+
return true;
|
|
138
|
+
};
|
|
139
|
+
}
|