screwdriver-api 4.1.280 → 4.1.283

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.
@@ -149,7 +149,7 @@ function registerNotificationEvent(config, server) {
149
149
  }
150
150
 
151
151
  notificationPlugin.events.forEach(event => {
152
- server.events.on(event, buildData => notificationPlugin.notify(buildData));
152
+ server.events.on(event, buildData => notificationPlugin.notify(event, buildData));
153
153
  });
154
154
  }
155
155
  });
package/lib/server.js CHANGED
@@ -141,9 +141,7 @@ module.exports = async config => {
141
141
  ecosystem: config.ecosystem,
142
142
  release: config.release,
143
143
  queueWebhook: config.queueWebhook,
144
- feature: {
145
- unzipArtifacts: config.unzipArtifactsEnabled
146
- }
144
+ unzipArtifacts: config.unzipArtifactsEnabled
147
145
  };
148
146
 
149
147
  const bellConfigs = await config.auth.scm.getBellConfiguration();
@@ -162,8 +160,8 @@ module.exports = async config => {
162
160
  // Write prettier errors
163
161
  server.ext('onPreResponse', prettyPrintErrors);
164
162
 
165
- // Register build_status event for notifications plugin
166
- server.event('build_status');
163
+ // Register events for notifications plugin
164
+ server.event(['build_status', 'job_status']);
167
165
 
168
166
  // Register plugins
169
167
  await registerPlugins(server, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "4.1.280",
3
+ "version": "4.1.283",
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": "^7.6.0",
106
106
  "screwdriver-coverage-bookend": "^1.0.3",
107
107
  "screwdriver-coverage-sonar": "^3.4.0",
108
- "screwdriver-data-schema": "^21.27.0",
108
+ "screwdriver-data-schema": "^21.28.1",
109
109
  "screwdriver-datastore-sequelize": "^7.2.7",
110
110
  "screwdriver-executor-base": "^8.4.0",
111
111
  "screwdriver-executor-docker": "^5.0.1",
@@ -115,8 +115,8 @@
115
115
  "screwdriver-executor-router": "^2.3.0",
116
116
  "screwdriver-logger": "^1.1.0",
117
117
  "screwdriver-models": "^28.18.1",
118
- "screwdriver-notifications-email": "^2.2.0",
119
- "screwdriver-notifications-slack": "^3.2.1",
118
+ "screwdriver-notifications-email": "^2.3.1",
119
+ "screwdriver-notifications-slack": "^3.3.0",
120
120
  "screwdriver-request": "^1.0.3",
121
121
  "screwdriver-scm-base": "^7.3.0",
122
122
  "screwdriver-scm-bitbucket": "^4.5.1",
@@ -18,7 +18,7 @@ module.exports = config => ({
18
18
  },
19
19
 
20
20
  handler: async (req, h) => {
21
- if (!req.server.app.feature.unzipArtifacts) {
21
+ if (!req.server.app.unzipArtifacts) {
22
22
  const data = {
23
23
  statusCode: 200,
24
24
  message: "This function is not enabled and will do nothing."
@@ -6,6 +6,7 @@ const listBuildsRoute = require('./listBuilds');
6
6
  const lastSuccessfulMeta = require('./lastSuccessfulMeta');
7
7
  const latestBuild = require('./latestBuild');
8
8
  const metrics = require('./metrics');
9
+ const notify = require('./notify');
9
10
 
10
11
  /**
11
12
  * Job API Plugin
@@ -15,7 +16,15 @@ const metrics = require('./metrics');
15
16
  const jobsPlugin = {
16
17
  name: 'jobs',
17
18
  async register(server) {
18
- server.route([getRoute(), updateRoute(), listBuildsRoute(), lastSuccessfulMeta(), metrics(), latestBuild()]);
19
+ server.route([
20
+ getRoute(),
21
+ updateRoute(),
22
+ listBuildsRoute(),
23
+ lastSuccessfulMeta(),
24
+ metrics(),
25
+ latestBuild(),
26
+ notify()
27
+ ]);
19
28
  }
20
29
  };
21
30
 
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const boom = require('@hapi/boom');
4
+ const joi = require('joi');
5
+ const schema = require('screwdriver-data-schema');
6
+ const idSchema = schema.models.job.base.extract('id');
7
+ const statusSchema = schema.models.build.base.extract('status');
8
+ const messageSchema = joi.string();
9
+
10
+ module.exports = () => ({
11
+ method: 'POST',
12
+ path: '/jobs/{id}/notify',
13
+ options: {
14
+ description: 'Notify user about job status',
15
+ notes: 'Does nothing if notifaction setting was not set',
16
+ tags: ['api', 'jobs'],
17
+ auth: {
18
+ strategies: ['token'],
19
+ scope: ['pipeline']
20
+ },
21
+
22
+ handler: async (request, h) => {
23
+ const { jobFactory, pipelineFactory } = request.server.app;
24
+ const { credentials } = request.auth;
25
+ const jobId = request.params.id;
26
+ const job = await jobFactory.get(jobId);
27
+ const uiUrl = request.server.app.ecosystem.ui;
28
+
29
+ if (!job) {
30
+ throw boom.notFound(`Job ${jobId} does not exist`);
31
+ }
32
+
33
+ const pipelineId = job.pipelineId;
34
+
35
+ if (pipelineId !== credentials.pipelineId) {
36
+ throw boom.forbidden('Token does not have permission for this pipeline');
37
+ }
38
+
39
+ const pipeline = await pipelineFactory.get(pipelineId);
40
+
41
+ await request.server.events.emit('job_status', {
42
+ status: request.payload.status,
43
+ pipeline: pipeline.toJson(),
44
+ jobName: job.name,
45
+ pipelineLink: `${uiUrl}/pipelines/${pipelineId}`,
46
+ message: request.payload.message,
47
+ settings: job.permutations[0].settings
48
+ });
49
+
50
+ return h.response({}).code(200);
51
+ },
52
+ validate: {
53
+ params: joi.object({
54
+ id: idSchema
55
+ }),
56
+ payload: joi.object({
57
+ status: statusSchema,
58
+ message: messageSchema
59
+ })
60
+ }
61
+ }
62
+ });