gitlab-radiator 3.4.0 → 3.4.1

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.
@@ -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,187 @@
1
- import {basicAuth} from './auth'
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";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
6
+
7
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
+
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+
11
+ var _auth = require("./auth");
12
+
13
+ var _compression = _interopRequireDefault(require("compression"));
14
+
15
+ var _config = require("./config");
16
+
17
+ var _express = _interopRequireDefault(require("express"));
18
+
19
+ var _runners = require("./gitlab/runners");
20
+
21
+ var _http = _interopRequireDefault(require("http"));
22
+
23
+ var _lessMiddleware = _interopRequireDefault(require("less-middleware"));
24
+
25
+ var _os = _interopRequireDefault(require("os"));
26
+
27
+ var _path = _interopRequireDefault(require("path"));
28
+
29
+ var _socket = _interopRequireDefault(require("socket.io"));
30
+
31
+ var _gitlab = require("./gitlab");
32
+
33
+ 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; }
34
+
35
+ 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; }
36
+
37
+ var cacheDir = _path.default.join(_os.default.tmpdir(), 'gitlab-radiator-css-cache');
38
+
39
+ var app = (0, _express.default)();
40
+
41
+ var httpServer = _http.default.Server(app);
42
+
43
+ var socketIoServer = (0, _socket.default)(httpServer);
18
44
 
19
45
  if (process.env.NODE_ENV !== 'production') {
20
46
  // eslint-disable-next-line global-require
21
- const {bindDevAssets} = require('./dev-assets')
22
- bindDevAssets(app)
47
+ var _require = require('./dev-assets'),
48
+ bindDevAssets = _require.bindDevAssets;
49
+
50
+ bindDevAssets(app);
23
51
  }
24
52
 
25
- app.disable('x-powered-by')
26
- app.use(lessMiddleware(`${__dirname}/../public`, {
27
- dest: cacheDir,
28
- preprocess: {
29
- less: (src) => {
30
- let colorLess = ''
31
- Object.keys(config.colors).forEach((stateName) => {
32
- colorLess += `@${stateName}-color:${config.colors[stateName]};`
33
- })
34
- return src + colorLess
35
- }
53
+ app.disable('x-powered-by');
54
+ app.use((0, _lessMiddleware.default)("".concat(__dirname, "/../public"), {
55
+ dest: cacheDir,
56
+ preprocess: {
57
+ less: src => {
58
+ var colorLess = '';
59
+ Object.keys(_config.config.colors).forEach(stateName => {
60
+ colorLess += "@".concat(stateName, "-color:").concat(_config.config.colors[stateName], ";");
61
+ });
62
+ return src + colorLess;
36
63
  }
37
64
  }
38
- ))
39
- app.use(express.static(cacheDir))
40
- app.use(express.static(`${__dirname}/../public`))
41
- app.use(compression())
42
- app.use(basicAuth(config.auth))
43
-
44
- httpServer.listen(config.port, () => {
65
+ }));
66
+ app.use(_express.default.static(cacheDir));
67
+ app.use(_express.default.static("".concat(__dirname, "/../public")));
68
+ app.use((0, _compression.default)());
69
+ app.use((0, _auth.basicAuth)(_config.config.auth));
70
+ httpServer.listen(_config.config.port, () => {
45
71
  // eslint-disable-next-line no-console
46
- console.log(`Listening on port *:${config.port}`)
47
- })
48
-
49
- const globalState = {
72
+ console.log("Listening on port *:".concat(_config.config.port));
73
+ });
74
+ var globalState = {
50
75
  projects: null,
51
76
  error: null,
52
- zoom: config.zoom,
53
- projectsOrder: config.projectsOrder,
54
- columns: config.columns,
55
- groupSuccessfulProjects: config.groupSuccessfulProjects
77
+ zoom: _config.config.zoom,
78
+ projectsOrder: _config.config.projectsOrder,
79
+ columns: _config.config.columns,
80
+ groupSuccessfulProjects: _config.config.groupSuccessfulProjects
81
+ };
82
+ socketIoServer.on('connection', socket => {
83
+ socket.emit('state', withDate(globalState));
84
+ });
85
+
86
+ function runUpdate() {
87
+ return _runUpdate.apply(this, arguments);
56
88
  }
57
89
 
58
- socketIoServer.on('connection', (socket) => {
59
- socket.emit('state', withDate(globalState))
60
- })
61
-
62
- async function runUpdate() {
63
- try {
64
- globalState.projects = await update(config)
65
- globalState.error = await errorIfRunnerOffline()
66
- socketIoServer.emit('state', withDate(globalState))
67
- } catch (error) {
68
- // eslint-disable-next-line no-console
69
- console.error(error.message)
70
- globalState.error = `Failed to communicate with GitLab API: ${error.message}`
71
- socketIoServer.emit('state', withDate(globalState))
72
- }
73
- setTimeout(runUpdate, config.interval)
90
+ function _runUpdate() {
91
+ _runUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
92
+ return _regenerator.default.wrap(function _callee$(_context) {
93
+ while (1) {
94
+ switch (_context.prev = _context.next) {
95
+ case 0:
96
+ _context.prev = 0;
97
+ _context.next = 3;
98
+ return (0, _gitlab.update)(_config.config);
99
+
100
+ case 3:
101
+ globalState.projects = _context.sent;
102
+ _context.next = 6;
103
+ return errorIfRunnerOffline();
104
+
105
+ case 6:
106
+ globalState.error = _context.sent;
107
+ socketIoServer.emit('state', withDate(globalState));
108
+ _context.next = 15;
109
+ break;
110
+
111
+ case 10:
112
+ _context.prev = 10;
113
+ _context.t0 = _context["catch"](0);
114
+ // eslint-disable-next-line no-console
115
+ console.error(_context.t0.message);
116
+ globalState.error = "Failed to communicate with GitLab API: ".concat(_context.t0.message);
117
+ socketIoServer.emit('state', withDate(globalState));
118
+
119
+ case 15:
120
+ setTimeout(runUpdate, _config.config.interval);
121
+
122
+ case 16:
123
+ case "end":
124
+ return _context.stop();
125
+ }
126
+ }
127
+ }, _callee, null, [[0, 10]]);
128
+ }));
129
+ return _runUpdate.apply(this, arguments);
74
130
  }
75
131
 
76
- async function errorIfRunnerOffline() {
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})
132
+ function errorIfRunnerOffline() {
133
+ return _errorIfRunnerOffline.apply(this, arguments);
134
+ }
84
135
 
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
136
+ function _errorIfRunnerOffline() {
137
+ _errorIfRunnerOffline = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
138
+ var offlineRunnersPerGitlab, _offlineRunnersPerGit, offline, totalCount, names, counts;
139
+
140
+ return _regenerator.default.wrap(function _callee2$(_context2) {
141
+ while (1) {
142
+ switch (_context2.prev = _context2.next) {
143
+ case 0:
144
+ _context2.next = 2;
145
+ return Promise.all(_config.config.gitlabs.map(_runners.fetchOfflineRunners));
146
+
147
+ case 2:
148
+ offlineRunnersPerGitlab = _context2.sent;
149
+ _offlineRunnersPerGit = offlineRunnersPerGitlab.reduce((acc, runner) => {
150
+ return {
151
+ offline: acc.offline.concat(runner.offline),
152
+ totalCount: acc.totalCount + runner.totalCount
153
+ };
154
+ }, {
155
+ offline: [],
156
+ totalCount: 0
157
+ }), offline = _offlineRunnersPerGit.offline, totalCount = _offlineRunnersPerGit.totalCount;
158
+
159
+ if (!(offline.length > 0)) {
160
+ _context2.next = 8;
161
+ break;
162
+ }
163
+
164
+ names = offline.map(r => r.name).sort().join(', ');
165
+ counts = offline.length === totalCount ? 'All' : "".concat(offline.length, "/").concat(totalCount);
166
+ return _context2.abrupt("return", "".concat(counts, " runners offline: ").concat(names));
167
+
168
+ case 8:
169
+ return _context2.abrupt("return", null);
170
+
171
+ case 9:
172
+ case "end":
173
+ return _context2.stop();
174
+ }
175
+ }
176
+ }, _callee2);
177
+ }));
178
+ return _errorIfRunnerOffline.apply(this, arguments);
91
179
  }
