screwdriver-api 7.0.229 → 7.0.231

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.229",
3
+ "version": "7.0.231",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -294,6 +294,7 @@ async function createExternalEvent(config) {
294
294
  * @param {Boolean} config.start Whether to start the build or not
295
295
  * @param {Number|undefined} config.jobId Job ID
296
296
  * @param {EventModel} config.event Event build belongs to
297
+ * @param {String} config.causeMessage Reason the event is run
297
298
  * @returns {Promise<BuildModel|null>}
298
299
  */
299
300
  async function createInternalBuild(config) {
@@ -309,7 +310,8 @@ async function createInternalBuild(config) {
309
310
  start,
310
311
  baseBranch,
311
312
  parentBuildId,
312
- jobId
313
+ jobId,
314
+ causeMessage
313
315
  } = config;
314
316
  const { ref = '', prSource = '', prBranchName = '', url = '' } = event.pr || {};
315
317
  const prInfo = prBranchName ? { url, prBranchName } : '';
@@ -334,7 +336,8 @@ async function createInternalBuild(config) {
334
336
  prSource,
335
337
  prInfo,
336
338
  start: start !== false,
337
- baseBranch
339
+ baseBranch,
340
+ causeMessage
338
341
  };
339
342
 
340
343
  let jobState = job.state;
@@ -609,9 +612,10 @@ async function getParentBuildStatus({ newBuild, joinListNames, pipelineId, build
609
612
  * @param {String|undefined} arg.pipelineId Pipeline ID
610
613
  * @param {String|undefined} arg.stageName Stage name
611
614
  * @param {Boolean} arg.isVirtualJob If the job is virtual or not
615
+ * @param {Event} arg.event Event
612
616
  * @returns {Promise<Build|null>} The newly updated/created build
613
617
  */
614
- async function handleNewBuild({ done, hasFailure, newBuild, job, pipelineId, stageName, isVirtualJob }) {
618
+ async function handleNewBuild({ done, hasFailure, newBuild, job, pipelineId, stageName, isVirtualJob, event }) {
615
619
  if (!done || Status.isStarted(newBuild.status)) {
616
620
  return null;
617
621
  }
@@ -647,7 +651,9 @@ async function handleNewBuild({ done, hasFailure, newBuild, job, pipelineId, sta
647
651
  newBuild.status = Status.QUEUED;
648
652
  await newBuild.update();
649
653
 
650
- return newBuild.start();
654
+ const causeMessage = job.name === event.startFrom ? event.causeMessage : '';
655
+
656
+ return newBuild.start({ causeMessage });
651
657
  }
652
658
 
653
659
  /**
@@ -105,7 +105,8 @@ class JoinBase {
105
105
  job: nextJob,
106
106
  pipelineId,
107
107
  isVirtualJob: isNextJobVirtual,
108
- stageName: nextJobStageName
108
+ stageName: nextJobStageName,
109
+ event
109
110
  });
110
111
  }
111
112
  }
@@ -50,6 +50,8 @@ class OrBase {
50
50
  const hasFreezeWindows =
51
51
  nextJob.permutations[0].freezeWindows && nextJob.permutations[0].freezeWindows.length > 0;
52
52
 
53
+ const causeMessage = nextJob.name === event.startFrom ? event.causeMessage : '';
54
+
53
55
  if (nextBuild !== null) {
54
56
  if (Status.isStarted(nextBuild.status)) {
55
57
  return nextBuild;
@@ -67,7 +69,7 @@ class OrBase {
67
69
  nextBuild.status = Status.QUEUED;
68
70
  await nextBuild.update();
69
71
 
70
- return nextBuild.start();
72
+ return nextBuild.start({ causeMessage });
71
73
  }
72
74
 
73
75
  nextBuild = await createInternalBuild({
@@ -82,7 +84,8 @@ class OrBase {
82
84
  baseBranch: event.baseBranch || null,
83
85
  parentBuilds,
84
86
  parentBuildId: this.currentBuild.id,
85
- start: hasFreezeWindows || !isNextJobVirtual
87
+ start: hasFreezeWindows || !isNextJobVirtual,
88
+ causeMessage
86
89
  });
87
90
 
88
91
  // Bypass execution of the build if the job is virtual
@@ -110,12 +110,19 @@ Query Params:
110
110
  * `sortBy` - *Optional* Field to sort by
111
111
  * `type` - *Optional* Get pipeline or pr events (default `pipeline`)
112
112
  * `prNum` - *Optional* Return only PR events of specified PR number
113
- * `sha` - *Optional* Search `sha` and `configPipelineSha` for events
114
113
  * `groupEventId` - *Optional* Return only events with a specified groupEventId
115
114
  * `id` - *Optional* Fetch specific event ID; alternatively can use greater than(`gt:`) or less than(`lt:`) prefix
115
+ * `sha` - *Optional* Search `sha` and `configPipelineSha` for events
116
+ * `author` - *Optional* Search commit author `username` and `name` for events
117
+ * `creator` - *Optional* Search creator `username` and `name` for events
118
+ * `message` - *Optional* Search commit `message` for events
119
+
120
+ _Caveats_: Only one of the search fields can be used at one time (sha, author, creator, or message).
116
121
 
117
122
  `GET /pipelines/{id}/events?page={pageNumber}&count={countNumber}&sort={sort}&type={type}&prNum={prNumber}&sha={sha}`
118
123
 
124
+ `GET /pipelines/{id}/events?message={message}`
125
+
119
126
  `GET /pipelines/{id}/events?id=gt:{eventId}&count={countNumber}` (greater than eventId)
120
127
 
121
128
  `GET /pipelines/{id}/events?id=lt:{eventId}&count={countNumber}&sort=ascending` (less than eventId)
@@ -34,7 +34,7 @@ module.exports = () => ({
34
34
 
35
35
  handler: async (request, h) => {
36
36
  const factory = request.server.app.pipelineFactory;
37
- const { page, count, sha, prNum, id, sort, sortBy, groupEventId } = request.query;
37
+ const { page, count, sha, prNum, id, sort, sortBy, groupEventId, message, author, creator } = request.query;
38
38
 
39
39
  return factory
40
40
  .get(request.params.id)
@@ -62,13 +62,18 @@ module.exports = () => ({
62
62
  config.params.prNum = prNum;
63
63
  }
64
64
 
65
+ // Do a search
66
+ // See https://www.w3schools.com/sql/sql_like.asp for syntax
65
67
  if (sha) {
66
- config.search = {
67
- field: ['sha', 'configPipelineSha'],
68
- // Do a search for sha
69
- // See https://www.w3schools.com/sql/sql_like.asp for syntax
70
- keyword: `${sha}%`
71
- };
68
+ config.search = { field: ['sha', 'configPipelineSha'], keyword: `${sha}%` };
69
+ } else if (message) {
70
+ config.search = { field: ['commit'], keyword: `%"message":"${message}%` };
71
+ } else if (author) {
72
+ // searches name and username
73
+ config.search = { field: ['commit'], keyword: `%name":"${author}%` };
74
+ } else if (creator) {
75
+ // searches name and username
76
+ config.search = { field: ['creator'], keyword: `%name":"${creator}%` };
72
77
  }
73
78
 
74
79
  if (groupEventId) {
@@ -95,15 +100,24 @@ module.exports = () => ({
95
100
  id: pipelineIdSchema
96
101
  }),
97
102
  query: schema.api.pagination.concat(
98
- joi.object({
99
- type: typeSchema,
100
- prNum: prNumSchema,
101
- sha: shaSchema,
102
- id: queryIdSchema,
103
- groupEventId: pipelineIdSchema,
104
- search: joi.forbidden(), // we don't support search for Pipeline list events
105
- getCount: joi.forbidden() // we don't support getCount for Pipeline list events
106
- })
103
+ joi
104
+ .object({
105
+ type: typeSchema,
106
+ prNum: prNumSchema,
107
+ sha: shaSchema,
108
+ message: joi.string().label('Commit message').example('fix: Typo'),
109
+ author: joi.string().label('Author Name').example('Dao Lam'),
110
+ creator: joi.string().label('Creator Name').example('Dao Lam'),
111
+ id: queryIdSchema,
112
+ groupEventId: pipelineIdSchema,
113
+ search: joi.forbidden(), // we don't support search for Pipeline list events
114
+ getCount: joi.forbidden() // we don't support getCount for Pipeline list events
115
+ })
116
+ // https://joi.dev/api/?v=17.13.3#objectoxorpeers-options
117
+ .oxor('sha', 'message', 'author', 'creator')
118
+ .messages({
119
+ 'object.oxor': 'You can only specify one search parameter: sha, message, author, or creator.'
120
+ })
107
121
  )
108
122
  }
109
123
  }