gitlab-radiator 3.4.2 → 3.5.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/src/app.js CHANGED
@@ -10,14 +10,11 @@ var _config = require("./config");
10
10
  var _express = _interopRequireDefault(require("express"));
11
11
  var _runners = require("./gitlab/runners");
12
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"));
13
+ var _less = require("./less");
16
14
  var _socket = _interopRequireDefault(require("socket.io"));
17
15
  var _gitlab = require("./gitlab");
18
16
  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
17
  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
18
  var app = (0, _express.default)();
22
19
  var httpServer = _http.default.Server(app);
23
20
  var socketIoServer = (0, _socket.default)(httpServer);
@@ -28,19 +25,7 @@ if (process.env.NODE_ENV !== 'production') {
28
25
  bindDevAssets(app);
29
26
  }
30
27
  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;
40
- }
41
- }
42
- }));
43
- app.use(_express.default.static(cacheDir));
28
+ app.get('/client.css', _less.serveLessAsCss);
44
29
  app.use(_express.default.static("".concat(__dirname, "/../public")));
45
30
  app.use((0, _compression.default)());
46
31
  app.use((0, _auth.basicAuth)(_config.config.auth));
@@ -65,34 +50,32 @@ function runUpdate() {
65
50
  function _runUpdate() {
66
51
  _runUpdate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
67
52
  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
- }
53
+ while (1) switch (_context.prev = _context.next) {
54
+ case 0:
55
+ _context.prev = 0;
56
+ _context.next = 3;
57
+ return (0, _gitlab.update)(_config.config);
58
+ case 3:
59
+ globalState.projects = _context.sent;
60
+ _context.next = 6;
61
+ return errorIfRunnerOffline();
62
+ case 6:
63
+ globalState.error = _context.sent;
64
+ socketIoServer.emit('state', withDate(globalState));
65
+ _context.next = 15;
66
+ break;
67
+ case 10:
68
+ _context.prev = 10;
69
+ _context.t0 = _context["catch"](0);
70
+ // eslint-disable-next-line no-console
71
+ console.error(_context.t0.message);
72
+ globalState.error = "Failed to communicate with GitLab API: ".concat(_context.t0.message);
73
+ socketIoServer.emit('state', withDate(globalState));
74
+ case 15:
75
+ setTimeout(runUpdate, _config.config.interval);
76
+ case 16:
77
+ case "end":
78
+ return _context.stop();
96
79
  }
97
80
  }, _callee, null, [[0, 10]]);
98
81
  }));
@@ -105,35 +88,33 @@ function _errorIfRunnerOffline() {
105
88
  _errorIfRunnerOffline = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
106
89
  var offlineRunnersPerGitlab, _offlineRunnersPerGit, offline, totalCount, names, counts;
107
90
  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
- }
91
+ while (1) switch (_context2.prev = _context2.next) {
92
+ case 0:
93
+ _context2.next = 2;
94
+ return Promise.all(_config.config.gitlabs.map(_runners.fetchOfflineRunners));
95
+ case 2:
96
+ offlineRunnersPerGitlab = _context2.sent;
97
+ _offlineRunnersPerGit = offlineRunnersPerGitlab.reduce((acc, runner) => {
98
+ return {
99
+ offline: acc.offline.concat(runner.offline),
100
+ totalCount: acc.totalCount + runner.totalCount
101
+ };
102
+ }, {
103
+ offline: [],
104
+ totalCount: 0
105
+ }), offline = _offlineRunnersPerGit.offline, totalCount = _offlineRunnersPerGit.totalCount;
106
+ if (!(offline.length > 0)) {
107
+ _context2.next = 8;
108
+ break;
109
+ }
110
+ names = offline.map(r => r.name).sort().join(', ');
111
+ counts = offline.length === totalCount ? 'All' : "".concat(offline.length, "/").concat(totalCount);
112
+ return _context2.abrupt("return", "".concat(counts, " runners offline: ").concat(names));
113
+ case 8:
114
+ return _context2.abrupt("return", null);
115
+ case 9:
116
+ case "end":
117
+ return _context2.stop();
137
118
  }
138
119
  }, _callee2);
139
120
  }));
@@ -21,18 +21,16 @@ function _update() {
21
21
  _update = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(config) {
22
22
  var projectsWithPipelines;
23
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
- }
24
+ while (1) switch (_context.prev = _context.next) {
25
+ case 0:
26
+ _context.next = 2;
27
+ return loadProjectsWithPipelines(config);
28
+ case 2:
29
+ projectsWithPipelines = _context.sent;
30
+ return _context.abrupt("return", projectsWithPipelines.filter(project => project.pipelines.length > 0));
31
+ case 4:
32
+ case "end":
33
+ return _context.stop();
36
34
  }
37
35
  }, _callee);
38
36
  }));
@@ -45,47 +43,43 @@ function _loadProjectsWithPipelines() {
45
43
  _loadProjectsWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(config) {
46
44
  var allProjectsWithPipelines;
47
45
  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
- }
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 _ref = (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 _ref.apply(this, arguments);
76
+ };
77
+ }()));
78
+ case 3:
79
+ return _context3.abrupt("return", allProjectsWithPipelines);
80
+ case 4:
81
+ case "end":
82
+ return _context3.stop();
89
83
  }
90
84
  }, _callee3);
91
85
  }));
@@ -98,24 +92,22 @@ function _projectWithPipelines() {
98
92
  _projectWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(project, config) {
99
93
  var pipelines, status;
100
94
  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
- }
95
+ while (1) switch (_context4.prev = _context4.next) {
96
+ case 0:
97
+ _context4.t0 = filterOutEmpty;
98
+ _context4.next = 3;
99
+ return (0, _pipelines.fetchLatestPipelines)(project.id, config);
100
+ case 3:
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();
119
111
  }
120
112
  }, _callee4);
121
113
  }));