Command-line tool for testing the github-copier webhook endpoint with example or real PR data.
The test-webhook tool helps you:
- Test webhook processing locally
- Use example payloads for testing
- Fetch real PR data from GitHub
- Debug webhook issues
- Validate configuration with real data
cd github-copier
go build -o test-webhook ./cmd/test-webhookSend a pre-made example payload to the webhook endpoint.
Usage:
./test-webhook -payload <file> [-url <url>]Options:
-payload- Path to JSON payload file (required)-url- Webhook URL (default:http://localhost:8080/events)
Example:
# Use example payload
./test-webhook -payload testdata/example-pr-merged.json
# Use custom URL
./test-webhook -payload testdata/example-pr-merged.json \
-url http://localhost:8080/eventsOutput:
Testing webhook with example payload...
✓ Loaded payload from testdata/example-pr-merged.json
✓ Response: 200 OK
✓ Webhook sent successfully
Check application logs for processing details.
Fetch real PR data from GitHub and send it to the webhook.
Usage:
./test-webhook -pr <number> -owner <owner> -repo <repo> [-url <url>]Options:
-pr- Pull request number (required)-owner- Repository owner (required)-repo- Repository name (required)-url- Webhook URL (default:http://localhost:8080/events)
Environment Variables:
GITHUB_TOKEN- GitHub personal access token (required for real PR data)
Example:
# Set GitHub token
export GITHUB_TOKEN=ghp_your_token_here
# Test with real PR
./test-webhook -pr 42 -owner mongodb -repo docs-code-examples
# Test with custom URL
./test-webhook -pr 42 -owner mongodb -repo docs-code-examples \
-url http://localhost:8080/eventsOutput:
Fetching PR data from GitHub...
✓ Fetched PR #42 from mongodb/docs-code-examples
✓ PR Title: Add Go database examples
✓ Files changed: 21
✓ Response: 200 OK
✓ Webhook sent successfully
Check application logs for processing details.
Test your configuration locally before deploying:
# 1. Start app in dry-run mode
./scripts/run-local.sh
# 2. In another terminal, send test webhook
./test-webhook -payload testdata/example-pr-merged.json
# 3. Check logs (JSON format on stdout via slog)Test if your patterns match real PR files:
# 1. Start app
./scripts/run-local.sh
# 2. Send webhook with real PR data
export GITHUB_TOKEN=ghp_...
./test-webhook -pr 42 -owner myorg -repo myrepo
# 3. Check metrics
curl http://localhost:8080/metrics | jq '.files'Verify files are copied to correct locations:
# 1. Start app in dry-run mode
DRY_RUN=true ./github-copier &
# 2. Send test webhook
./test-webhook -payload testdata/example-pr-merged.json
# 3. Check logs for transformed paths
# Check stdout for "transformed path" entriesTest Slack integration:
# 1. Start app with Slack enabled
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
./github-copier &
# 2. Send test webhook
./test-webhook -payload testdata/example-pr-merged.json
# 3. Check Slack channel for notificationDebug webhook processing:
# 1. Enable debug logging
export LOG_LEVEL=debug
./github-copier &
# 2. Send test webhook
./test-webhook -payload testdata/example-pr-merged.json
# 3. Review detailed logs
# Run with LOG_LEVEL=debug for verbose outputThe testdata/ directory contains example webhook payloads:
A complete merged PR payload with:
- Multiple file changes (added, modified, removed)
- Various file types and paths
- Realistic PR metadata
Usage:
./test-webhook -payload testdata/example-pr-merged.jsonCreate custom payloads for specific test scenarios:
# Copy example
cp testdata/example-pr-merged.json testdata/my-test.json
# Edit to match your test case
vim testdata/my-test.json
# Test with custom payload
./test-webhook -payload testdata/my-test.jsonExample custom payload:
{
"action": "closed",
"pull_request": {
"number": 123,
"merged": true,
"merge_commit_sha": "abc123",
"head": {
"sha": "def456"
}
},
"repository": {
"full_name": "myorg/myrepo"
}
}# 1. Start app in dry-run mode
DRY_RUN=true ./github-copier &
# 2. Test with example payload
./test-webhook -payload testdata/example-pr-merged.json
# 3. Check metrics
curl http://localhost:8080/metrics | jq
# 4. Test with real PR
export GITHUB_TOKEN=ghp_...
./test-webhook -pr 42 -owner myorg -repo myrepo
# 5. Review logs
# Check stdout for "matched" entriesError:
Error: connection refused
Solution: Ensure the app is running:
curl http://localhost:8080/healthError:
Response: 401 Unauthorized
Solution: Disable webhook signature verification for testing:
unset WEBHOOK_SECRET
./github-copier &Error:
Response: 404 Not Found
Solution: Check the webhook URL:
# Default is /events
./test-webhook -payload test.json -url http://localhost:8080/eventsError:
Error: GitHub API rate limit exceeded
Solution:
- Wait for rate limit reset
- Use authenticated requests with
GITHUB_TOKEN - Use example payloads instead of real PR data
Error:
Error: invalid JSON payload
Solution: Validate your JSON:
cat testdata/my-test.json | jq# Create script to test multiple PRs
cat > test-multiple-prs.sh << 'EOF'
#!/bin/bash
export GITHUB_TOKEN=ghp_...
for pr in 42 43 44 45; do
echo "Testing PR #$pr..."
./test-webhook -pr $pr -owner myorg -repo myrepo
sleep 2
done
EOF
chmod +x test-multiple-prs.sh
./test-multiple-prs.sh# Create test script
cat > run-tests.sh << 'EOF'
#!/bin/bash
set -e
echo "Starting app..."
DRY_RUN=true ./github-copier &
APP_PID=$!
sleep 2
echo "Running tests..."
./test-webhook -payload testdata/example-pr-merged.json
echo "Checking metrics..."
curl -s http://localhost:8080/metrics | jq '.files.matched'
echo "Stopping app..."
kill $APP_PID
echo "Tests complete!"
EOF
chmod +x run-tests.sh
./run-tests.sh0- Success1- Error occurred
- Webhook Testing Guide - Comprehensive testing guide
- Local Testing - Local development
- Test Payloads - Example payloads