feat(webhooks): add outbound webhook integrations for DevTrack activity alerts (#2525) - #3278
Open
sureshsuriya wants to merge 1 commit into
Conversation
…ty alerts (Priyanshu-byte-coder#2525) ## Summary Implements GitHub Issue Priyanshu-byte-coder#2525 - Outbound Webhook Integrations for DevTrack Activity Alerts. ## Changes ### New Events (Issue Priyanshu-byte-coder#2525 activity alerts) - streak.milestone_reached - fired on streak milestone (7, 30, 100 days, etc.) - goal.completed - fired when a weekly coding goal is completed - weekly_summary.ready - fired when the weekly coding summary is generated These are added alongside the existing 6 events and listed first in the UI. ### src/lib/webhooks.ts - Add ACTIVITY_ALERT_EVENTS constant with the three new event types - Add ActivityAlertEvent type - Add isActivityAlertEvent() validator - Add getActivityAlertEvents() helper - Add dispatchActivityAlert() async helper (fire-and-forget, error-isolated) - Fix Content-Type header to use per-webhook content_type column (defaults to application/json) - Add X-DevTrack-Version: 1 header to all outbound webhook requests - Fix misaligned indentation of redirect-check block ### src/app/api/webhooks/activity-alerts/route.ts (NEW) - POST: receives activity-alert trigger events from server-side callers (goal-sync, cron jobs, streak checks); validates event type and dispatches asynchronously via dispatchActivityAlert() - GET: returns the list of valid activity-alert event types (for discovery) - Requires authenticated session; rejects non-activity-alert events ### src/app/api/webhooks/custom/route.ts - Accept content_type field (stored in DB, used when dispatching) - Accept optional user-supplied secret_token (falls back to auto-generated) - Add streak.milestone_reached and weekly_summary.ready to valid events ### src/app/api/webhooks/custom/[id]/route.ts - Add streak.milestone_reached and weekly_summary.ready to valid events in the PATCH handler ### src/components/webhook/WebhookManager.tsx - Rewrite: Activity Alert events (Issue Priyanshu-byte-coder#2525) listed first with descriptions - Add Content-Type selector (application/json / x-www-form-urlencoded) - Add Secret Token input field with auto-generate fallback explanation - Add copy-to-clipboard button for revealed secret tokens - Rename heading to 'Outbound Webhooks' with clearer description - Group events into 'Activity Alerts' and 'Other Events' sections ### test/webhook-activity-alerts.test.ts (NEW - 36 tests) - ACTIVITY_ALERT_EVENTS constant validation - isActivityAlertEvent() - all three events, negatives, null/undefined, case - isValidWebhookEvent() - verifies new events accepted - getActivityAlertEvents() - list consistency - getAvailableEvents() - backwards-compat + new events present - signPayload() - determinism, uniqueness per payload/secret - dispatchActivityAlert() - no-op when no webhooks, supabase lookup, error isolation (DB failure does not throw), payload data injection - GET /api/webhooks/activity-alerts - returns event list ### test/webhooks.test.ts - Update event-count assertions from 6 to 8 (two new events added)
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Outbound Webhook Integrations for DevTrack Activity Alerts (Closes #2525).
This PR adds support for activity alert webhook events, introduces a dedicated activity alerts API, enhances outbound webhook configuration with customizable content types and secret tokens, improves the webhook management UI, and adds comprehensive test coverage.
Type of Change
What Changed
Added three new activity alert webhook events:
streak.milestone_reachedgoal.completedweekly_summary.readyAdded
dispatchActivityAlert()and activity alert helper utilities insrc/lib/webhooks.ts.Added new authenticated API endpoint:
POST /api/webhooks/activity-alertsGET /api/webhooks/activity-alertsEnhanced custom webhook creation and update APIs with:
content_typesecret_tokenUpdated the Webhook Manager UI with:
Added comprehensive tests for activity alerts and updated existing webhook tests.
How to Test
npm run lint npm run type-check npm run testExpected result:
Screenshots / Recordings
UI changes included. Screenshots will be added before review.
Checklist
npm run lintpasses locallynpm run type-check)Additional Context
Feature-specific tests pass successfully. The repository has pre-existing unrelated test failures on the current
mainbranch, and this PR does not introduce additional failures.