screwdriver-api 5.0.1 → 5.0.2
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 +2 -2
- package/plugins/pipelines/README.md +4 -0
- package/plugins/pipelines/list.js +36 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screwdriver-api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "API server for the Screwdriver.cd service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"screwdriver-executor-k8s-vm": "^4.3.2",
|
|
114
114
|
"screwdriver-executor-queue": "^3.1.2",
|
|
115
115
|
"screwdriver-executor-router": "^2.3.0",
|
|
116
|
-
"screwdriver-logger": "^1.
|
|
116
|
+
"screwdriver-logger": "^1.2.0",
|
|
117
117
|
"screwdriver-models": "^28.20.0",
|
|
118
118
|
"screwdriver-notifications-email": "^2.3.1",
|
|
119
119
|
"screwdriver-notifications-slack": "^3.3.0",
|
|
@@ -33,6 +33,10 @@ server.register({
|
|
|
33
33
|
|
|
34
34
|
`GET /pipelines?page={pageNumber}&count={countNumber}&configPipelineId={configPipelineId}&search={search}`
|
|
35
35
|
|
|
36
|
+
Need to have array format for `ids` to only return pipelines with matching ids
|
|
37
|
+
`GET /pipelines?search={search}&ids[]=12345&ids[]=55555`
|
|
38
|
+
|
|
39
|
+
|
|
36
40
|
#### Get single pipeline
|
|
37
41
|
|
|
38
42
|
`GET /pipelines/{id}`
|
|
@@ -7,6 +7,11 @@ const listSchema = joi
|
|
|
7
7
|
.array()
|
|
8
8
|
.items(schema.models.pipeline.get)
|
|
9
9
|
.label('List of Pipelines');
|
|
10
|
+
const pipelineIdsSchema = joi
|
|
11
|
+
.alternatives()
|
|
12
|
+
.try(joi.array().items(idSchema), idSchema)
|
|
13
|
+
.required();
|
|
14
|
+
const IDS_KEY = 'ids[]';
|
|
10
15
|
|
|
11
16
|
module.exports = () => ({
|
|
12
17
|
method: 'GET',
|
|
@@ -21,30 +26,40 @@ module.exports = () => ({
|
|
|
21
26
|
},
|
|
22
27
|
|
|
23
28
|
handler: async (request, h) => {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
29
|
+
const { pipelineFactory } = request.server.app;
|
|
30
|
+
const { sort, configPipelineId, sortBy, search, page, count } = request.query;
|
|
31
|
+
const scmContexts = pipelineFactory.scm.getScmContexts();
|
|
26
32
|
let pipelineArray = [];
|
|
27
33
|
|
|
28
34
|
scmContexts.forEach(scmContext => {
|
|
29
35
|
const config = {
|
|
30
36
|
params: { scmContext },
|
|
31
|
-
sort
|
|
37
|
+
sort
|
|
32
38
|
};
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
// Only return specific pipelines
|
|
41
|
+
if (request.query[IDS_KEY]) {
|
|
42
|
+
const ids = request.query[IDS_KEY];
|
|
43
|
+
|
|
44
|
+
config.params.id = Array.isArray(ids)
|
|
45
|
+
? ids.map(pipelineId => parseInt(pipelineId, 10))
|
|
46
|
+
: [parseInt(ids, 10)];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (configPipelineId) {
|
|
50
|
+
config.params.configPipelineId = configPipelineId;
|
|
36
51
|
}
|
|
37
52
|
|
|
38
|
-
if (
|
|
39
|
-
config.sortBy =
|
|
53
|
+
if (sortBy) {
|
|
54
|
+
config.sortBy = sortBy;
|
|
40
55
|
}
|
|
41
56
|
|
|
42
|
-
if (
|
|
57
|
+
if (search) {
|
|
43
58
|
config.search = {
|
|
44
59
|
field: 'name',
|
|
45
60
|
// Do a fuzzy search for name: screwdriver-cd/ui
|
|
46
61
|
// See https://www.w3schools.com/sql/sql_like.asp for syntax
|
|
47
|
-
keyword: `%${
|
|
62
|
+
keyword: `%${search}%`
|
|
48
63
|
};
|
|
49
64
|
} else {
|
|
50
65
|
// default list all to 50 max count, according to schema.api.pagination
|
|
@@ -54,17 +69,17 @@ module.exports = () => ({
|
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
if (
|
|
72
|
+
if (page) {
|
|
58
73
|
config.paginate = config.paginate || {};
|
|
59
|
-
config.paginate.page =
|
|
74
|
+
config.paginate.page = page;
|
|
60
75
|
}
|
|
61
76
|
|
|
62
|
-
if (
|
|
77
|
+
if (count) {
|
|
63
78
|
config.paginate = config.paginate || {};
|
|
64
|
-
config.paginate.count =
|
|
79
|
+
config.paginate.count = count;
|
|
65
80
|
}
|
|
66
81
|
|
|
67
|
-
const pipelines =
|
|
82
|
+
const pipelines = pipelineFactory.list(config);
|
|
68
83
|
|
|
69
84
|
pipelineArray = pipelineArray.concat(pipelines);
|
|
70
85
|
});
|
|
@@ -76,7 +91,7 @@ module.exports = () => ({
|
|
|
76
91
|
let adminDetails;
|
|
77
92
|
|
|
78
93
|
if (scmContext) {
|
|
79
|
-
const scmDisplayName =
|
|
94
|
+
const scmDisplayName = pipelineFactory.scm.getDisplayName({ scmContext });
|
|
80
95
|
|
|
81
96
|
adminDetails = request.server.plugins.banners.screwdriverAdminDetails(username, scmDisplayName);
|
|
82
97
|
}
|
|
@@ -86,10 +101,11 @@ module.exports = () => ({
|
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
return allPipelines.filter(pipeline => {
|
|
89
|
-
const
|
|
90
|
-
const
|
|
104
|
+
const { settings, scmRepo, admins } = pipeline;
|
|
105
|
+
const setToPublic = settings && settings.public;
|
|
106
|
+
const privatePipeline = scmRepo && scmRepo.private;
|
|
91
107
|
|
|
92
|
-
return !privatePipeline || setToPublic ||
|
|
108
|
+
return !privatePipeline || setToPublic || admins[username];
|
|
93
109
|
});
|
|
94
110
|
})
|
|
95
111
|
.then(allPipelines => h.response(allPipelines.map(p => p.toJson())))
|
|
@@ -103,7 +119,8 @@ module.exports = () => ({
|
|
|
103
119
|
validate: {
|
|
104
120
|
query: schema.api.pagination.concat(
|
|
105
121
|
joi.object({
|
|
106
|
-
configPipelineId: idSchema
|
|
122
|
+
configPipelineId: idSchema,
|
|
123
|
+
'ids[]': pipelineIdsSchema.optional()
|
|
107
124
|
})
|
|
108
125
|
)
|
|
109
126
|
}
|