A Github Webhook Testing Tool
npm install github-webhook-testerThe GitHub Webhook Tester is a tool that generates an API exposed over an ngrok tunnel, configures a repositories webhooks to use this API, and provides multiway logging for events.
How does this tool address this?
1. First get the command line args and parse these - generating any required logger instances
2. Next build and start a REST API server from the blueprint provided in the --spec argument, see ./example/ for example blueprints
3. Create an ngrok.io tunnel, and generate a url
4. Connect to the GitHub repository
5. Delete any existing hooks that use ngrok.io and exist in the blueprint we provided
6. Create a brand new set of hooks using the new ngrok.io tunnel and the blueprint in the spec file
7. Provide multiway logging and execute the callbacks designated in the spec file
github-webhook-tester --token XXX --repo :owner/:repo./example/basic.js blueprintgithub-webhook-tester --token XXX --repo :owner/:repo --spec path/to/jsspecpath/to/jsspecgithub-webhook-tester --token XXX --repo :owner/:repo --noConsoleLogging./example/basic.js blueprintgithub-webhook-tester --token XXX --repo :owner/:repo --noConsoleOutput --logLevel 4./example/basic.js blueprintmkdir logs && github-webhook-tester --token XXX --repo :owner/:repo --noConsoleOutput --hookfile=./logs/payloads.log--outputFile./example/basic.jsSee a full breakdown of the options below
- --logLevel Specify the level of logging for the system logs (defaults to 5 for ALL logs)
- --spec Specify the blueprint file to use for the API (--spec=./path/bp.js)
- --repo Specify the target repository to manage the hooks on
- --token Specify the OAuth token with repo scope to use
- --port Specify the port to expose to ngrok, defaults to 5000
- --logfile Specify the file to write the system logs to (--logfile ./logs/log.log)
- --suppressConsoleLogs Switch off console logging
- --hookfile Specify the file to write the webhook content to (--hookfile ./logs/payload.log)
- --suppressConsoleHooks Switch off console output of the payloads
- --suppressConsole Switch off all console output
The spec file is relatively straightforward, the js module you create must return specific keys:
```
module.exports = {
hook_endpoint: {
content_type: json,
callback: (req, res) => {},
verb: 'post',
events: ['*'],
}/hook_endpoint
The outer keys of the object we provide to module.exports are our endpoints, in this case .content_type
For each of these endpoints we provide:
- for the webhook, this will either be json or form, json makes the most sense here.callback
- is the function that will be called when a payload is received, the callback function is an express-js callback: https://expressjs.com/en/api.html#app.post.method req is the request, res is your response (send a 200!)verb
- is the http method, in all cases this will be post - but for flexibility why not :smile:events
- is an array of events that you want this webhook to listen for, * is a wildcard
1. Finish the command line options
2. Add tests to maintain stability and integrity
3. Add more spec examples
4. Add further logging transport layers