screwdriver-api 8.0.53 → 8.0.55

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": "8.0.53",
3
+ "version": "8.0.55",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -7,6 +7,7 @@ const joi = require('joi');
7
7
  const schema = require('screwdriver-data-schema');
8
8
  const getSchema = schema.models.event.get;
9
9
  const idSchema = schema.models.event.base.extract('id');
10
+ const { deriveEventStatusFromBuildStatuses } = require('../builds/helper/updateBuild');
10
11
 
11
12
  module.exports = () => ({
12
13
  method: 'PUT',
@@ -78,6 +79,7 @@ module.exports = () => ({
78
79
  // User has good permissions, get event builds
79
80
  const builds = await event.getBuilds();
80
81
  const toUpdate = [];
82
+ const updatedBuilds = [];
81
83
 
82
84
  // Update endtime and stop running builds
83
85
  // Note: COLLAPSED builds will never run
@@ -90,10 +92,18 @@ module.exports = () => ({
90
92
  b.statusMessage = `Aborted by ${username}`;
91
93
 
92
94
  toUpdate.push(b.update());
95
+ } else {
96
+ updatedBuilds.push(b);
93
97
  }
94
98
  });
99
+ updatedBuilds.push(...(await Promise.all(toUpdate)));
95
100
 
96
- await Promise.all(toUpdate);
101
+ const newEventStatus = deriveEventStatusFromBuildStatuses(updatedBuilds);
102
+
103
+ if (newEventStatus && event.status !== newEventStatus) {
104
+ event.status = newEventStatus;
105
+ await event.update();
106
+ }
97
107
 
98
108
  // everything succeeded, inform the user
99
109
  const location = urlLib.format({
@@ -69,31 +69,17 @@ const webhooksPlugin = {
69
69
  const { executor, queueWebhookEnabled } = queueWebhook;
70
70
  const message = 'Unable to process this kind of event';
71
71
  let hookId;
72
- let webhookSettings;
73
72
 
74
73
  try {
75
- const scmContexts = await scm.getScmContexts();
76
-
77
- scmContexts.forEach(scmContext => {
78
- if (pluginOptions[scmContext]) {
79
- webhookSettings = pluginOptions[scmContext];
80
- }
81
- });
82
-
83
- if (!webhookSettings) {
84
- logger.error(`No webhook settings found for scm context: ${scmContexts.join(', ')}`);
85
- throw boom.internal();
86
- }
87
-
88
74
  let size = 0;
89
75
  let data = '';
90
76
 
91
77
  for await (const chunk of request.payload) {
92
78
  size += chunk.length;
93
79
  data += chunk;
94
- if (size > (webhookSettings.maxBytes || DEFAULT_MAX_BYTES)) {
80
+ if (size > DEFAULT_MAX_BYTES) {
95
81
  throw boom.entityTooLarge(
96
- `Payload size exceeds the maximum limit of ${webhookSettings.maxBytes || DEFAULT_MAX_BYTES} bytes`
82
+ `Payload size exceeds the maximum limit of ${DEFAULT_MAX_BYTES} bytes`
97
83
  );
98
84
  }
99
85
  }
@@ -113,6 +99,13 @@ const webhooksPlugin = {
113
99
  return h.response({ message }).code(204);
114
100
  }
115
101
 
102
+ const webhookSettings = pluginOptions[parsed.scmContext];
103
+
104
+ if (!webhookSettings) {
105
+ logger.error(`No webhook settings found for scm context: ${parsed.scmContext}`);
106
+ throw boom.internal();
107
+ }
108
+
116
109
  parsed.pluginOptions = webhookSettings;
117
110
 
118
111
  const { type } = parsed;