screwdriver-api 4.1.178 → 4.1.182

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.
@@ -60,7 +60,8 @@ async function registerResourcePlugins(server, config) {
60
60
  'isAdmin',
61
61
  'shutdown',
62
62
  'release',
63
- 'validator'
63
+ 'validator',
64
+ 'processHooks'
64
65
  ];
65
66
 
66
67
  if (hoek.reach(config, 'coverage.coveragePlugin')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "4.1.178",
3
+ "version": "4.1.182",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,49 @@
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.build.base.extract('id');
7
+
8
+ module.exports = config => ({
9
+ method: 'POST',
10
+ path: '/builds/{id}/artifacts/unzip',
11
+ options: {
12
+ description: 'Extract a ZIP for build artifacts',
13
+ notes: 'Extract a specific ZIP for build artifacts',
14
+ tags: ['api', 'builds', 'artifacts'],
15
+ auth: {
16
+ strategies: ['token'],
17
+ scope: ['build']
18
+ },
19
+
20
+ handler: async (req, h) => {
21
+ const buildId = req.params.id;
22
+ const { username, scope } = req.auth.credentials;
23
+ const isBuild = scope.includes('build');
24
+ const { buildFactory } = req.server.app;
25
+
26
+ if (isBuild && username !== buildId) {
27
+ return boom.forbidden(`Credential only valid for ${username}`);
28
+ }
29
+
30
+ return buildFactory
31
+ .get(buildId)
32
+ .then(async buildModel => {
33
+ if (!buildModel) {
34
+ throw boom.notFound('Build does not exist');
35
+ }
36
+ await buildModel.unzipArtifacts();
37
+ return h.response().code(202);
38
+ })
39
+ .catch(err => {
40
+ throw err;
41
+ });
42
+ },
43
+ validate: {
44
+ params: joi.object({
45
+ id: idSchema
46
+ })
47
+ }
48
+ }
49
+ });
@@ -11,6 +11,7 @@ const createRoute = require('./create');
11
11
  const stepGetRoute = require('./steps/get');
12
12
  const listStepsRoute = require('./steps/list');
13
13
  const artifactGetRoute = require('./artifacts/get');
14
+ const artifactUnzipRoute = require('./artifacts/unzip');
14
15
  const stepUpdateRoute = require('./steps/update');
15
16
  const stepLogsRoute = require('./steps/logs');
16
17
  const listSecretsRoute = require('./listSecrets');
@@ -270,7 +271,6 @@ async function createInternalBuild(config) {
270
271
  } else {
271
272
  job = await jobFactory.get(jobId);
272
273
  }
273
-
274
274
  const internalBuildConfig = {
275
275
  jobId: job.id,
276
276
  sha: event.sha,
@@ -410,6 +410,11 @@ function parseJobInfo({ joinObj = {}, current, nextJobName, nextPipelineId }) {
410
410
  * @return {Promise} All finished builds
411
411
  */
412
412
  async function getFinishedBuilds(event, buildFactory) {
413
+ if (!event.parentEventId) {
414
+ // FIXME: remove this flow to always use buildFactory.getLatestBuilds
415
+ return event.getBuilds();
416
+ }
417
+
413
418
  // FIXME: buildFactory.getLatestBuilds doesn't return build model
414
419
  const builds = await buildFactory.getLatestBuilds({ groupEventId: event.groupEventId });
415
420
 
@@ -1106,7 +1111,8 @@ const buildsPlugin = {
1106
1111
  listSecretsRoute(),
1107
1112
  tokenRoute(),
1108
1113
  metricsRoute(),
1109
- artifactGetRoute(options)
1114
+ artifactGetRoute(options),
1115
+ artifactUnzipRoute(),
1110
1116
  ]);
1111
1117
  }
1112
1118
  };
@@ -149,7 +149,7 @@ module.exports = () => ({
149
149
 
150
150
  const [files, prInfo] = await Promise.all([
151
151
  scm.getChangedFiles({
152
- payload: null,
152
+ webhookConfig: null,
153
153
  type: 'pr',
154
154
  ...scmConfig
155
155
  }),
@@ -0,0 +1,33 @@
1
+ # Process Hooks Plugin
2
+ > Hapi processHooks plugin for the Screwdriver API
3
+
4
+ ## Usage
5
+
6
+ ### Register plugin
7
+
8
+ ```javascript
9
+ const Hapi = require('@hapi/hapi');
10
+ const server = new Hapi.Server();
11
+ const processHooksPlugin = require('./');
12
+
13
+ server.connection({ port: 3000 });
14
+
15
+ server.register({
16
+ register: processHooksPlugin,
17
+ options: {}
18
+ }, () => {
19
+ server.start((err) => {
20
+ if (err) {
21
+ throw err;
22
+ }
23
+ console.log('Server running at:', server.info.uri);
24
+ });
25
+ });
26
+ ```
27
+
28
+ ### Routes
29
+
30
+ #### Start pipeline events from scm webhook config
31
+
32
+ `POST /processHooks`
33
+
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const logger = require('screwdriver-logger');
4
+ const { startHookEvent } = require('../webhooks/helper');
5
+
6
+ /**
7
+ * Process Hooks API Plugin
8
+ * - Start pipeline events with scm webhook config via queue-service
9
+ * @method register
10
+ * @param {Hapi} server Hapi Server
11
+ * @param {Object} options Configuration
12
+ * @param {Function} next Function to call when done
13
+ */
14
+ const processHooksPlugin = {
15
+ name: 'processHooks',
16
+ async register(server, options) {
17
+ server.route({
18
+ method: 'POST',
19
+ path: '/processHooks',
20
+ options: {
21
+ description: 'Handle process hook events',
22
+ notes: 'Acts on pull request, pushes, comments, etc.',
23
+ tags: ['api', 'processHook'],
24
+ auth: {
25
+ strategies: ['token'],
26
+ scope: ['webhook_worker']
27
+ },
28
+ plugins: {
29
+ 'hapi-rate-limit': {
30
+ enabled: false
31
+ }
32
+ },
33
+ handler: async (request, h) => {
34
+ try {
35
+ return await startHookEvent(request, h, request.payload);
36
+ } catch (err) {
37
+ logger.error(`Error starting hook events for ${request.payload.hookId}:${err}`);
38
+
39
+ throw err;
40
+ }
41
+ }
42
+ }
43
+ });
44
+ }
45
+ };
46
+
47
+ module.exports = processHooksPlugin;