spatie/laravel-github-webhooks
Handle GitHub webhooks in Laravel with signature verification, automatic logging to the database, and easy job/event dispatching per webhook type. Configure handlers, queue processing, and access the webhook payload via a stored call model.
push, pull_request, issue_comment). It aligns well with Laravel’s job queue system (ShouldQueue), making it ideal for async processing of webhook payloads.HandleIssueOpenedWebhookJob). The package handles signature validation, payload parsing, and logging out-of-the-box.shouldProcess() in jobs or middleware hooks. Can extend GitHubWebhookCall model for domain-specific attributes.signed middleware for critical paths.sync jobs for critical paths.pull_request with many comments) may hit Laravel’s max_execution_time or queue job size limits. Test with edge cases..env). Rotation requires updating both GitHub and Laravel configs.push for CI/CD) vs. non-critical (e.g., watch events)? Should some bypass queues?push events)?database, single, stack). Can integrate with third-party loggers (e.g., Papertrail).HttpTests, JobTestingTraits). Supports mocking webhook payloads via Spatie\GitHubWebhooks\Testing\GitHubWebhooks.composer require spatie/laravel-github-webhooks
php artisan vendor:publish --provider="Spatie\GitHubWebhooks\GitHubWebhooksServiceProvider"
Configure .env with GITHUB_WEBHOOK_SECRET.routes/web.php:
Route::middleware(['github.webhook'])->post('/github/webhook', [GitHubWebhookHandler::class, 'handle']);
HandlePushWebhookJob). Annotate with @queue for async processing.GitHubWebhooks::fake() in tests to simulate webhooks:
GitHubWebhooks::fake()
->assertSent(fn (GitHubWebhookCall $call) => $call->event === 'push');
composer.json for LTS compatibility).push, pull_request). Test with GitHub’s webhook delivery service.spatie/laravel-github-webhooks for breaking changes (MIT license allows forks if needed). Updates are typically backward-compatible.GITHUB_WEBHOOK_SECRET in .env and regenerate GitHub webhook secrets. Use Laravel’s config:cache to avoid downtime.pull_request events). Test with GitHub’s webhook payload generator.GITHUB_WEBHOOK_SECRET matches GitHub’s configured secret. Check for typos or whitespace.failed_jobs table and implement dead-letter queues for persistent failures.dd($call->payload) in jobs to debug malformed data.queue:work --daemon for production.push in large repos), implement rate-limiting at the Laravel level (e.g., throttle middleware) or GitHub’s webhook delivery limits.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| GitHub webhook secret mismatch | All webhooks rejected | Automated secret rotation with CI/CD checks. |
| Queue worker crashes | Delayed/failed job processing | Use supervisor/PM2 to restart workers. Implement circuit breakers. |
| Database connection issues | Logging failures, job persistence | Use queue retries and dead-letter queues. Monitor database health. |
| Large payloads (e.g., 10MB+) | Job timeouts or memory limits | Increase max_execution_time or split payload processing. |
| GitHub rate-limiting | Webhook deliveries throttled | Monitor GitHub’s rate limits. |
| Laravel app downtime | Missed webhooks | Use GitHub’s "Active" webhook status and implement retry logic in jobs. |
How can I help you explore Laravel packages today?