92
180
 
93
- runUpdate()
181
+ runUpdate();
94
182
 
95
183
  function withDate(state) {
96
- return {
97
- ...state,
184
+ return _objectSpread(_objectSpread({}, state), {}, {
98
185
  now: Date.now()
99
- }
100
- }
186
+ });
187
+ }
package/src/auth.js CHANGED
@@ -1,21 +1,33 @@
1
- import authenticate from 'basic-auth'
1
+ "use strict";
2
2
 
3
- export function basicAuth(auth) {
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.basicAuth = basicAuth;
9
+
10
+ var _basicAuth = _interopRequireDefault(require("basic-auth"));
11
+
12
+ function basicAuth(auth) {
4
13
  if (!auth || !auth.username || !auth.password) {
5
14
  // eslint-disable-next-line no-console
6
- console.log('No authentication configured')
7
- return (req, res, next) => next()
8
- }
15
+ console.log('No authentication configured');
16
+ return (req, res, next) => next();
17
+ } // eslint-disable-next-line no-console
9
18
 
10
- // eslint-disable-next-line no-console
11
- console.log('HTTP basic auth enabled')
19
+
20
+ console.log('HTTP basic auth enabled');
12
21
  return (req, res, next) => {
13
- const {name, pass} = authenticate(req) || {}
22
+ var _ref = (0, _basicAuth.default)(req) || {},
23
+ name = _ref.name,
24
+ pass = _ref.pass;
25
+
14
26
  if (auth.username === name && auth.password === pass) {
15
- next()
27
+ next();
16
28
  } else {
17
- res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"')
18
- res.status(401).end()
29
+ res.setHeader('WWW-Authenticate', 'Basic realm="gitlab-radiator"');
30
+ res.status(401).end();
19
31
  }
20
- }
21
- }
32
+ };
33
+ }
package/src/config.js CHANGED
@@ -1,43 +1,59 @@
1
- import assert from 'assert'
2
- import fs from 'fs'
3
- import os from 'os'
4
- import yaml from 'js-yaml'
5
-
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) => {
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.config = void 0;
9
+
10
+ var _assert = _interopRequireDefault(require("assert"));
11
+
12
+ var _fs = _interopRequireDefault(require("fs"));
13
+
14
+ var _os = _interopRequireDefault(require("os"));
15
+
16
+ var _jsYaml = _interopRequireDefault(require("js-yaml"));
17
+
18
+ var configFile = expandTilde(process.env.GITLAB_RADIATOR_CONFIG || '~/.gitlab-radiator.yml');
19
+
20
+ var yamlContent = _fs.default.readFileSync(configFile, 'utf8');
21
+
22
+ var config = validate(_jsYaml.default.load(yamlContent));
23
+ exports.config = config;
24
+ config.interval = Number(config.interval || 10) * 1000;
25
+ config.port = Number(config.port || 3000);
26
+ config.zoom = Number(config.zoom || 1.0);
27
+ config.columns = Number(config.columns || 1);
28
+ config.groupSuccessfulProjects = config.groupSuccessfulProjects || false;
29
+ config.projectsOrder = config.projectsOrder || ['name'];
30
+ config.gitlabs = config.gitlabs.map(gitlab => {
17
31
  return {
18
32
  url: gitlab.url,
19
33
  ignoreArchived: gitlab.ignoreArchived === undefined ? true : gitlab.ignoreArchived,
20
34
  maxNonFailedJobsVisible: Number(gitlab.maxNonFailedJobsVisible || 999999),
21
- ca: gitlab.caFile && fs.existsSync(gitlab.caFile, 'utf-8') ? fs.readFileSync(gitlab.caFile) : undefined,
35
+ ca: gitlab.caFile && _fs.default.existsSync(gitlab.caFile, 'utf-8') ? _fs.default.readFileSync(gitlab.caFile) : undefined,
22
36
  'access-token': gitlab['access-token'] || process.env.GITLAB_ACCESS_TOKEN,
23
37
  projects: {
24
38
  excludePipelineStatus: (gitlab.projects || {}).excludePipelineStatus || [],
25
39
  include: (gitlab.projects || {}).include || '',
26
40
  exclude: (gitlab.projects || {}).exclude || ''
27
41
  }
28
- }
29
- })
30
- config.colors = config.colors || {}
42
+ };
43
+ });
44
+ config.colors = config.colors || {};
31
45
 
