-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(1769): Add processHooks endpoint for queue-service cooperation (#…
- Loading branch information
Showing
11 changed files
with
1,802 additions
and
1,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.