forked from qodo-ai/pr-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Overview
Implement a universal webhook router that can automatically detect and route webhooks from multiple platforms to appropriate handlers.
Problem
When running a single webhook endpoint, we need to:
- Identify which platform sent the webhook
- Verify the signature using the correct method
- Parse the payload into typed models
- Route to appropriate handlers
Solution ✅ Implemented
Created pr_agent/webhooks/ module with:
Detection (router.py)
- Header-based detection (platform-specific headers)
- Payload structure analysis
- User-Agent inspection
- Confidence scoring for accuracy
Models (models.py)
WebhookSourceenum for all platformsWebhookHeadersnormalized header containerWebhookPayloaduniversal payload wrapper- Platform-specific
WebhookEventsubclasses
Supported Platforms
| Platform | Header Detection | Payload Detection | Signature Verification |
|---|---|---|---|
| GitHub | X-GitHub-Event, X-Hub-Signature-256 |
repository, sender |
HMAC SHA256 |
| Vercel | x-vercel-signature |
type, deploymentId |
HMAC SHA1 |
| Linear | Linear-Signature, Linear-Event |
type, action, data |
HMAC SHA256 |
| Slack | X-Slack-Signature |
team_id, api_app_id |
HMAC SHA256 |
| Discord | X-Signature-Ed25519 |
type (int), application_id |
Ed25519 |
| Gmail | - | Pub/Sub structure | - |
| Railway | User-Agent | deployment, service |
- |
Usage
from pr_agent.webhooks import WebhookRouter, WebhookSource
router = WebhookRouter()
router.set_secret(WebhookSource.GITHUB, "github_secret")
@router.on(WebhookSource.GITHUB)
async def handle_github(event):
print(f"GitHub: {event.event_type} on {event.repository}")
# In webhook endpoint:
event = await router.handle_webhook(headers, body, raw_body)Files
pr_agent/webhooks/__init__.pypr_agent/webhooks/models.pypr_agent/webhooks/router.py
Remaining Tasks
- Add FastAPI endpoint example
- Add tests for each platform detection
- Add confidence threshold configuration
- Add Notion webhook support
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request