screwdriver-api 4.1.181 → 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.
- package/lib/registerPlugins.js +2 -1
- package/package.json +1 -1
- package/plugins/events/create.js +1 -1
- package/plugins/processHooks/README.md +33 -0
- package/plugins/processHooks/index.js +47 -0
- package/plugins/webhooks/helper.js +1192 -0
- package/plugins/webhooks/index.js +6 -1164
package/lib/registerPlugins.js
CHANGED
package/package.json
CHANGED
package/plugins/events/create.js
CHANGED
|
@@ -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;
|