Refactor to Spatie webhook client#3
Conversation
Replace custom WebhookController with Spatie's laravel-webhook-client package for better webhook handling: - Add spatie/laravel-webhook-client package - Create GateSignatureValidator for HMAC signature verification - Create GateWebhookProfile for payload validation - Create ProcessGateWebhookJob to fire CertificationCompleted events - Configure webhook-client.php for gate endpoint - Update routes to use Spatie's webhooks() macro - Update tests to verify new webhook flow - Add unit tests for GateSignatureValidator - Maintain 100% test coverage
|
Caution Review failedThe pull request is closed. WalkthroughThis pull request replaces a custom webhook handler with the Spatie WebhookClient library. The changes remove the existing WebhookController and GateWebhookRequest classes, introduce Spatie-based signature validation and webhook processing components, add a configuration file for webhook handling, create a database migration for webhook storage, and update routes and tests accordingly. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Router as API Router
participant SignatureValidator as GateSignatureValidator
participant WebhookProfile as GateWebhookProfile
participant ProcessJob as ProcessGateWebhookJob
participant Database as DB (webhook_calls)
participant Event as CertificationCompleted Event
Client->>Router: POST /api/webhooks/gate<br/>(with signature header)
Router->>SignatureValidator: isValid(request, config)
alt Signature invalid
SignatureValidator-->>Router: false
Router-->>Client: HTTP 403
else Signature valid
SignatureValidator-->>Router: true
Router->>WebhookProfile: shouldProcess(request)
alt Payload invalid
WebhookProfile-->>Router: false
Router-->>Client: HTTP 400
else Payload valid
WebhookProfile-->>Router: true
Router->>Database: Store webhook_calls record
Database-->>Router: ✓ Stored
Router->>ProcessJob: dispatch(webhook)
ProcessJob->>Event: fire CertificationCompleted<br/>(repository, sha, verdict, ...)
Event-->>ProcessJob: ✓ Dispatched
ProcessJob-->>Router: ✓ Complete
Router-->>Client: HTTP 202
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
spatie/laravel-webhook-clientpackageChanges
spatie/laravel-webhook-clientv3.4App\Webhooks\GateSignatureValidator- HMAC-SHA256 signature verificationApp\Webhooks\GateWebhookProfile- Payload validation (required fields, verdict enum)App\Webhooks\ProcessGateWebhookJob- Fires CertificationCompleted Verbs eventconfig/webhook-client.phpwith gate endpoint configurationwebhook_callstable for webhook storageWebhookControllerandGateWebhookRequestclassesTest plan
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.