devtrack icon indicating copy to clipboard operation
devtrack copied to clipboard

[FEAT] Add real-time metric updates via GitHub webhooks

Open Priyanshu-byte-coder opened this issue 6 months ago • 6 comments

Summary

Instead of users manually refreshing the dashboard, configure a GitHub webhook so push events instantly trigger metric cache invalidation and the dashboard auto-refreshes.

Motivation

Currently metrics show stale data until the user clicks refresh. A webhook makes DevTrack feel live.

Architecture

GitHub push event → POST /api/webhooks/github → invalidate cache → broadcast via Server-Sent Events → client refreshes widget

Acceptance Criteria

  • [ ] New endpoint: POST /api/webhooks/github — validates HMAC-SHA256 signature (X-Hub-Signature-256)
  • [ ] Handles push event: extracts repo and username, marks that user's metrics as stale
  • [ ] New endpoint: GET /api/metrics/events — Server-Sent Events stream per authenticated user
  • [ ] Dashboard widgets subscribe to SSE and re-fetch on invalidate event
  • [ ] Settings page: webhook setup instructions (URL + secret) for users to configure in their GitHub settings
  • [ ] Requires GITHUB_WEBHOOK_SECRET env var (document in .env.example)
  • [ ] Graceful degradation: if SSE not connected, polling fallback every 5 min

Security

  • HMAC validation is non-negotiable — reject any request without valid signature
  • Never expose the webhook secret to the client

Files to Touch

  • New: src/app/api/webhooks/github/route.ts
  • New: src/app/api/metrics/events/route.ts
  • src/app/dashboard/settings/page.tsx
  • .env.example

Priyanshu-byte-coder avatar May 16 '26 19:05 Priyanshu-byte-coder

Hi @Priyanshu-byte-coder , I’d like to work on this issue under GSSOC 26.

This looks like a really interesting backend/infrastructure feature, especially around webhooks, SSE, and real-time cache invalidation.

My approach would be to:

  • Implement POST /api/webhooks/github with proper HMAC-SHA256 signature validation using X-Hub-Signature-256
  • Handle GitHub push events and mark the corresponding user metrics/cache as stale
  • Create an SSE endpoint (GET /api/metrics/events) for real-time dashboard refresh events
  • Update dashboard widgets to listen for invalidate events and re-fetch data
  • Add webhook setup instructions and required environment variables documentation
  • Ensure graceful fallback polling if SSE is unavailable

I’ll also make sure the webhook secret remains server-side only and invalid requests are rejected securely.

Please assign this issue to me if it’s available. Thanks!

maria-453 avatar May 17 '26 17:05 maria-453

Hi @Priyanshu-byte-coder,

I would like to work on this issue.

Proposed implementation approach:

  • Add a secure GitHub webhook endpoint at: POST /api/webhooks/github

  • Validate incoming webhook requests using: X-Hub-Signature-256 with HMAC-SHA256 verification against GITHUB_WEBHOOK_SECRET

  • Handle GitHub push events by:

    • extracting repository + GitHub username
    • invalidating the corresponding cached dashboard metrics
    • marking affected metric groups as stale
  • Implement a Server-Sent Events endpoint at: GET /api/metrics/events

  • Use authenticated SSE streams so connected dashboard clients receive realtime invalidation events and automatically re-fetch updated metrics.

  • Add graceful degradation:

    • if SSE is unavailable/disconnected, dashboard falls back to polling every 5 minutes
  • Update the dashboard settings page with:

    • webhook setup instructions
    • webhook URL guidance
    • secret configuration guidance for GitHub repository settings
  • Add GITHUB_WEBHOOK_SECRET to .env.example

Additional focus areas:

  • secure signature verification
  • preventing unauthorized webhook execution
  • lightweight SSE connection management
  • proper cleanup of disconnected streams
  • minimal and maintainable cache invalidation logic
  • preserving existing dashboard behavior when realtime updates are unavailable

I’ll keep the implementation modular, production-safe, and aligned with the existing Next.js API architecture and caching flow.

Ridanshi avatar May 18 '26 07:05 Ridanshi

Hi @Priyanshu-byte-coder, I would like to work on this issue under GSSoC 2026. I’m interested in implementing the real-time metric updates feature using GitHub webhooks and would love to contribute to this enhancement. Please assign this issue to me. Thanks!

Aarya1402 avatar May 19 '26 06:05 Aarya1402

/assign

vaishnavi003-svg avatar Jun 30 '26 17:06 vaishnavi003-svg

Hey @maria-453 — this issue was assigned a while back with no recent activity. Unassigning so it's available for Hacktoberfest contributors. Still working on it? Comment and we'll reassign you.

Priyanshu-byte-coder avatar Oct 14 '26 18:10 Priyanshu-byte-coder

Assigned to @Priyanshu-byte-coder! You have 7 days to open a PR. No PR after 7 days = auto-unassigned so others can pick it up. Good luck!

github-actions[bot] avatar Oct 14 '26 18:10 github-actions[bot]