A Rust server that handles GitHub pull request webhooks.
- Clone the repository
- Set environment variables:
export GITHUB_WEBHOOK_SECRET=your_webhook_secret
export PORT=3000 # Optional, defaults to 3000
export WEBHOOK_SCRIPT=./pr_script.sh # Optional, defaults to ./pr_script.sh- Run the server
cargo run- Test with curl (simulating a GitHub webhook):
Generate signature (replace 'your_webhook_secret' with your secret)
echo -n '{"action":"opened","number":1,"pull_request":{"title":"Test PR","html_url":"https://github.com/user/repo/pull/1"}}' | openssl sha256 -hmac "your_webhook_secret" -hexSend test webhook
curl -X POST http://localhost:3000/webhook \
-H "Content-Type: application/json" \
-H "X-Hub-Signature-256: sha256=<signature_from_above>" \
-d '{"action":"opened","number":1,"pull_request":{"title":"Test PR","html_url":"https://github.com/user/repo/pull/1"}}'- Install Cloudflare CLI tool:
brew install cloudflare/cloudflare/cloudflared  # macOS
# or
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb  # Linux- Create a tunnel to expose your local server:
cloudflared tunnel --url http://localhost:3000- Copy the generated URL (like https://your-tunnel.trycloudflare.com)
- 
Go to your GitHub repository 
- 
Navigate to Settings > Webhooks > Add webhook 
- 
Configure the webhook: - Payload URL: Your Cloudflare tunnel URL + /webhook(e.g.,https://your-tunnel.trycloudflare.com/webhook)
- Content type: application/json
- Secret: Same value as your GITHUB_WEBHOOK_SECRET
- Events: Select "Pull requests"
- Active: Check this box
 
- Payload URL: Your Cloudflare tunnel URL + 
- 
Click "Add webhook" 
Now when you:
- Create a new PR
- Update an existing PR GitHub will send webhooks to your local server through the Cloudflare tunnel.
You can still use the test script for local testing:
./test_webhook.shRun the tests:
cargo testTo run with 1password cli:
op run --env-file demo.env -- cargo runTo run with 1password cli and test webhook over tunnel:
op run --env-file demo.env -- ./test_webhook_over_tunnel.sh