screwdriver-api 7.0.105 → 7.0.107

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.105",
3
+ "version": "7.0.107",
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",
@@ -122,7 +122,7 @@
122
122
  "screwdriver-scm-bitbucket": "^5.0.1",
123
123
  "screwdriver-scm-github": "^12.6.0",
124
124
  "screwdriver-scm-gitlab": "^3.1.0",
125
- "screwdriver-scm-router": "^7.0.0",
125
+ "screwdriver-scm-router": "^7.1.0",
126
126
  "screwdriver-template-validator": "^7.0.0",
127
127
  "screwdriver-workflow-parser": "^4.1.1",
128
128
  "sqlite3": "^5.1.4",
@@ -111,7 +111,8 @@ function addOAuthRoutes(config) {
111
111
  if (scmConfig && scmConfig.gheCloud) {
112
112
  const isEnterpriseUser = await userFactory.scm.isEnterpriseUser({
113
113
  token: accessToken,
114
- login: username
114
+ login: username,
115
+ scmContext
115
116
  });
116
117
 
117
118
  if (!isEnterpriseUser) {
@@ -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,6 +106,12 @@ 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
 
@@ -380,4 +386,4 @@ Example payload:
380
386
  {
381
387
  "trusted": true
382
388
  }
383
- ```
389
+ ```
@@ -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
+ });