The webhook has been enhanced to fix the 504 timeout issues:
- Added Comprehensive Logging: All requests now have detailed logging with request IDs for easy tracking
- Added Timeout Handling: HTTP requests now have 10-second timeouts to prevent hanging
- Added Retry Logic: Automatic retry for failed requests with exponential backoff
- Enhanced Error Handling: Better error handling and reporting for debugging
- Improved Health Check: More detailed health check with GitHub API connectivity test
- Request Tracking: Each request gets a unique ID for easier debugging
pip install -r requirements.txtCreate a custom.conf file or set environment variables:
Option A: Configuration File
cp custom.conf.template custom.conf
# Edit custom.conf with your GitHub credentials and label requirementsOption B: Environment Variables
export GITHUB_TOKEN="your_github_token"
export REQUIRED_LABELS_ANY="bug,feature,enhancement"
export REQUIRED_LABELS_ALL="reviewed"
export BANNED_LABELS="wip,draft"# For development
python main.py
# For production with gunicorn
gunicorn main:app --bind 0.0.0.0:5000 --timeout 30 --workers 2# Test with the provided test script
python test_webhook.py
# Or test a specific URL
python test_webhook.py http://your-app-url.comcurl http://localhost:5000/healthcurl http://localhost:5000/configcurl -X POST http://localhost:5000/ \
-H "Content-Type: application/json" \
-d '{
"action": "opened",
"pull_request": {
"issue_url": "https://api.github.com/repos/owner/repo/issues/123",
"statuses_url": "https://api.github.com/repos/owner/repo/statuses/abc123"
}
}'Logs are written to stdout and to webhook.log (if not on Heroku):
tail -f webhook.log[req_XXXXXX]- Each request has a unique IDResponse Time: XXXms- Monitor response timesStatus API response: XXX- GitHub API call resultsLabel validation result: True/False- Label check outcomes
504 Gateway Timeout
- Check if GitHub API is accessible
- Verify GitHub token has proper permissions
- Look for timeout errors in logs
Authentication Issues
- Verify GITHUB_TOKEN is set correctly
- Check token permissions (needs repo status access)
- Test with /health endpoint
Configuration Issues
- Use /config endpoint to verify settings
- Check label requirements are properly formatted
- Verify required environment variables are set
# Set environment variables
heroku config:set GITHUB_TOKEN=your_token
heroku config:set REQUIRED_LABELS_ANY=bug,feature
# Deploy
git push heroku mainFROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "main:app", "--bind", "0.0.0.0:5000", "--timeout", "30"]- Timeout Settings: Requests timeout after 10 seconds
- Retry Logic: Up to 3 retries with exponential backoff
- Connection Pooling: Reuses HTTP connections
- Error Handling: Graceful degradation on failures
import logging
logging.getLogger().setLevel(logging.DEBUG)curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/rate_limit- Go to your GitHub repo settings
- Navigate to Webhooks
- Check the "Recent Deliveries" section
- Look for failed deliveries and error messages
REQUIRED_LABELS_ANY="bug,feature,enhancement" # At least one required
REQUIRED_LABELS_ALL="reviewed,tested" # All required
BANNED_LABELS="wip,draft,do-not-merge" # None allowedGITHUB_STATUS_TEXT="Please add required labels"
GITHUB_STATUS_URL="https://your-docs.com/labeling-guide"If you're still experiencing 504 errors:
- Check the logs for specific error messages
- Test the /health endpoint to verify GitHub connectivity
- Run the test script to identify slow endpoints
- Verify your GitHub token has the necessary permissions
- Check if your deployment platform has timeout limits
The enhanced logging will help identify exactly where the timeouts are occurring.