gitlab-radiator 3.5.4 → 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 +30 -39
- package/public/client.js +1 -1
- package/src/app.js +74 -118
- package/src/auth.js +11 -19
- package/src/config.js +29 -33
- 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/gitlab/pipelines.js
CHANGED
|
@@ -1,298 +1,119 @@
|
|
|
1
|
-
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import {gitlabRequest} from './client.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function fetchLatestPipelines(_x, _x2) {
|
|
20
|
-
return _fetchLatestPipelines.apply(this, arguments);
|
|
21
|
-
} // eslint-disable-next-line max-statements
|
|
22
|
-
function _fetchLatestPipelines() {
|
|
23
|
-
_fetchLatestPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(projectId, gitlab) {
|
|
24
|
-
var pipelines;
|
|
25
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
26
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
27
|
-
case 0:
|
|
28
|
-
_context2.next = 2;
|
|
29
|
-
return fetchLatestAndMasterPipeline(projectId, gitlab);
|
|
30
|
-
case 2:
|
|
31
|
-
pipelines = _context2.sent;
|
|
32
|
-
return _context2.abrupt("return", Promise.all(pipelines.map( /*#__PURE__*/function () {
|
|
33
|
-
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
|
|
34
|
-
var id, ref, status, _yield$fetchJobs, commit, stages, downstreamStages;
|
|
35
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
36
|
-
while (1) switch (_context.prev = _context.next) {
|
|
37
|
-
case 0:
|
|
38
|
-
id = _ref.id, ref = _ref.ref, status = _ref.status;
|
|
39
|
-
_context.next = 3;
|
|
40
|
-
return fetchJobs(projectId, id, gitlab);
|
|
41
|
-
case 3:
|
|
42
|
-
_yield$fetchJobs = _context.sent;
|
|
43
|
-
commit = _yield$fetchJobs.commit;
|
|
44
|
-
stages = _yield$fetchJobs.stages;
|
|
45
|
-
_context.next = 8;
|
|
46
|
-
return fetchDownstreamJobs(projectId, id, gitlab);
|
|
47
|
-
case 8:
|
|
48
|
-
downstreamStages = _context.sent;
|
|
49
|
-
return _context.abrupt("return", {
|
|
50
|
-
id,
|
|
51
|
-
ref,
|
|
52
|
-
status,
|
|
53
|
-
commit,
|
|
54
|
-
stages: stages.concat(downstreamStages)
|
|
55
|
-
});
|
|
56
|
-
case 10:
|
|
57
|
-
case "end":
|
|
58
|
-
return _context.stop();
|
|
59
|
-
}
|
|
60
|
-
}, _callee);
|
|
61
|
-
}));
|
|
62
|
-
return function (_x14) {
|
|
63
|
-
return _ref2.apply(this, arguments);
|
|
64
|
-
};
|
|
65
|
-
}())));
|
|
66
|
-
case 4:
|
|
67
|
-
case "end":
|
|
68
|
-
return _context2.stop();
|
|
69
|
-
}
|
|
70
|
-
}, _callee2);
|
|
71
|
-
}));
|
|
72
|
-
return _fetchLatestPipelines.apply(this, arguments);
|
|
73
|
-
}
|
|
74
|
-
function fetchLatestAndMasterPipeline(_x3, _x4) {
|
|
75
|
-
return _fetchLatestAndMasterPipeline.apply(this, arguments);
|
|
76
|
-
}
|
|
77
|
-
function _fetchLatestAndMasterPipeline() {
|
|
78
|
-
_fetchLatestAndMasterPipeline = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(projectId, config) {
|
|
79
|
-
var pipelines, latestPipeline, latestMasterPipeline, masterPipelines;
|
|
80
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
81
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
82
|
-
case 0:
|
|
83
|
-
_context3.next = 2;
|
|
84
|
-
return fetchPipelines(projectId, config, {
|
|
85
|
-
per_page: 100
|
|
86
|
-
});
|
|
87
|
-
case 2:
|
|
88
|
-
pipelines = _context3.sent;
|
|
89
|
-
if (!(pipelines.length === 0)) {
|
|
90
|
-
_context3.next = 5;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
return _context3.abrupt("return", []);
|
|
94
|
-
case 5:
|
|
95
|
-
latestPipeline = _lodash.default.take(pipelines, 1);
|
|
96
|
-
if (!(latestPipeline[0].ref === 'master')) {
|
|
97
|
-
_context3.next = 8;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
return _context3.abrupt("return", latestPipeline);
|
|
101
|
-
case 8:
|
|
102
|
-
latestMasterPipeline = (0, _lodash.default)(pipelines).filter({
|
|
103
|
-
ref: 'master'
|
|
104
|
-
}).take(1).value();
|
|
105
|
-
if (!(latestMasterPipeline.length > 0)) {
|
|
106
|
-
_context3.next = 11;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
return _context3.abrupt("return", latestPipeline.concat(latestMasterPipeline));
|
|
110
|
-
case 11:
|
|
111
|
-
_context3.next = 13;
|
|
112
|
-
return fetchPipelines(projectId, config, {
|
|
113
|
-
per_page: 50,
|
|
114
|
-
ref: 'master'
|
|
115
|
-
});
|
|
116
|
-
case 13:
|
|
117
|
-
masterPipelines = _context3.sent;
|
|
118
|
-
return _context3.abrupt("return", latestPipeline.concat(_lodash.default.take(masterPipelines, 1)));
|
|
119
|
-
case 15:
|
|
120
|
-
case "end":
|
|
121
|
-
return _context3.stop();
|
|
122
|
-
}
|
|
123
|
-
}, _callee3);
|
|
124
|
-
}));
|
|
125
|
-
return _fetchLatestAndMasterPipeline.apply(this, arguments);
|
|
126
|
-
}
|
|
127
|
-
function fetchPipelines(_x5, _x6, _x7) {
|
|
128
|
-
return _fetchPipelines.apply(this, arguments);
|
|
129
|
-
}
|
|
130
|
-
function _fetchPipelines() {
|
|
131
|
-
_fetchPipelines = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(projectId, config, options) {
|
|
132
|
-
var _yield$gitlabRequest, pipelines;
|
|
133
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
134
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
135
|
-
case 0:
|
|
136
|
-
_context4.next = 2;
|
|
137
|
-
return (0, _client.gitlabRequest)("/projects/".concat(projectId, "/pipelines"), options, config);
|
|
138
|
-
case 2:
|
|
139
|
-
_yield$gitlabRequest = _context4.sent;
|
|
140
|
-
pipelines = _yield$gitlabRequest.data;
|
|
141
|
-
return _context4.abrupt("return", pipelines.filter(pipeline => pipeline.status !== 'skipped'));
|
|
142
|
-
case 5:
|
|
143
|
-
case "end":
|
|
144
|
-
return _context4.stop();
|
|
145
|
-
}
|
|
146
|
-
}, _callee4);
|
|
147
|
-
}));
|
|
148
|
-
return _fetchPipelines.apply(this, arguments);
|
|
4
|
+
export async function fetchLatestPipelines(projectId, gitlab) {
|
|
5
|
+
const pipelines = await fetchLatestAndMasterPipeline(projectId, gitlab)
|
|
6
|
+
|
|
7
|
+
const pipelinesWithStages = []
|
|
8
|
+
for (const {id, ref, status} of pipelines) {
|
|
9
|
+
const {commit, stages} = await fetchJobs(projectId, id, gitlab)
|
|
10
|
+
const downstreamStages = await fetchDownstreamJobs(projectId, id, gitlab)
|
|
11
|
+
pipelinesWithStages.push({
|
|
12
|
+
id,
|
|
13
|
+
ref,
|
|
14
|
+
status,
|
|
15
|
+
commit,
|
|
16
|
+
stages: stages.concat(downstreamStages)
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
return pipelinesWithStages
|
|
149
20
|
}
|
|
150
|
-
|
|
151
|
-
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line max-statements
|
|
23
|
+
async function fetchLatestAndMasterPipeline(projectId, config) {
|
|
24
|
+
const pipelines = await fetchPipelines(projectId, config, {per_page: 100})
|
|
25
|
+
if (pipelines.length === 0) {
|
|
26
|
+
return []
|
|
27
|
+
}
|
|
28
|
+
const latestPipeline = _.take(pipelines, 1)
|
|
29
|
+
if (latestPipeline[0].ref === 'master') {
|
|
30
|
+
return latestPipeline
|
|
31
|
+
}
|
|
32
|
+
const latestMasterPipeline = _(pipelines).filter({ref: 'master'}).take(1).value()
|
|
33
|
+
if (latestMasterPipeline.length > 0) {
|
|
34
|
+
return latestPipeline.concat(latestMasterPipeline)
|
|
35
|
+
}
|
|
36
|
+
const masterPipelines = await fetchPipelines(projectId, config, {per_page: 50, ref: 'master'})
|
|
37
|
+
return latestPipeline.concat(_.take(masterPipelines, 1))
|
|
152
38
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
158
|
-
case 0:
|
|
159
|
-
_context6.next = 2;
|
|
160
|
-
return (0, _client.gitlabRequest)("/projects/".concat(projectId, "/pipelines/").concat(pipelineId, "/bridges"), {
|
|
161
|
-
per_page: 100
|
|
162
|
-
}, config);
|
|
163
|
-
case 2:
|
|
164
|
-
_yield$gitlabRequest2 = _context6.sent;
|
|
165
|
-
gitlabBridgeJobs = _yield$gitlabRequest2.data;
|
|
166
|
-
childPipelines = gitlabBridgeJobs.filter(bridge => bridge.downstream_pipeline.status !== 'skipped');
|
|
167
|
-
downstreamStages = [];
|
|
168
|
-
_iterator = _createForOfIteratorHelper(childPipelines);
|
|
169
|
-
_context6.prev = 7;
|
|
170
|
-
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
171
|
-
var childPipeline, _yield$fetchJobs2, stages;
|
|
172
|
-
return _regenerator.default.wrap(function _loop$(_context5) {
|
|
173
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
174
|
-
case 0:
|
|
175
|
-
childPipeline = _step.value;
|
|
176
|
-
_context5.next = 3;
|
|
177
|
-
return fetchJobs(projectId, childPipeline.downstream_pipeline.id, config);
|
|
178
|
-
case 3:
|
|
179
|
-
_yield$fetchJobs2 = _context5.sent;
|
|
180
|
-
stages = _yield$fetchJobs2.stages;
|
|
181
|
-
downstreamStages.push(stages.map(stage => _objectSpread(_objectSpread({}, stage), {}, {
|
|
182
|
-
name: "".concat(childPipeline.stage, ":").concat(stage.name)
|
|
183
|
-
})));
|
|
184
|
-
case 6:
|
|
185
|
-
case "end":
|
|
186
|
-
return _context5.stop();
|
|
187
|
-
}
|
|
188
|
-
}, _loop);
|
|
189
|
-
});
|
|
190
|
-
_iterator.s();
|
|
191
|
-
case 10:
|
|
192
|
-
if ((_step = _iterator.n()).done) {
|
|
193
|
-
_context6.next = 14;
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
return _context6.delegateYield(_loop(), "t0", 12);
|
|
197
|
-
case 12:
|
|
198
|
-
_context6.next = 10;
|
|
199
|
-
break;
|
|
200
|
-
case 14:
|
|
201
|
-
_context6.next = 19;
|
|
202
|
-
break;
|
|
203
|
-
case 16:
|
|
204
|
-
_context6.prev = 16;
|
|
205
|
-
_context6.t1 = _context6["catch"](7);
|
|
206
|
-
_iterator.e(_context6.t1);
|
|
207
|
-
case 19:
|
|
208
|
-
_context6.prev = 19;
|
|
209
|
-
_iterator.f();
|
|
210
|
-
return _context6.finish(19);
|
|
211
|
-
case 22:
|
|
212
|
-
return _context6.abrupt("return", downstreamStages.flat());
|
|
213
|
-
case 23:
|
|
214
|
-
case "end":
|
|
215
|
-
return _context6.stop();
|
|
216
|
-
}
|
|
217
|
-
}, _callee5, null, [[7, 16, 19, 22]]);
|
|
218
|
-
}));
|
|
219
|
-
return _fetchDownstreamJobs.apply(this, arguments);
|
|
39
|
+
|
|
40
|
+
async function fetchPipelines(projectId, config, options) {
|
|
41
|
+
const {data: pipelines} = await gitlabRequest(`/projects/${projectId}/pipelines`, options, config)
|
|
42
|
+
return pipelines.filter(pipeline => pipeline.status !== 'skipped')
|
|
220
43
|
}
|
|
221
|
-
|
|
222
|
-
|
|
44
|
+
|
|
45
|
+
async function fetchDownstreamJobs(projectId, pipelineId, config) {
|
|
46
|
+
const {data: gitlabBridgeJobs} = await gitlabRequest(`/projects/${projectId}/pipelines/${pipelineId}/bridges`, {per_page: 100}, config)
|
|
47
|
+
const childPipelines = gitlabBridgeJobs.filter(bridge => bridge.downstream_pipeline.status !== 'skipped')
|
|
48
|
+
|
|
49
|
+
const downstreamStages = []
|
|
50
|
+
for(const childPipeline of childPipelines) {
|
|
51
|
+
const {stages} = await fetchJobs(projectId, childPipeline.downstream_pipeline.id, config)
|
|
52
|
+
downstreamStages.push(stages.map(stage => ({
|
|
53
|
+
...stage,
|
|
54
|
+
name: `${childPipeline.stage}:${stage.name}`
|
|
55
|
+
})))
|
|
56
|
+
}
|
|
57
|
+
return downstreamStages.flat()
|
|
223
58
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
name = _ref4[0],
|
|
255
|
-
jobs = _ref4[1];
|
|
256
|
-
return {
|
|
257
|
-
name,
|
|
258
|
-
jobs: _lodash.default.sortBy(jobs, 'name')
|
|
259
|
-
};
|
|
260
|
-
}).value();
|
|
261
|
-
return _context7.abrupt("return", {
|
|
262
|
-
commit,
|
|
263
|
-
stages
|
|
264
|
-
});
|
|
265
|
-
case 9:
|
|
266
|
-
case "end":
|
|
267
|
-
return _context7.stop();
|
|
268
|
-
}
|
|
269
|
-
}, _callee6);
|
|
270
|
-
}));
|
|
271
|
-
return _fetchJobs.apply(this, arguments);
|
|
59
|
+
|
|
60
|
+
async function fetchJobs(projectId, pipelineId, config) {
|
|
61
|
+
const {data: gitlabJobs} = await gitlabRequest(`/projects/${projectId}/pipelines/${pipelineId}/jobs?include_retried=true`, {per_page: 100}, config)
|
|
62
|
+
if (gitlabJobs.length === 0) {
|
|
63
|
+
return {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const commit = findCommit(gitlabJobs)
|
|
67
|
+
const stages = _(gitlabJobs)
|
|
68
|
+
.map(job => ({
|
|
69
|
+
id: job.id,
|
|
70
|
+
status: job.status,
|
|
71
|
+
stage: job.stage,
|
|
72
|
+
name: job.name,
|
|
73
|
+
startedAt: job.started_at,
|
|
74
|
+
finishedAt: job.finished_at,
|
|
75
|
+
url: job.web_url
|
|
76
|
+
}))
|
|
77
|
+
.orderBy('id')
|
|
78
|
+
.groupBy('stage')
|
|
79
|
+
.mapValues(mergeRetriedJobs)
|
|
80
|
+
.mapValues(cleanup)
|
|
81
|
+
.toPairs()
|
|
82
|
+
.map(([name, jobs]) => ({name, jobs: _.sortBy(jobs, 'name')}))
|
|
83
|
+
.value()
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
commit,
|
|
87
|
+
stages
|
|
88
|
+
}
|
|
272
89
|
}
|
|
90
|
+
|
|
273
91
|
function findCommit(jobs) {
|
|
274
|
-
|
|
275
|
-
_jobs$filter2 = (0, _slicedToArray2.default)(_jobs$filter, 1),
|
|
276
|
-
job = _jobs$filter2[0];
|
|
92
|
+
const [job] = jobs.filter(j => j.commit)
|
|
277
93
|
if (!job) {
|
|
278
|
-
return null
|
|
94
|
+
return null
|
|
279
95
|
}
|
|
280
96
|
return {
|
|
281
97
|
title: job.commit.title,
|
|
282
98
|
author: job.commit.author_name
|
|
283
|
-
}
|
|
99
|
+
}
|
|
284
100
|
}
|
|
101
|
+
|
|
285
102
|
function mergeRetriedJobs(jobs) {
|
|
286
103
|
return jobs.reduce((mergedJobs, job) => {
|
|
287
|
-
|
|
104
|
+
const index = mergedJobs.findIndex(mergedJob => mergedJob.name === job.name)
|
|
288
105
|
if (index >= 0) {
|
|
289
|
-
mergedJobs[index] = job
|
|
106
|
+
mergedJobs[index] = job
|
|
290
107
|
} else {
|
|
291
|
-
mergedJobs.push(job)
|
|
108
|
+
mergedJobs.push(job)
|
|
292
109
|
}
|
|
293
|
-
return mergedJobs
|
|
294
|
-
}, [])
|
|
110
|
+
return mergedJobs
|
|
111
|
+
}, [])
|
|
295
112
|
}
|
|
113
|
+
|
|
296
114
|
function cleanup(jobs) {
|
|
297
|
-
return (
|
|
298
|
-
|
|
115
|
+
return _(jobs)
|
|
116
|
+
.map(job => _.omitBy(job, _.isNull))
|
|
117
|
+
.map(job => _.omit(job, 'stage'))
|
|
118
|
+
.value()
|
|
119
|
+
}
|
package/src/gitlab/projects.js
CHANGED
|
@@ -1,84 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import {gitlabRequest} from './client.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return _fetchProjects.apply(this, arguments);
|
|
3
|
+
export async function fetchProjects(gitlab) {
|
|
4
|
+
const projects = await fetchOwnProjects(gitlab)
|
|
5
|
+
return projects
|
|
6
|
+
// Ignore projects for which CI/CD is not enabled
|
|
7
|
+
.filter(project => project.jobs_enabled)
|
|
8
|
+
.map(projectMapper)
|
|
9
|
+
.filter(includeRegexFilter(gitlab))
|
|
10
|
+
.filter(excludeRegexFilter(gitlab))
|
|
11
|
+
.filter(archivedFilter(gitlab))
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
case 4:
|
|
28
|
-
case "end":
|
|
29
|
-
return _context.stop();
|
|
30
|
-
}
|
|
31
|
-
}, _callee);
|
|
32
|
-
}));
|
|
33
|
-
return _fetchProjects.apply(this, arguments);
|
|
34
|
-
}
|
|
35
|
-
function fetchOwnProjects(_x2) {
|
|
36
|
-
return _fetchOwnProjects.apply(this, arguments);
|
|
37
|
-
}
|
|
38
|
-
function _fetchOwnProjects() {
|
|
39
|
-
_fetchOwnProjects = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
40
|
-
var projects, SAFETY_MAX_PAGE, page, _yield$gitlabRequest, data, headers;
|
|
41
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
42
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
43
|
-
case 0:
|
|
44
|
-
projects = [];
|
|
45
|
-
SAFETY_MAX_PAGE = 10;
|
|
46
|
-
page = 1;
|
|
47
|
-
case 3:
|
|
48
|
-
if (!(page <= SAFETY_MAX_PAGE)) {
|
|
49
|
-
_context2.next = 15;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
_context2.next = 6;
|
|
53
|
-
return (0, _client.gitlabRequest)('/projects', {
|
|
54
|
-
page,
|
|
55
|
-
per_page: 100,
|
|
56
|
-
membership: true
|
|
57
|
-
}, gitlab);
|
|
58
|
-
case 6:
|
|
59
|
-
_yield$gitlabRequest = _context2.sent;
|
|
60
|
-
data = _yield$gitlabRequest.data;
|
|
61
|
-
headers = _yield$gitlabRequest.headers;
|
|
62
|
-
projects.push(data);
|
|
63
|
-
if (!(data.length === 0 || !headers['x-next-page'])) {
|
|
64
|
-
_context2.next = 12;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
return _context2.abrupt("break", 15);
|
|
68
|
-
case 12:
|
|
69
|
-
page += 1;
|
|
70
|
-
_context2.next = 3;
|
|
71
|
-
break;
|
|
72
|
-
case 15:
|
|
73
|
-
return _context2.abrupt("return", projects.flat());
|
|
74
|
-
case 16:
|
|
75
|
-
case "end":
|
|
76
|
-
return _context2.stop();
|
|
77
|
-
}
|
|
78
|
-
}, _callee2);
|
|
79
|
-
}));
|
|
80
|
-
return _fetchOwnProjects.apply(this, arguments);
|
|
13
|
+
|
|
14
|
+
async function fetchOwnProjects(gitlab) {
|
|
15
|
+
const projects = []
|
|
16
|
+
const SAFETY_MAX_PAGE = 10
|
|
17
|
+
for (let page = 1; page <= SAFETY_MAX_PAGE; page += 1) {
|
|
18
|
+
// eslint-disable-next-line no-await-in-loop
|
|
19
|
+
const {data, headers} = await gitlabRequest('/projects', {page, per_page: 100, membership: true}, gitlab)
|
|
20
|
+
projects.push(data)
|
|
21
|
+
if (data.length === 0 || !headers['x-next-page']) {
|
|
22
|
+
break
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return projects.flat()
|
|
81
26
|
}
|
|
27
|
+
|
|
82
28
|
function projectMapper(project) {
|
|
83
29
|
return {
|
|
84
30
|
id: project.id,
|
|
@@ -89,35 +35,39 @@ function projectMapper(project) {
|
|
|
89
35
|
default_branch: project.default_branch || 'master',
|
|
90
36
|
url: project.web_url,
|
|
91
37
|
tags: (project.tag_list || []).map(t => t.toLowerCase())
|
|
92
|
-
}
|
|
38
|
+
}
|
|
93
39
|
}
|
|
40
|
+
|
|
94
41
|
function getGroupName(project) {
|
|
95
|
-
|
|
96
|
-
return pathWithNameSpace.split('/')[0]
|
|
42
|
+
const pathWithNameSpace = project.path_with_namespace
|
|
43
|
+
return pathWithNameSpace.split('/')[0]
|
|
97
44
|
}
|
|
45
|
+
|
|
98
46
|
function includeRegexFilter(config) {
|
|
99
47
|
return project => {
|
|
100
48
|
if (config.projects && config.projects.include) {
|
|
101
|
-
|
|
102
|
-
return includeRegex.test(project.name)
|
|
49
|
+
const includeRegex = new RegExp(config.projects.include, "i")
|
|
50
|
+
return includeRegex.test(project.name)
|
|
103
51
|
}
|
|
104
|
-
return true
|
|
105
|
-
}
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
106
54
|
}
|
|
55
|
+
|
|
107
56
|
function excludeRegexFilter(config) {
|
|
108
57
|
return project => {
|
|
109
58
|
if (config.projects && config.projects.exclude) {
|
|
110
|
-
|
|
111
|
-
return !excludeRegex.test(project.name)
|
|
59
|
+
const excludeRegex = new RegExp(config.projects.exclude, "i")
|
|
60
|
+
return !excludeRegex.test(project.name)
|
|
112
61
|
}
|
|
113
|
-
return true
|
|
114
|
-
}
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
115
64
|
}
|
|
65
|
+
|
|
116
66
|
function archivedFilter(config) {
|
|
117
67
|
return project => {
|
|
118
68
|
if (config.ignoreArchived) {
|
|
119
|
-
return !project.archived
|
|
69
|
+
return !project.archived
|
|
120
70
|
}
|
|
121
|
-
return true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/gitlab/runners.js
CHANGED
|
@@ -1,62 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import {gitlabRequest} from './client.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _client = require("./client");
|
|
11
|
-
function fetchOfflineRunners(_x) {
|
|
12
|
-
return _fetchOfflineRunners.apply(this, arguments);
|
|
3
|
+
export async function fetchOfflineRunners(gitlab) {
|
|
4
|
+
const runners = await fetchRunners(gitlab)
|
|
5
|
+
const offline = runners.filter(r => r.status === 'offline')
|
|
6
|
+
return {
|
|
7
|
+
offline,
|
|
8
|
+
totalCount: runners.length
|
|
9
|
+
}
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return fetchRunners(gitlab);
|
|
22
|
-
case 2:
|
|
23
|
-
runners = _context.sent;
|
|
24
|
-
offline = runners.filter(r => r.status === 'offline');
|
|
25
|
-
return _context.abrupt("return", {
|
|
26
|
-
offline,
|
|
27
|
-
totalCount: runners.length
|
|
28
|
-
});
|
|
29
|
-
case 5:
|
|
30
|
-
case "end":
|
|
31
|
-
return _context.stop();
|
|
32
|
-
}
|
|
33
|
-
}, _callee);
|
|
34
|
-
}));
|
|
35
|
-
return _fetchOfflineRunners.apply(this, arguments);
|
|
36
|
-
}
|
|
37
|
-
function fetchRunners(_x2) {
|
|
38
|
-
return _fetchRunners.apply(this, arguments);
|
|
11
|
+
|
|
12
|
+
async function fetchRunners(gitlab) {
|
|
13
|
+
const {data: runners} = await gitlabRequest('/runners', {}, gitlab)
|
|
14
|
+
return runners.map(r => ({
|
|
15
|
+
name: r.description || r.id,
|
|
16
|
+
status: r.status
|
|
17
|
+
}))
|
|
39
18
|
}
|
|
40
|
-
function _fetchRunners() {
|
|
41
|
-
_fetchRunners = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
42
|
-
var _yield$gitlabRequest, runners;
|
|
43
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
44
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
45
|
-
case 0:
|
|
46
|
-
_context2.next = 2;
|
|
47
|
-
return (0, _client.gitlabRequest)('/runners', {}, gitlab);
|
|
48
|
-
case 2:
|
|
49
|
-
_yield$gitlabRequest = _context2.sent;
|
|
50
|
-
runners = _yield$gitlabRequest.data;
|
|
51
|
-
return _context2.abrupt("return", runners.map(r => ({
|
|
52
|
-
name: r.description || r.id,
|
|
53
|
-
status: r.status
|
|
54
|
-
})));
|
|
55
|
-
case 5:
|
|
56
|
-
case "end":
|
|
57
|
-
return _context2.stop();
|
|
58
|
-
}
|
|
59
|
-
}, _callee2);
|
|
60
|
-
}));
|
|
61
|
-
return _fetchRunners.apply(this, arguments);
|
|
62
|
-
}
|