gitlab-radiator 3.3.5 → 3.3.9
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/.babelrc +4 -0
- package/.eslintrc +13 -0
- package/.github/workflows/test.yml +20 -0
- package/.nvmrc +1 -0
- package/README.md +1 -7
- package/build-npm +19 -0
- package/package.json +34 -34
- package/screenshot.png +0 -0
- package/src/app.js +78 -187
- package/src/auth.js +14 -28
- package/src/client/.eslintrc +21 -0
- package/src/client/arguments.ts +75 -0
- package/src/client/gitlab-types.ts +54 -0
- package/src/client/groupedProjects.tsx +40 -0
- package/src/client/groups.tsx +59 -0
- package/src/client/index.tsx +94 -0
- package/src/client/info.tsx +16 -0
- package/src/client/jobs.tsx +56 -0
- package/src/client/projects.tsx +51 -0
- package/src/client/renderTimestamp.tsx +45 -0
- package/src/client/stages.tsx +18 -0
- package/src/config.js +28 -44
- package/src/dev-assets.js +10 -0
- package/src/gitlab/client.js +17 -39
- package/src/gitlab/index.js +45 -167
- package/src/gitlab/pipelines.js +73 -263
- package/src/gitlab/projects.js +43 -126
- package/src/gitlab/runners.js +15 -80
- package/src/index.js +2 -4
- package/test/gitlab/projects.test.js +75 -0
- package/test/gitlab-integration.js +384 -0
- package/tsconfig.json +28 -0
- package/webpack.common.js +25 -0
- package/webpack.dev.js +13 -0
- package/webpack.prod.js +9 -0
- package/public/client.js +0 -2
- package/public/client.js.LICENSE.txt +0 -41
package/src/gitlab/index.js
CHANGED
|
@@ -1,175 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return loadProjectsWithPipelines(config);
|
|
41
|
-
|
|
42
|
-
case 2:
|
|
43
|
-
projectsWithPipelines = _context.sent;
|
|
44
|
-
return _context.abrupt("return", projectsWithPipelines.filter(function (project) {
|
|
45
|
-
return project.pipelines.length > 0;
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
case 4:
|
|
49
|
-
case "end":
|
|
50
|
-
return _context.stop();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, _callee);
|
|
54
|
-
}));
|
|
55
|
-
return _update.apply(this, arguments);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function loadProjectsWithPipelines(_x2) {
|
|
59
|
-
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _loadProjectsWithPipelines() {
|
|
63
|
-
_loadProjectsWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(config) {
|
|
64
|
-
var allProjectsWithPipelines;
|
|
65
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
66
|
-
while (1) {
|
|
67
|
-
switch (_context3.prev = _context3.next) {
|
|
68
|
-
case 0:
|
|
69
|
-
allProjectsWithPipelines = [];
|
|
70
|
-
_context3.next = 3;
|
|
71
|
-
return Promise.all(config.gitlabs.map( /*#__PURE__*/function () {
|
|
72
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
73
|
-
var projects, projectsWithPipelines;
|
|
74
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
75
|
-
while (1) {
|
|
76
|
-
switch (_context2.prev = _context2.next) {
|
|
77
|
-
case 0:
|
|
78
|
-
_context2.next = 2;
|
|
79
|
-
return (0, _projects.fetchProjects)(gitlab);
|
|
80
|
-
|
|
81
|
-
case 2:
|
|
82
|
-
projects = _context2.sent;
|
|
83
|
-
projects.forEach(function (project) {
|
|
84
|
-
project.maxNonFailedJobsVisible = gitlab.maxNonFailedJobsVisible;
|
|
85
|
-
});
|
|
86
|
-
_context2.next = 6;
|
|
87
|
-
return Promise.all(projects.map(function (project) {
|
|
88
|
-
return projectWithPipelines(project, gitlab);
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
case 6:
|
|
92
|
-
projectsWithPipelines = _context2.sent;
|
|
93
|
-
allProjectsWithPipelines.push.apply(allProjectsWithPipelines, (0, _toConsumableArray2.default)(projectsWithPipelines));
|
|
94
|
-
|
|
95
|
-
case 8:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context2.stop();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, _callee2);
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
return function (_x5) {
|
|
104
|
-
return _ref.apply(this, arguments);
|
|
105
|
-
};
|
|
106
|
-
}()));
|
|
107
|
-
|
|
108
|
-
case 3:
|
|
109
|
-
return _context3.abrupt("return", allProjectsWithPipelines);
|
|
110
|
-
|
|
111
|
-
case 4:
|
|
112
|
-
case "end":
|
|
113
|
-
return _context3.stop();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}, _callee3);
|
|
117
|
-
}));
|
|
118
|
-
return _loadProjectsWithPipelines.apply(this, arguments);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function projectWithPipelines(_x3, _x4) {
|
|
122
|
-
return _projectWithPipelines.apply(this, arguments);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function _projectWithPipelines() {
|
|
126
|
-
_projectWithPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(project, config) {
|
|
127
|
-
var pipelines, status;
|
|
128
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
129
|
-
while (1) {
|
|
130
|
-
switch (_context4.prev = _context4.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
_context4.t0 = filterOutEmpty;
|
|
133
|
-
_context4.next = 3;
|
|
134
|
-
return (0, _pipelines.fetchLatestPipelines)(project.id, config);
|
|
135
|
-
|
|
136
|
-
case 3:
|
|
137
|
-
_context4.t1 = _context4.sent;
|
|
138
|
-
pipelines = (0, _context4.t0)(_context4.t1).filter(excludePipelineStatusFilter(config));
|
|
139
|
-
status = masterBranchStatus(pipelines);
|
|
140
|
-
return _context4.abrupt("return", _objectSpread(_objectSpread({}, project), {}, {
|
|
141
|
-
pipelines,
|
|
142
|
-
status
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
case 7:
|
|
146
|
-
case "end":
|
|
147
|
-
return _context4.stop();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}, _callee4);
|
|
151
|
-
}));
|
|
152
|
-
return _projectWithPipelines.apply(this, arguments);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function masterBranchStatus(pipelines) {
|
|
156
|
-
return (0, _lodash.default)(pipelines).filter({
|
|
157
|
-
ref: 'master'
|
|
158
|
-
}).map('status').head();
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import {fetchLatestPipelines} from './pipelines'
|
|
3
|
+
import {fetchProjects} from './projects'
|
|
4
|
+
|
|
5
|
+
export async function update(config) {
|
|
6
|
+
const projectsWithPipelines = await loadProjectsWithPipelines(config)
|
|
7
|
+
return projectsWithPipelines
|
|
8
|
+
.filter(project => project.pipelines.length > 0)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function loadProjectsWithPipelines(config) {
|
|
12
|
+
const allProjectsWithPipelines = []
|
|
13
|
+
await Promise.all(config.gitlabs.map(async (gitlab) => {
|
|
14
|
+
const projects = await fetchProjects(gitlab)
|
|
15
|
+
projects.forEach((project) => {
|
|
16
|
+
project.maxNonFailedJobsVisible = gitlab.maxNonFailedJobsVisible
|
|
17
|
+
})
|
|
18
|
+
const projectsWithPipelines = await Promise.all(projects.map(project => projectWithPipelines(project, gitlab)))
|
|
19
|
+
allProjectsWithPipelines.push(...projectsWithPipelines)
|
|
20
|
+
}))
|
|
21
|
+
return allProjectsWithPipelines
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function projectWithPipelines(project, config) {
|
|
25
|
+
const pipelines = filterOutEmpty(await fetchLatestPipelines(project.id, config))
|
|
26
|
+
.filter(excludePipelineStatusFilter(config))
|
|
27
|
+
const status = defaultBranchStatus(project, pipelines)
|
|
28
|
+
return {
|
|
29
|
+
...project,
|
|
30
|
+
pipelines,
|
|
31
|
+
status
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function defaultBranchStatus(project, pipelines) {
|
|
36
|
+
return _(pipelines)
|
|
37
|
+
.filter({ref: project.default_branch})
|
|
38
|
+
.map('status')
|
|
39
|
+
.head()
|
|
159
40
|
}
|
|
160
41
|
|
|
161
42
|
function filterOutEmpty(pipelines) {
|
|
162
|
-
return pipelines.filter(
|
|
163
|
-
return pipeline.stages;
|
|
164
|
-
});
|
|
43
|
+
return pipelines.filter(pipeline => pipeline.stages)
|
|
165
44
|
}
|
|
166
45
|
|
|
167
46
|
function excludePipelineStatusFilter(config) {
|
|
168
|
-
return
|
|
47
|
+
return pipeline => {
|
|
169
48
|
if (config.projects && config.projects.excludePipelineStatus) {
|
|
170
|
-
return !config.projects.excludePipelineStatus.includes(pipeline.status)
|
|
49
|
+
return !config.projects.excludePipelineStatus.includes(pipeline.status)
|
|
171
50
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/gitlab/pipelines.js
CHANGED
|
@@ -1,245 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import {gitlabRequest} from './client'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export async function fetchLatestPipelines(projectId, gitlab) {
|
|
5
|
+
const pipelines = await fetchLatestAndMasterPipeline(projectId, gitlab)
|
|
6
|
+
const jobsForPipelines = await fetchJobsForPipelines(projectId, pipelines, gitlab)
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
-
|
|
16
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
-
|
|
18
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
19
|
-
|
|
20
|
-
var _client = require("./client");
|
|
21
|
-
|
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
-
|
|
26
|
-
function fetchLatestPipelines(_x, _x2) {
|
|
27
|
-
return _fetchLatestPipelines.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _fetchLatestPipelines() {
|
|
31
|
-
_fetchLatestPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(projectId, gitlab) {
|
|
32
|
-
var pipelines, jobsForPipelines;
|
|
33
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
34
|
-
while (1) {
|
|
35
|
-
switch (_context.prev = _context.next) {
|
|
36
|
-
case 0:
|
|
37
|
-
_context.next = 2;
|
|
38
|
-
return fetchLatestAndMasterPipeline(projectId, gitlab);
|
|
39
|
-
|
|
40
|
-
case 2:
|
|
41
|
-
pipelines = _context.sent;
|
|
42
|
-
_context.next = 5;
|
|
43
|
-
return fetchJobsForPipelines(projectId, pipelines, gitlab);
|
|
44
|
-
|
|
45
|
-
case 5:
|
|
46
|
-
jobsForPipelines = _context.sent;
|
|
47
|
-
return _context.abrupt("return", pipelines.map(function (_ref3) {
|
|
48
|
-
var id = _ref3.id,
|
|
49
|
-
ref = _ref3.ref,
|
|
50
|
-
status = _ref3.status;
|
|
51
|
-
var jobs = matchJobs(id, jobsForPipelines);
|
|
52
|
-
return _objectSpread({
|
|
53
|
-
id,
|
|
54
|
-
ref,
|
|
55
|
-
status
|
|
56
|
-
}, jobs);
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
case 7:
|
|
60
|
-
case "end":
|
|
61
|
-
return _context.stop();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, _callee);
|
|
65
|
-
}));
|
|
66
|
-
return _fetchLatestPipelines.apply(this, arguments);
|
|
8
|
+
return pipelines.map(({id, ref, status}) => {
|
|
9
|
+
const jobs = matchJobs(id, jobsForPipelines)
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
ref,
|
|
13
|
+
status,
|
|
14
|
+
...jobs
|
|
15
|
+
}
|
|
16
|
+
})
|
|
67
17
|
}
|
|
68
18
|
|
|
69
|
-
function fetchLatestAndMasterPipeline(
|
|
70
|
-
|
|
19
|
+
async function fetchLatestAndMasterPipeline(projectId, config) {
|
|
20
|
+
const [latestPipeline] = await fetchNonSkippedPipelines(projectId, config, {per_page: 100})
|
|
21
|
+
if (!latestPipeline) {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
if (latestPipeline.ref === 'master') {
|
|
25
|
+
return [latestPipeline]
|
|
26
|
+
}
|
|
27
|
+
const [latestMasterPipeline] = await fetchNonSkippedPipelines(projectId, config, {per_page: 50, ref: 'master'})
|
|
28
|
+
return [latestPipeline].concat(latestMasterPipeline || [])
|
|
71
29
|
}
|
|
72
30
|
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
78
|
-
while (1) {
|
|
79
|
-
switch (_context2.prev = _context2.next) {
|
|
80
|
-
case 0:
|
|
81
|
-
_context2.next = 2;
|
|
82
|
-
return fetchNonSkippedPipelines(projectId, config, {
|
|
83
|
-
per_page: 100
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
case 2:
|
|
87
|
-
_yield$fetchNonSkippe = _context2.sent;
|
|
88
|
-
_yield$fetchNonSkippe2 = (0, _slicedToArray2.default)(_yield$fetchNonSkippe, 1);
|
|
89
|
-
latestPipeline = _yield$fetchNonSkippe2[0];
|
|
90
|
-
|
|
91
|
-
if (latestPipeline) {
|
|
92
|
-
_context2.next = 7;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return _context2.abrupt("return", []);
|
|
97
|
-
|
|
98
|
-
case 7:
|
|
99
|
-
if (!(latestPipeline.ref === 'master')) {
|
|
100
|
-
_context2.next = 9;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return _context2.abrupt("return", [latestPipeline]);
|
|
105
|
-
|
|
106
|
-
case 9:
|
|
107
|
-
_context2.next = 11;
|
|
108
|
-
return fetchNonSkippedPipelines(projectId, config, {
|
|
109
|
-
per_page: 50,
|
|
110
|
-
ref: 'master'
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
case 11:
|
|
114
|
-
_yield$fetchNonSkippe3 = _context2.sent;
|
|
115
|
-
_yield$fetchNonSkippe4 = (0, _slicedToArray2.default)(_yield$fetchNonSkippe3, 1);
|
|
116
|
-
latestMasterPipeline = _yield$fetchNonSkippe4[0];
|
|
117
|
-
return _context2.abrupt("return", [latestPipeline].concat(latestMasterPipeline || []));
|
|
118
|
-
|
|
119
|
-
case 15:
|
|
120
|
-
case "end":
|
|
121
|
-
return _context2.stop();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}, _callee2);
|
|
125
|
-
}));
|
|
126
|
-
return _fetchLatestAndMasterPipeline.apply(this, arguments);
|
|
31
|
+
async function fetchNonSkippedPipelines(projectId, config, options) {
|
|
32
|
+
const {data: pipelines} = await gitlabRequest(`/projects/${projectId}/pipelines`, options, config)
|
|
33
|
+
return pipelines.filter(pipeline => pipeline.status !== 'skipped')
|
|
127
34
|
}
|
|
128
35
|
|
|
129
|
-
|
|
130
|
-
return _fetchNonSkippedPipelines.apply(this, arguments);
|
|
131
|
-
} // GitLab API endpoint `/projects/${projectId}/pipelines/${pipelineId}/jobs` is broken and not returning all jobs
|
|
36
|
+
// GitLab API endpoint `/projects/${projectId}/pipelines/${pipelineId}/jobs` is broken and not returning all jobs
|
|
132
37
|
// Need to fetch all jobs for the project (from newer to older) and match later
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return pipeline.status !== 'skipped';
|
|
151
|
-
}));
|
|
152
|
-
|
|
153
|
-
case 5:
|
|
154
|
-
case "end":
|
|
155
|
-
return _context3.stop();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}, _callee3);
|
|
159
|
-
}));
|
|
160
|
-
return _fetchNonSkippedPipelines.apply(this, arguments);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function fetchJobsForPipelines(_x8, _x9, _x10) {
|
|
164
|
-
return _fetchJobsForPipelines.apply(this, arguments);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function _fetchJobsForPipelines() {
|
|
168
|
-
_fetchJobsForPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(projectId, pipelines, config) {
|
|
169
|
-
var includedPipelineIds, _pipelines$map$sort, _pipelines$map$sort2, oldestCreatedAt, jobs, SAFETY_MAX_PAGE, page, _yield$gitlabRequest2, jobsBatch;
|
|
170
|
-
|
|
171
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
172
|
-
while (1) {
|
|
173
|
-
switch (_context4.prev = _context4.next) {
|
|
174
|
-
case 0:
|
|
175
|
-
includedPipelineIds = pipelines.map(function (pipeline) {
|
|
176
|
-
return pipeline.id;
|
|
177
|
-
});
|
|
178
|
-
_pipelines$map$sort = pipelines.map(function (pipeline) {
|
|
179
|
-
return pipeline.created_at;
|
|
180
|
-
}).sort(), _pipelines$map$sort2 = (0, _slicedToArray2.default)(_pipelines$map$sort, 1), oldestCreatedAt = _pipelines$map$sort2[0];
|
|
181
|
-
jobs = [];
|
|
182
|
-
SAFETY_MAX_PAGE = 10;
|
|
183
|
-
page = 1;
|
|
184
|
-
|
|
185
|
-
case 5:
|
|
186
|
-
if (!(page <= SAFETY_MAX_PAGE)) {
|
|
187
|
-
_context4.next = 16;
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
_context4.next = 8;
|
|
192
|
-
return (0, _client.gitlabRequest)("/projects/".concat(projectId, "/jobs"), {
|
|
193
|
-
page,
|
|
194
|
-
per_page: 100
|
|
195
|
-
}, config);
|
|
196
|
-
|
|
197
|
-
case 8:
|
|
198
|
-
_yield$gitlabRequest2 = _context4.sent;
|
|
199
|
-
jobsBatch = _yield$gitlabRequest2.data;
|
|
200
|
-
jobs.push(jobsBatch.filter(function (job) {
|
|
201
|
-
return includedPipelineIds.includes(job.pipeline.id);
|
|
202
|
-
}).filter(function (job) {
|
|
203
|
-
return job.created_at >= oldestCreatedAt;
|
|
204
|
-
}));
|
|
205
|
-
|
|
206
|
-
if (!(jobsBatch.length === 0 || jobsBatch[jobsBatch.length - 1].created_at < oldestCreatedAt)) {
|
|
207
|
-
_context4.next = 13;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return _context4.abrupt("break", 16);
|
|
212
|
-
|
|
213
|
-
case 13:
|
|
214
|
-
page += 1;
|
|
215
|
-
_context4.next = 5;
|
|
216
|
-
break;
|
|
217
|
-
|
|
218
|
-
case 16:
|
|
219
|
-
return _context4.abrupt("return", jobs.flat());
|
|
220
|
-
|
|
221
|
-
case 17:
|
|
222
|
-
case "end":
|
|
223
|
-
return _context4.stop();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}, _callee4);
|
|
227
|
-
}));
|
|
228
|
-
return _fetchJobsForPipelines.apply(this, arguments);
|
|
38
|
+
async function fetchJobsForPipelines(projectId, pipelines, config) {
|
|
39
|
+
const includedPipelineIds = pipelines.map(pipeline => pipeline.id)
|
|
40
|
+
const [oldestCreatedAt] = pipelines.map(pipeline => pipeline.created_at).sort()
|
|
41
|
+
|
|
42
|
+
const jobs = []
|
|
43
|
+
const SAFETY_MAX_PAGE = 10
|
|
44
|
+
for (let page = 1; page <= SAFETY_MAX_PAGE; page += 1) {
|
|
45
|
+
// eslint-disable-next-line no-await-in-loop
|
|
46
|
+
const {data: jobsBatch} = await gitlabRequest(`/projects/${projectId}/jobs`, {page, per_page: 100}, config)
|
|
47
|
+
jobs.push(jobsBatch
|
|
48
|
+
.filter(job => includedPipelineIds.includes(job.pipeline.id))
|
|
49
|
+
.filter(job => job.created_at >= oldestCreatedAt))
|
|
50
|
+
if (jobsBatch.length === 0 || jobsBatch[jobsBatch.length - 1].created_at < oldestCreatedAt) {
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return jobs.flat()
|
|
229
55
|
}
|
|
230
56
|
|
|
231
57
|
function matchJobs(pipelineId, gitlabJobsForMultiplePipelines) {
|
|
232
|
-
|
|
233
|
-
return job.pipeline.id === pipelineId;
|
|
234
|
-
});
|
|
235
|
-
|
|
58
|
+
const gitlabJobs = gitlabJobsForMultiplePipelines.filter(job => job.pipeline.id === pipelineId)
|
|
236
59
|
if (gitlabJobs.length === 0) {
|
|
237
|
-
return {}
|
|
60
|
+
return {}
|
|
238
61
|
}
|
|
239
62
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
63
|
+
const commit = findCommit(gitlabJobs)
|
|
64
|
+
const stages = _(gitlabJobs)
|
|
65
|
+
.map(job => ({
|
|
243
66
|
id: job.id,
|
|
244
67
|
status: job.status,
|
|
245
68
|
stage: job.stage,
|
|
@@ -247,60 +70,47 @@ function matchJobs(pipelineId, gitlabJobsForMultiplePipelines) {
|
|
|
247
70
|
startedAt: job.started_at,
|
|
248
71
|
finishedAt: job.finished_at,
|
|
249
72
|
url: job.web_url
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
73
|
+
}))
|
|
74
|
+
.orderBy('id')
|
|
75
|
+
.groupBy('stage')
|
|
76
|
+
.mapValues(mergeRetriedJobs)
|
|
77
|
+
.mapValues(cleanup)
|
|
78
|
+
.toPairs()
|
|
79
|
+
.map(([name, jobs]) => ({name, jobs: _.sortBy(jobs, 'name')}))
|
|
80
|
+
.value()
|
|
255
81
|
|
|
256
|
-
return {
|
|
257
|
-
name,
|
|
258
|
-
jobs: _lodash.default.sortBy(jobs, 'name')
|
|
259
|
-
};
|
|
260
|
-
}).value();
|
|
261
82
|
return {
|
|
262
83
|
commit,
|
|
263
84
|
stages
|
|
264
|
-
}
|
|
85
|
+
}
|
|
265
86
|
}
|
|
266
87
|
|
|
267
88
|
function findCommit(jobs) {
|
|
268
|
-
|
|
269
|
-
return j.commit;
|
|
270
|
-
}),
|
|
271
|
-
_jobs$filter2 = (0, _slicedToArray2.default)(_jobs$filter, 1),
|
|
272
|
-
job = _jobs$filter2[0];
|
|
273
|
-
|
|
89
|
+
const [job] = jobs.filter(j => j.commit)
|
|
274
90
|
if (!job) {
|
|
275
|
-
return null
|
|
91
|
+
return null
|
|
276
92
|
}
|
|
277
|
-
|
|
278
93
|
return {
|
|
279
94
|
title: job.commit.title,
|
|
280
95
|
author: job.commit.author_name
|
|
281
|
-
}
|
|
96
|
+
}
|
|
282
97
|
}
|
|
283
98
|
|
|
284
99
|
function mergeRetriedJobs(jobs) {
|
|
285
|
-
return jobs.reduce(
|
|
286
|
-
|
|
287
|
-
return mergedJob.name === job.name;
|
|
288
|
-
});
|
|
289
|
-
|
|
100
|
+
return jobs.reduce((mergedJobs, job) => {
|
|
101
|
+
const index = mergedJobs.findIndex(mergedJob => mergedJob.name === job.name)
|
|
290
102
|
if (index >= 0) {
|
|
291
|
-
mergedJobs[index] = job
|
|
103
|
+
mergedJobs[index] = job
|
|
292
104
|
} else {
|
|
293
|
-
mergedJobs.push(job)
|
|
105
|
+
mergedJobs.push(job)
|
|
294
106
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}, []);
|
|
107
|
+
return mergedJobs
|
|
108
|
+
}, [])
|
|
298
109
|
}
|
|
299
110
|
|
|
300
111
|
function cleanup(jobs) {
|
|
301
|
-
return (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
112
|
+
return _(jobs)
|
|
113
|
+
.map(job => _.omitBy(job, _.isNull))
|
|
114
|
+
.map(job => _.omit(job, 'stage'))
|
|
115
|
+
.value()
|
|
116
|
+
}
|