| .. | ||
| debug-secret.js | ||
| README.md | ||
| test-gh-webhook-simple-curl.sh | ||
| test-github-webhooks.js | ||
GitHub Webhook Testing
This directory contains tools for testing GitHub webhooks locally during development.
Quick Start
-
Start your local server:
npm run dev -
Run webhook tests:
# Test all webhooks node test/webhooks/test-github-webhooks.js # Test specific webhook node test/webhooks/test-github-webhooks.js installation node test/webhooks/test-github-webhooks.js pull_request.opened
Configuration
The test script uses the following defaults:
- Webhook Secret:
dev-webhook-secret-2pjGGmaNy2gyEY4o3aU - Server URL:
http://localhost:3001/cfapi/github/webhooks
To use different values:
# Custom server URL
SERVER_URL=http://localhost:4000/webhooks node test/webhooks/test-github-webhooks.js
# Custom webhook secret
GH_APP_WEBHOOK_SECRET=my-secret node test/webhooks/test-github-webhooks.js
Available Webhook Events
ping- GitHub ping eventinstallation- App installation createdinstallation_repositories- Repositories added to installationpull_request.opened- Pull request openedpull_request.closed- Pull request closed (includes merge scenario)pull_request.synchronize- Pull request updated with new commitsmarketplace_purchase- Marketplace purchase eventcheck_suite- Check suite requested
Adding New Test Events
To add a new webhook event for testing:
- Add the payload to
webhookPayloadsobject intest-github-webhooks.js - Use actual payload structure from GitHub Webhook Events documentation
- Include all required fields for your event handlers
Development Setup
For local development, ensure your .env file includes:
GH_APP_WEBHOOK_SECRET=dev-webhook-secret-2pjGGmaNy2gyEY4o3aU
This matches the default secret used by the test script.
Testing with Real GitHub Webhooks
For testing with actual GitHub webhooks:
-
Install ngrok:
brew install ngrok # macOS # or download from https://ngrok.com -
Expose your local server:
ngrok http 3001 -
Update your GitHub App webhook URL:
- Go to your GitHub App settings
- Set webhook URL to:
https://[your-ngrok-subdomain].ngrok.io/cfapi/github/webhooks - Keep the same webhook secret
-
Monitor webhooks:
- Check your server logs
- View webhook deliveries in GitHub App settings
Troubleshooting
"Cannot set headers after they are sent" error
- Ensure CORS middleware is placed before webhook routes in
server.js
Webhook not being processed
- Check that
ghAppMiddlewareis created with the correct path prefix - Verify webhook secret matches between test script and server
- Ensure event handlers are registered in
github-app.js
Signature verification failing
- Webhook secret must match exactly (including any whitespace)
- Payload must be stringified consistently
- Check that headers are properly formatted
Example Output
GitHub Webhook Local Testing
Server URL: http://localhost:3001/cfapi/github/webhooks
Webhook Secret: dev-webhoo...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Testing webhook: installation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Delivery ID: 550e8400-e29b-41d4-a716-446655440000
Signature: sha256=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0...
Payload size: 1234 bytes
Response:
Status: 200 (45ms)
Body: Webhook processed successfully
✓ Webhook delivered successfully