Skip to content

Commit

Permalink
feat(1769): Add processHooks endpoint for queue-service cooperation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yk634 authored Jan 3, 2022
1 parent 2f0f5d9 commit 63d19a4
Show file tree
Hide file tree
Showing 11 changed files with 1,802 additions and 1,408 deletions.
3 changes: 2 additions & 1 deletion lib/registerPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async function registerResourcePlugins(server, config) {
'isAdmin',
'shutdown',
'release',
'validator'
'validator',
'processHooks'
];

if (hoek.reach(config, 'coverage.coveragePlugin')) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/events/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = () => ({

const [files, prInfo] = await Promise.all([
scm.getChangedFiles({
payload: null,
webhookConfig: null,
type: 'pr',
...scmConfig
}),
Expand Down
33 changes: 33 additions & 0 deletions plugins/processHooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Process Hooks Plugin
> Hapi processHooks plugin for the Screwdriver API
## Usage

### Register plugin

```javascript
const Hapi = require('@hapi/hapi');
const server = new Hapi.Server();
const processHooksPlugin = require('./');

server.connection({ port: 3000 });

server.register({
register: processHooksPlugin,
options: {}
}, () => {
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
});
```

### Routes

#### Start pipeline events from scm webhook config

`POST /processHooks`

47 changes: 47 additions & 0 deletions plugins/processHooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const logger = require('screwdriver-logger');
const { startHookEvent } = require('../webhooks/helper');

/**
* Process Hooks API Plugin
* - Start pipeline events with scm webhook config via queue-service
* @method register
* @param {Hapi} server Hapi Server
* @param {Object} options Configuration
* @param {Function} next Function to call when done
*/
const processHooksPlugin = {
name: 'processHooks',
async register(server, options) {
server.route({
method: 'POST',
path: '/processHooks',
options: {
description: 'Handle process hook events',
notes: 'Acts on pull request, pushes, comments, etc.',
tags: ['api', 'processHook'],
auth: {
strategies: ['token'],
scope: ['webhook_worker']
},
plugins: {
'hapi-rate-limit': {
enabled: false
}
},
handler: async (request, h) => {
try {
return await startHookEvent(request, h, request.payload);
} catch (err) {
logger.error(`Error starting hook events for ${request.payload.hookId}:${err}`);

throw err;
}
}
}
});
}
};

module.exports = processHooksPlugin;
Loading

0 comments on commit 63d19a4

Please sign in to comment.