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/projects.js
CHANGED
|
@@ -1,107 +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(function (project) {
|
|
34
|
-
return project.jobs_enabled;
|
|
35
|
-
}).map(projectMapper).filter(includeRegexFilter(gitlab)).filter(excludeRegexFilter(gitlab)).filter(archivedFilter(gitlab)));
|
|
36
|
-
|
|
37
|
-
case 4:
|
|
38
|
-
case "end":
|
|
39
|
-
return _context.stop();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}, _callee);
|
|
43
|
-
}));
|
|
44
|
-
return _fetchProjects.apply(this, arguments);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function fetchOwnProjects(_x2) {
|
|
48
|
-
return _fetchOwnProjects.apply(this, arguments);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function _fetchOwnProjects() {
|
|
52
|
-
_fetchOwnProjects = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
53
|
-
var projects, SAFETY_MAX_PAGE, page, _yield$gitlabRequest, data, headers;
|
|
54
|
-
|
|
55
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
56
|
-
while (1) {
|
|
57
|
-
switch (_context2.prev = _context2.next) {
|
|
58
|
-
case 0:
|
|
59
|
-
projects = [];
|
|
60
|
-
SAFETY_MAX_PAGE = 10;
|
|
61
|
-
page = 1;
|
|
62
|
-
|
|
63
|
-
case 3:
|
|
64
|
-
if (!(page <= SAFETY_MAX_PAGE)) {
|
|
65
|
-
_context2.next = 15;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
_context2.next = 6;
|
|
70
|
-
return (0, _client.gitlabRequest)('/projects', {
|
|
71
|
-
page,
|
|
72
|
-
per_page: 100,
|
|
73
|
-
membership: true
|
|
74
|
-
}, gitlab);
|
|
75
|
-
|
|
76
|
-
case 6:
|
|
77
|
-
_yield$gitlabRequest = _context2.sent;
|
|
78
|
-
data = _yield$gitlabRequest.data;
|
|
79
|
-
headers = _yield$gitlabRequest.headers;
|
|
80
|
-
projects.push(data);
|
|
81
|
-
|
|
82
|
-
if (!(data.length === 0 || !headers['x-next-page'])) {
|
|
83
|
-
_context2.next = 12;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return _context2.abrupt("break", 15);
|
|
88
|
-
|
|
89
|
-
case 12:
|
|
90
|
-
page += 1;
|
|
91
|
-
_context2.next = 3;
|
|
92
|
-
break;
|
|
93
|
-
|
|
94
|
-
case 15:
|
|
95
|
-
return _context2.abrupt("return", projects.flat());
|
|
96
|
-
|
|
97
|
-
case 16:
|
|
98
|
-
case "end":
|
|
99
|
-
return _context2.stop();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, _callee2);
|
|
103
|
-
}));
|
|
104
|
-
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()
|
|
105
26
|
}
|
|
106
27
|
|
|
107
28
|
function projectMapper(project) {
|
|
@@ -111,46 +32,42 @@ function projectMapper(project) {
|
|
|
111
32
|
nameWithoutNamespace: project.path,
|
|
112
33
|
group: getGroupName(project),
|
|
113
34
|
archived: project.archived,
|
|
35
|
+
default_branch: project.default_branch || 'master',
|
|
114
36
|
url: project.web_url,
|
|
115
|
-
tags: (project.tag_list || []).map(
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
};
|
|
37
|
+
tags: (project.tag_list || []).map(t => t.toLowerCase())
|
|
38
|
+
}
|
|
119
39
|
}
|
|
120
40
|
|
|
121
41
|
function getGroupName(project) {
|
|
122
|
-
|
|
123
|
-
return pathWithNameSpace.split('/')[0]
|
|
42
|
+
const pathWithNameSpace = project.path_with_namespace
|
|
43
|
+
return pathWithNameSpace.split('/')[0]
|
|
124
44
|
}
|
|
125
45
|
|
|
126
46
|
function includeRegexFilter(config) {
|
|
127
|
-
return
|
|
47
|
+
return project => {
|
|
128
48
|
if (config.projects && config.projects.include) {
|
|
129
|
-
|
|
130
|
-
return includeRegex.test(project.name)
|
|
49
|
+
const includeRegex = new RegExp(config.projects.include, "i")
|
|
50
|
+
return includeRegex.test(project.name)
|
|
131
51
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
135
54
|
}
|
|
136
55
|
|
|
137
56
|
function excludeRegexFilter(config) {
|
|
138
|
-
return
|
|
57
|
+
return project => {
|
|
139
58
|
if (config.projects && config.projects.exclude) {
|
|
140
|
-
|
|
141
|
-
return !excludeRegex.test(project.name)
|
|
59
|
+
const excludeRegex = new RegExp(config.projects.exclude, "i")
|
|
60
|
+
return !excludeRegex.test(project.name)
|
|
142
61
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
146
64
|
}
|
|
147
65
|
|
|
148
66
|
function archivedFilter(config) {
|
|
149
|
-
return
|
|
67
|
+
return project => {
|
|
150
68
|
if (config.ignoreArchived) {
|
|
151
|
-
return !project.archived
|
|
69
|
+
return !project.archived
|
|
152
70
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/gitlab/runners.js
CHANGED
|
@@ -1,83 +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(function (r) {
|
|
33
|
-
return r.status === 'offline';
|
|
34
|
-
});
|
|
35
|
-
return _context.abrupt("return", {
|
|
36
|
-
offline,
|
|
37
|
-
totalCount: runners.length
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
case 5:
|
|
41
|
-
case "end":
|
|
42
|
-
return _context.stop();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}, _callee);
|
|
46
|
-
}));
|
|
47
|
-
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
|
+
}
|
|
48
10
|
}
|
|
49
11
|
|
|
50
|
-
function fetchRunners(
|
|
51
|
-
|
|
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
|
+
}))
|
|
52
18
|
}
|
|
53
|
-
|
|
54
|
-
function _fetchRunners() {
|
|
55
|
-
_fetchRunners = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(gitlab) {
|
|
56
|
-
var _yield$gitlabRequest, runners;
|
|
57
|
-
|
|
58
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
59
|
-
while (1) {
|
|
60
|
-
switch (_context2.prev = _context2.next) {
|
|
61
|
-
case 0:
|
|
62
|
-
_context2.next = 2;
|
|
63
|
-
return (0, _client.gitlabRequest)('/runners', {}, gitlab);
|
|
64
|
-
|
|
65
|
-
case 2:
|
|
66
|
-
_yield$gitlabRequest = _context2.sent;
|
|
67
|
-
runners = _yield$gitlabRequest.data;
|
|
68
|
-
return _context2.abrupt("return", runners.map(function (r) {
|
|
69
|
-
return {
|
|
70
|
-
name: r.description || r.id,
|
|
71
|
-
status: r.status
|
|
72
|
-
};
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
case 5:
|
|
76
|
-
case "end":
|
|
77
|
-
return _context2.stop();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, _callee2);
|
|
81
|
-
}));
|
|
82
|
-
return _fetchRunners.apply(this, arguments);
|
|
83
|
-
}
|
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
|
+
})
|