Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(1769): [5] Add processHooks endpoint for queue-service cooperation #2622

Merged
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'],
yk634 marked this conversation as resolved.
Show resolved Hide resolved
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}`);
yk634 marked this conversation as resolved.
Show resolved Hide resolved

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

module.exports = processHooksPlugin;
Loading