gitlab-radiator 3.3.11 → 3.4.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/.babelrc +4 -0
- package/.eslintrc +13 -0
- package/.github/workflows/test.yml +20 -0
- package/.nvmrc +1 -0
- package/README.md +1 -1
- package/build-npm +19 -0
- package/package.json +38 -38
- package/screenshot.png +0 -0
- package/src/app.js +80 -167
- package/src/auth.js +13 -25
- 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 +95 -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 +41 -157
- package/src/gitlab/pipelines.js +82 -249
- package/src/gitlab/projects.js +38 -118
- package/src/gitlab/runners.js +15 -76
- package/src/index.js +2 -4
- package/test/gitlab/projects.test.js +75 -0
- package/test/gitlab-integration.js +434 -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/projects.js
CHANGED
|
@@ -1,105 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _client = require("./client");
|
|
15
|
-
|
|
16
|
-
function fetchProjects(_x) {
|
|
17
|
-
return _fetchProjects.apply(this, arguments);
|
|
1
|
+
import {gitlabRequest} from './client'
|
|
2
|
+
|
|
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))
|
|
18
12
|
}
|
|
19
13
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return _context.abrupt("return", projects // Ignore projects for which CI/CD is not enabled
|
|
33
|
-
.filter(project => project.jobs_enabled).map(projectMapper).filter(includeRegexFilter(gitlab)).filter(excludeRegexFilter(gitlab)).filter(archivedFilter(gitlab)));
|
|
34
|
-
|
|
35
|
-
case 4:
|
|
36
|
-
case "end":
|
|
37
|
-
return _context.stop();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}, _callee);
|
|
41
|
-
}));
|
|
42
|
-
return _fetchProjects.apply(this, arguments);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function fetchOwnProjects(_x2) {
|
|
46
|
-
return _fetchOwnProjects.apply(this, arguments);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function _fetchOwnProjects() {
|
|
50
|
-
_fetchOwnProjects = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
51
|
-
var projects, SAFETY_MAX_PAGE, page, _yield$gitlabRequest, data, headers;
|
|
52
|
-
|
|
53
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
54
|
-
while (1) {
|
|
55
|
-
switch (_context2.prev = _context2.next) {
|
|
56
|
-
case 0:
|
|
57
|
-
projects = [];
|
|
58
|
-
SAFETY_MAX_PAGE = 10;
|
|
59
|
-
page = 1;
|
|
60
|
-
|
|
61
|
-
case 3:
|
|
62
|
-
if (!(page <= SAFETY_MAX_PAGE)) {
|
|
63
|
-
_context2.next = 15;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
_context2.next = 6;
|
|
68
|
-
return (0, _client.gitlabRequest)('/projects', {
|
|
69
|
-
page,
|
|
70
|
-
per_page: 100,
|
|
71
|
-
membership: true
|
|
72
|
-
}, gitlab);
|
|
73
|
-
|
|
74
|
-
case 6:
|
|
75
|
-
_yield$gitlabRequest = _context2.sent;
|
|
76
|
-
data = _yield$gitlabRequest.data;
|
|
77
|
-
headers = _yield$gitlabRequest.headers;
|
|
78
|
-
projects.push(data);
|
|
79
|
-
|
|
80
|
-
if (!(data.length === 0 || !headers['x-next-page'])) {
|
|
81
|
-
_context2.next = 12;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return _context2.abrupt("break", 15);
|
|
86
|
-
|
|
87
|
-
case 12:
|
|
88
|
-
page += 1;
|
|
89
|
-
_context2.next = 3;
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 15:
|
|
93
|
-
return _context2.abrupt("return", projects.flat());
|
|
94
|
-
|
|
95
|
-
case 16:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context2.stop();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, _callee2);
|
|
101
|
-
}));
|
|
102
|
-
return _fetchOwnProjects.apply(this, arguments);
|
|
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()
|
|
103
26
|
}
|
|
104
27
|
|
|
105
28
|
function projectMapper(project) {
|
|
@@ -112,42 +35,39 @@ function projectMapper(project) {
|
|
|
112
35
|
default_branch: project.default_branch || 'master',
|
|
113
36
|
url: project.web_url,
|
|
114
37
|
tags: (project.tag_list || []).map(t => t.toLowerCase())
|
|
115
|
-
}
|
|
38
|
+
}
|
|
116
39
|
}
|
|
117
40
|
|
|
118
41
|
function getGroupName(project) {
|
|
119
|
-
|
|
120
|
-
return pathWithNameSpace.split('/')[0]
|
|
42
|
+
const pathWithNameSpace = project.path_with_namespace
|
|
43
|
+
return pathWithNameSpace.split('/')[0]
|
|
121
44
|
}
|
|
122
45
|
|
|
123
46
|
function includeRegexFilter(config) {
|
|
124
47
|
return project => {
|
|
125
48
|
if (config.projects && config.projects.include) {
|
|
126
|
-
|
|
127
|
-
return includeRegex.test(project.name)
|
|
49
|
+
const includeRegex = new RegExp(config.projects.include, "i")
|
|
50
|
+
return includeRegex.test(project.name)
|
|
128
51
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
132
54
|
}
|
|
133
55
|
|
|
134
56
|
function excludeRegexFilter(config) {
|
|
135
57
|
return project => {
|
|
136
58
|
if (config.projects && config.projects.exclude) {
|
|
137
|
-
|
|
138
|
-
return !excludeRegex.test(project.name)
|
|
59
|
+
const excludeRegex = new RegExp(config.projects.exclude, "i")
|
|
60
|
+
return !excludeRegex.test(project.name)
|
|
139
61
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
143
64
|
}
|
|
144
65
|
|
|
145
66
|
function archivedFilter(config) {
|
|
146
67
|
return project => {
|
|
147
68
|
if (config.ignoreArchived) {
|
|
148
|
-
return !project.archived
|
|
69
|
+
return !project.archived
|
|
149
70
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/gitlab/runners.js
CHANGED
|
@@ -1,79 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _client = require("./client");
|
|
15
|
-
|
|
16
|
-
function fetchOfflineRunners(_x) {
|
|
17
|
-
return _fetchOfflineRunners.apply(this, arguments);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function _fetchOfflineRunners() {
|
|
21
|
-
_fetchOfflineRunners = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(gitlab) {
|
|
22
|
-
var runners, offline;
|
|
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 fetchRunners(gitlab);
|
|
29
|
-
|
|
30
|
-
case 2:
|
|
31
|
-
runners = _context.sent;
|
|
32
|
-
offline = runners.filter(r => r.status === 'offline');
|
|
33
|
-
return _context.abrupt("return", {
|
|
34
|
-
offline,
|
|
35
|
-
totalCount: runners.length
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
case 5:
|
|
39
|
-
case "end":
|
|
40
|
-
return _context.stop();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}, _callee);
|
|
44
|
-
}));
|
|
45
|
-
return _fetchOfflineRunners.apply(this, arguments);
|
|
1
|
+
import {gitlabRequest} from './client'
|
|
2
|
+
|
|
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
|
+
}
|
|
46
10
|
}
|
|
47
11
|
|
|
48
|
-
function fetchRunners(
|
|
49
|
-
|
|
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
|
+
}))
|
|
50
18
|
}
|
|
51
|
-
|
|
52
|
-
function _fetchRunners() {
|
|
53
|
-
_fetchRunners = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
54
|
-
var _yield$gitlabRequest, runners;
|
|
55
|
-
|
|
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, _client.gitlabRequest)('/runners', {}, gitlab);
|
|
62
|
-
|
|
63
|
-
case 2:
|
|
64
|
-
_yield$gitlabRequest = _context2.sent;
|
|
65
|
-
runners = _yield$gitlabRequest.data;
|
|
66
|
-
return _context2.abrupt("return", runners.map(r => ({
|
|
67
|
-
name: r.description || r.id,
|
|
68
|
-
status: r.status
|
|
69
|
-
})));
|
|
70
|
-
|
|
71
|
-
case 5:
|
|
72
|
-
case "end":
|
|
73
|
-
return _context2.stop();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, _callee2);
|
|
77
|
-
}));
|
|
78
|
-
return _fetchRunners.apply(this, arguments);
|
|
79
|
-
}
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as clientMock from './../../src/gitlab/client'
|
|
2
|
+
import {expect} from 'chai'
|
|
3
|
+
import {fetchProjects} from './../../src/gitlab/projects'
|
|
4
|
+
import sinon from 'sinon'
|
|
5
|
+
|
|
6
|
+
describe("projects", () => {
|
|
7
|
+
const response = {
|
|
8
|
+
data: [
|
|
9
|
+
{
|
|
10
|
+
path_with_namespace: "group1/pro",
|
|
11
|
+
jobs_enabled: true
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
path_with_namespace: "group1/pro-other",
|
|
15
|
+
jobs_enabled: true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path_with_namespace: "group2/something",
|
|
19
|
+
jobs_enabled: true
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
path_with_namespace: "group3/no-ci-pipelines",
|
|
23
|
+
jobs_enabled: false
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
headers: {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
before(() => {
|
|
30
|
+
sinon.stub(clientMock, 'gitlabRequest').callsFake(() => {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
resolve(response)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
after(() => {
|
|
38
|
+
sinon.resetBehavior()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should return only included projects', async () => {
|
|
42
|
+
const gitlab = {
|
|
43
|
+
projects: {
|
|
44
|
+
include: '.*/pro.*'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const projects = await fetchProjects(gitlab)
|
|
48
|
+
expect(projects.length).to.equal(2)
|
|
49
|
+
expect(projects[0].name).to.equal('group1/pro')
|
|
50
|
+
expect(projects[1].name).to.equal('group1/pro-other')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should not return excluded projects', async () => {
|
|
54
|
+
const gitlab = {
|
|
55
|
+
projects: {
|
|
56
|
+
exclude: '.*/pro.*'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const projects = await fetchProjects(gitlab)
|
|
60
|
+
expect(projects.length).to.equal(1)
|
|
61
|
+
expect(projects[0].name).to.equal('group2/something')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('should not return excluded and return only included', async () => {
|
|
65
|
+
const gitlab = {
|
|
66
|
+
projects: {
|
|
67
|
+
include: '.*/pro.*',
|
|
68
|
+
exclude: '.*/pro-other.*'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const projects = await fetchProjects(gitlab)
|
|
72
|
+
expect(projects.length).to.equal(1)
|
|
73
|
+
expect(projects[0].name).to.equal('group1/pro')
|
|
74
|
+
})
|
|
75
|
+
})
|