32
46
  function expandTilde(path) {
33
- return path.replace(/^~($|\/|\\)/, `${os.homedir()}$1`)
47
+ return path.replace(/^~($|\/|\\)/, "".concat(_os.default.homedir(), "$1"));
34
48
  }
35
49
 
36
50
  function validate(cfg) {
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
- }
51
+ _assert.default.ok(cfg.gitlabs, 'Mandatory gitlab properties missing from configuration file');
52
+
53
+ cfg.gitlabs.forEach(gitlab => {
54
+ _assert.default.ok(gitlab.url, 'Mandatory gitlab url missing from configuration file');
55
+
56
+ _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)');
57
+ });
58
+ return cfg;
59
+ }
@@ -1,27 +1,49 @@
1
- import axios from 'axios'
2
- import https from 'https'
3
- import url from 'url'
1
+ "use strict";
4
2
 
5
- export function gitlabRequest(path, params, gitlab) {
6
- return lazyClient(gitlab).get(path, {params})
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.gitlabRequest = gitlabRequest;
9
+
10
+ var _axios = _interopRequireDefault(require("axios"));
11
+
12
+ var _https = _interopRequireDefault(require("https"));
13
+
14
+ var _url = _interopRequireDefault(require("url"));
15
+
16
+ function gitlabRequest(path, params, gitlab) {
17
+ return lazyClient(gitlab).get(path, {
18
+ params
19
+ });
7
20
  }
8
21
 
9
- const clients = new Map()
22
+ var clients = new Map();
10
23
 
11
24
  function lazyClient(gitlab) {
12
- const gitlabUrl = gitlab.url
25
+ var gitlabUrl = gitlab.url;
26
+
13
27
  if (gitlabUrl === undefined) {
14
28
  // eslint-disable-next-line no-console
15
- console.log('Got undefined url for ' + JSON.stringify(gitlab))
29
+ console.log('Got undefined url for ' + JSON.stringify(gitlab));
16
30
  }
31
+
17
32
  if (!clients.get(gitlabUrl)) {
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)
33
+ var client = _axios.default.create({
34
+ baseURL: _url.default.resolve(gitlabUrl, '/api/v4/'),
35
+ headers: {
36
+ 'PRIVATE-TOKEN': gitlab['access-token']
37
+ },
38
+ httpsAgent: new _https.default.Agent({
39
+ keepAlive: true,
40
+ ca: gitlab.ca
41
+ }),
42
+ timeout: 30 * 1000
43
+ });
44
+
45
+ clients.set(gitlabUrl, client);
25
46
  }
26
- return clients.get(gitlabUrl)
27
- }
47
+
48
+ return clients.get(gitlabUrl);
49
+ }