GitHub Integration
Set up HookWatch to receive GitHub webhooks for repository events like pushes, pull requests, issues, and more.
Prerequisites
- A HookWatch account
- A GitHub repository with admin access (for repository webhooks) or organization admin access (for organization webhooks)
- A server endpoint to process webhook payloads
Step 1: Create a HookWatch endpoint
- Go to your Endpoints page
- Click "Create Endpoint"
- Enter a name like "GitHub Webhooks"
- Enter your destination URL (where you want webhooks forwarded)
- Copy the generated webhook URL
Step 2: Configure GitHub webhook
For a repository:
- Go to your repository on GitHub
- Click Settings > Webhooks
- Click "Add webhook"
- Paste your HookWatch URL in the "Payload URL" field
- Set Content type to
application/json - Enter a Secret (you'll use this to verify webhooks)
- Select the events you want to trigger webhooks
- Click "Add webhook"
For an organization:
- Go to your organization settings on GitHub
- Click Webhooks in the sidebar
- Follow the same steps as above
Common events to subscribe to:
push - Code pushed to repositorypull_request - PR opened/closed/mergedissues - Issue created/updatedissue_comment - Comment on issue/PRrelease - Release publishedworkflow_run - GitHub Actions statusdeployment - Deployment createdstar - Repository starredStep 3: Verify webhooks on your server
GitHub signs webhook payloads with the secret you provided. HookWatch forwards the X-Hub-Signature-256 header so you can verify authenticity.
const crypto = require('crypto');
function verifyGitHubSignature(payload, signature, secret) {
const hmac = crypto.createHmac('sha256', secret);
const digest = 'sha256=' + hmac.update(payload).digest('hex');
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(digest));
}
app.post('/webhooks/github', express.raw({type: 'application/json'}), (req, res) => {
const signature = req.headers['x-hub-signature-256'];
const secret = process.env.GITHUB_WEBHOOK_SECRET;
if (!verifyGitHubSignature(req.body, signature, secret)) {
return res.status(401).send('Invalid signature');
}
const event = req.headers['x-github-event'];
const payload = JSON.parse(req.body);
switch (event) {
case 'push':
console.log('Push to', payload.repository.full_name);
break;
case 'pull_request':
console.log('PR', payload.action, payload.pull_request.title);
break;
// ... handle other events
}
res.json({received: true});
});GitHub webhook headers
HookWatch forwards all GitHub headers. Here are the important ones:
| Header | Description |
|---|---|
X-GitHub-Event | The event type (push, pull_request, etc.) |
X-GitHub-Delivery | Unique ID for the webhook delivery |
X-Hub-Signature-256 | HMAC hex digest of the payload (SHA-256) |
X-Hub-Signature | HMAC hex digest (SHA-1, deprecated) |
Testing the integration
You can redeliver webhooks from the GitHub webhook settings:
- Go to your webhook settings in GitHub
- Click on "Recent Deliveries"
- Click on any delivery and then "Redeliver"
- Check your HookWatch Events page
Common issues
Signature verification fails
Make sure the secret in your code exactly matches what you entered in GitHub. The secret is case-sensitive and must not have extra whitespace.
Webhook shows as "failed" in GitHub
GitHub expects a 2xx response. If your server returns an error, GitHub marks the delivery as failed. Check your server logs and the HookWatch event details for more info.
Missing events
Verify that you've selected the correct events in GitHub webhook settings. Some events (like workflow_run) might not be enabled by default.