screwdriver-api 7.0.164 → 7.0.166

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.164",
3
+ "version": "7.0.166",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -123,7 +123,7 @@
123
123
  "screwdriver-scm-github": "^12.6.0",
124
124
  "screwdriver-scm-gitlab": "^3.1.0",
125
125
  "screwdriver-scm-router": "^7.1.0",
126
- "screwdriver-template-validator": "^8.0.0",
126
+ "screwdriver-template-validator": "^8.1.0",
127
127
  "screwdriver-workflow-parser": "^4.1.1",
128
128
  "sqlite3": "^5.1.4",
129
129
  "stream": "0.0.2",
@@ -4,7 +4,7 @@ const urlLib = require('url');
4
4
  const boom = require('@hapi/boom');
5
5
  const validationSchema = require('screwdriver-data-schema');
6
6
  const ANNOT_RESTRICT_PR = 'screwdriver.cd/restrictPR';
7
- const { getScmUri } = require('../helper');
7
+ const { getScmUri, isStageTeardown } = require('../helper');
8
8
 
9
9
  module.exports = () => ({
10
10
  method: 'POST',
@@ -29,6 +29,11 @@ module.exports = () => ({
29
29
  let { pipelineId, startFrom, parentBuildId, parentBuilds, groupEventId, parentEventId, prNum } =
30
30
  request.payload;
31
31
 
32
+ // Validation: Prevent event creation if startFrom is a stage teardown and parentEventID does not exist (start case)
33
+ if (isStageTeardown(startFrom) && !parentEventId) {
34
+ throw boom.badRequest('Event cannot be started from a stage teardown');
35
+ }
36
+
32
37
  // restart case
33
38
  if (buildId) {
34
39
  const b = await buildFactory.get(buildId);
package/plugins/helper.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const boom = require('@hapi/boom');
4
4
  const dayjs = require('dayjs');
5
5
  const STAGE_PREFIX = 'stage@';
6
+ const STAGE_TEARDOWN_PATTERN = /^stage@([\w-]+):teardown$/;
6
7
 
7
8
  /**
8
9
  * Set default start time and end time
@@ -113,11 +114,21 @@ function getFullStageJobName({ stageName, jobName }) {
113
114
  return `${STAGE_PREFIX}${stageName}:${jobName}`;
114
115
  }
115
116
 
117
+ /**
118
+ * Check if the job is teardown job with teardown suffix
119
+ * @param {String} jobName Job name
120
+ * @return {Boolean}
121
+ */
122
+ function isStageTeardown(jobName) {
123
+ return STAGE_TEARDOWN_PATTERN.test(jobName);
124
+ }
125
+
116
126
  module.exports = {
117
127
  getReadOnlyInfo,
118
128
  getScmUri,
119
129
  getUserPermissions,
120
130
  setDefaultTimeRange,
121
131
  validTimeRange,
122
- getFullStageJobName
132
+ getFullStageJobName,
133
+ isStageTeardown
123
134
  };