screwdriver-api 7.0.106 → 7.0.108

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "7.0.106",
3
+ "version": "7.0.108",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -105,7 +105,7 @@
105
105
  "screwdriver-config-parser": "^9.0.0",
106
106
  "screwdriver-coverage-bookend": "^2.0.0",
107
107
  "screwdriver-coverage-sonar": "^4.1.1",
108
- "screwdriver-data-schema": "^23.0.0",
108
+ "screwdriver-data-schema": "^23.2.0",
109
109
  "screwdriver-datastore-sequelize": "^8.1.1",
110
110
  "screwdriver-executor-base": "^9.0.1",
111
111
  "screwdriver-executor-docker": "^6.0.0",
@@ -114,7 +114,7 @@
114
114
  "screwdriver-executor-queue": "^4.0.0",
115
115
  "screwdriver-executor-router": "^3.0.0",
116
116
  "screwdriver-logger": "^2.0.0",
117
- "screwdriver-models": "^29.18.0",
117
+ "screwdriver-models": "^29.18.4",
118
118
  "screwdriver-notifications-email": "^3.0.0",
119
119
  "screwdriver-notifications-slack": "^5.0.0",
120
120
  "screwdriver-request": "^2.0.1",
@@ -62,15 +62,16 @@ Example payload:
62
62
  }
63
63
  ```
64
64
 
65
- #### Creates a build
66
- `POST /builds`
65
+ #### Get build statuses
66
+ `GET /builds/statuses`
67
67
 
68
- Example payload:
69
- ```json
70
- {
71
- "jobId": "d398fb192747c9a0124e9e5b4e6e8e841cf8c71c"
72
- }
73
- ```
68
+ `GET /builds/statuses?jobIds=1&jobIds=2&numBuilds=3&offset=0`
69
+
70
+ Arguments:
71
+
72
+ * `jobIds` - Job IDs for builds to fetch
73
+ * `numBuilds` - Number of builds to load (default 1)
74
+ * `offset` - Number of build statuses to skip (default 0)
74
75
 
75
76
  #### Updates a build
76
77
  `PUT /builds/{id}`
@@ -28,7 +28,6 @@ module.exports = () => ({
28
28
  }
29
29
 
30
30
  const config = readOnly ? { readOnly: true } : {};
31
-
32
31
  const buildsModel = await event.getBuilds(config);
33
32
 
34
33
  let data;
@@ -106,10 +106,22 @@ Only PR events of specified PR number will be searched when `prNum` is set
106
106
 
107
107
  `GET /pipelines/{id}/events?page={pageNumber}&count={countNumber}&sort={sort}&prNum={prNumber}`
108
108
 
109
+ #### Get all pipeline builds
110
+ `page`, `count`, `sort`, `latest`, `sortBy`, `fetchSteps`, `readOnly`, and `groupEventId` are optional
111
+ When `latest=true` and `groupEventId` is set, only latest builds in a pipeline based on groupEventId will be returned. The `latest` parameter must be used in conjunction with the `groupEventId`.
112
+
113
+ `GET /pipelines/{id}/builds?page={pageNumber}&count={countNumber}&sort={sort}&latest=true&groupEventId={groupEventId}&sortBy={sortBy}&fetchSteps=false&readOnly=false`
114
+
109
115
  #### Get all jobs (including pull requests jobs)
110
116
  `archived` is optional and has a default value of `false`, which makes the endpoint not return archived jobs (e.g. closed pull requests)
111
117
 
112
- `GET /pipelines/{id}/jobs?archived={boolean}`
118
+ Arguments:
119
+
120
+ * `archived` - Optional and has a default value of `false`, which makes the endpoint not return archived jobs (e.g. closed pull requests)
121
+ * `type` - Optional and can be set to `pr` or `pipeline` to only return PR jobs or non-PR jobs
122
+ * `jobName` - Optional and can be set to only return only a single job
123
+
124
+ `GET /pipelines/{id}/jobs?archived={boolean}&type={type}&jobName={jobName}`
113
125
 
114
126
  #### Get Pipeline Admin
115
127
  `GET /pipelines/{id}/admin`
@@ -380,4 +392,4 @@ Example payload:
380
392
  {
381
393
  "trusted": true
382
394
  }
383
- ```
395
+ ```
@@ -16,6 +16,7 @@ const listStagesRoute = require('./listStages');
16
16
  const listTriggersRoute = require('./listTriggers');
17
17
  const listSecretsRoute = require('./listSecrets');
18
18
  const listEventsRoute = require('./listEvents');
19
+ const listBuildsRoute = require('./listBuilds');
19
20
  const startAllRoute = require('./startAll');
20
21
  const createToken = require('./tokens/create');
21
22
  const updateToken = require('./tokens/update');
@@ -249,6 +250,7 @@ const pipelinesPlugin = {
249
250
  listTriggersRoute(),
250
251
  listSecretsRoute(),
251
252
  listEventsRoute(),
253
+ listBuildsRoute(),
252
254
  startAllRoute(),
253
255
  updateToken(),
254
256
  refreshToken(),
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ const boom = require('@hapi/boom');
4
+ const joi = require('joi');
5
+ const schema = require('screwdriver-data-schema');
6
+ const groupEventIdSchema = schema.models.event.base.extract('groupEventId');
7
+ const pipelineIdSchema = schema.models.pipeline.base.extract('id');
8
+
9
+ module.exports = () => ({
10
+ method: 'GET',
11
+ path: '/pipelines/{id}/builds',
12
+ options: {
13
+ description: 'Get builds for this pipeline',
14
+ notes: 'Returns builds for the given pipeline',
15
+ tags: ['api', 'pipelines', 'builds'],
16
+ auth: {
17
+ strategies: ['token'],
18
+ scope: ['user', 'build', 'pipeline']
19
+ },
20
+
21
+ handler: async (request, h) => {
22
+ const factory = request.server.app.pipelineFactory;
23
+ const { sort, sortBy, page, count, fetchSteps, readOnly, groupEventId, latest } = request.query;
24
+
25
+ return factory
26
+ .get(request.params.id)
27
+ .then(pipeline => {
28
+ if (!pipeline) {
29
+ throw boom.notFound('Pipeline does not exist');
30
+ }
31
+
32
+ const config = readOnly
33
+ ? { sort, sortBy: 'createTime', readOnly: true }
34
+ : { sort, sortBy: 'createTime' };
35
+
36
+ if (sortBy) {
37
+ config.sortBy = sortBy;
38
+ }
39
+
40
+ if (page || count) {
41
+ config.paginate = { page, count };
42
+ }
43
+
44
+ if (groupEventId) {
45
+ config.params = {
46
+ ...config.params,
47
+ groupEventId
48
+ };
49
+
50
+ // Latest flag only works in conjunction with groupEventId
51
+ if (latest) {
52
+ config.params.latest = latest;
53
+ }
54
+ }
55
+
56
+ return pipeline.getBuilds(config);
57
+ })
58
+ .then(async builds => {
59
+ let data;
60
+
61
+ if (fetchSteps) {
62
+ data = await Promise.all(builds.map(b => b.toJsonWithSteps()));
63
+ } else {
64
+ data = await Promise.all(builds.map(b => b.toJson()));
65
+ }
66
+
67
+ return h.response(data);
68
+ })
69
+ .catch(err => {
70
+ throw err;
71
+ });
72
+ },
73
+ response: {
74
+ schema: joi.array()
75
+ },
76
+ validate: {
77
+ params: joi.object({
78
+ id: pipelineIdSchema
79
+ }),
80
+ query: schema.api.pagination.concat(
81
+ joi.object({
82
+ readOnly: joi.boolean().truthy('true').falsy('false').default(true),
83
+ fetchSteps: joi.boolean().truthy('true').falsy('false').default(true),
84
+ groupEventId: groupEventIdSchema,
85
+ latest: joi.boolean().truthy('true').falsy('false').default(false),
86
+ search: joi.forbidden(), // we don't support search for Pipeline list builds
87
+ getCount: joi.forbidden() // we don't support getCount for Pipeline list builds
88
+ })
89
+ )
90
+ }
91
+ }
92
+ });
@@ -6,6 +6,7 @@ const schema = require('screwdriver-data-schema');
6
6
  const jobListSchema = joi.array().items(schema.models.job.get).label('List of jobs');
7
7
  const jobNameSchema = schema.models.job.base.extract('name');
8
8
  const pipelineIdSchema = schema.models.pipeline.base.extract('id');
9
+ const JOB_PR_PATTERN = `PR-%:%`;
9
10
 
10
11
  module.exports = () => ({
11
12
  method: 'GET',
@@ -21,7 +22,7 @@ module.exports = () => ({
21
22
 
22
23
  handler: async (request, h) => {
23
24
  const { pipelineFactory } = request.server.app;
24
- const { page, count, jobName } = request.query;
25
+ const { page, count, jobName, type } = request.query;
25
26
 
26
27
  return pipelineFactory
27
28
  .get(request.params.id)
@@ -36,6 +37,20 @@ module.exports = () => ({
36
37
  }
37
38
  };
38
39
 
40
+ if (type) {
41
+ config.search = {
42
+ field: 'name',
43
+ // Do a search for PR-%:% in job name
44
+ // See https://www.w3schools.com/sql/sql_like.asp for syntax
45
+ keyword: JOB_PR_PATTERN
46
+ };
47
+
48
+ if (type === 'pipeline') {
49
+ // Do a search for job name without PR-%:% pattern
50
+ // See https://www.w3schools.com/sql/sql_not.asp for syntax
51
+ config.search.inverse = true;
52
+ }
53
+ }
39
54
  if (jobName) {
40
55
  config.params.name = jobName;
41
56
  }
@@ -59,6 +74,7 @@ module.exports = () => ({
59
74
  }),
60
75
  query: schema.api.pagination.concat(
61
76
  joi.object({
77
+ type: joi.string().valid('', 'pr', 'pipeline').label('Job type filter (pr or pipeline)').optional(),
62
78
  archived: joi.boolean().truthy('true').falsy('false').default(false),
63
79
  jobName: jobNameSchema,
64
80
  search: joi.forbidden(), // we don't support search for Pipeline list jobs