Skip to content

feat(dashboard): add GET /api/dashboard endpoint for aggregated PR health summary#280

Open
ojaswa072 wants to merge 3 commits intoOWASP-BLT:mainfrom
ojaswa072:feat/dashboard-endpoint
Open

feat(dashboard): add GET /api/dashboard endpoint for aggregated PR health summary#280
ojaswa072 wants to merge 3 commits intoOWASP-BLT:mainfrom
ojaswa072:feat/dashboard-endpoint

Conversation

@ojaswa072
Copy link
Copy Markdown
Contributor

@ojaswa072 ojaswa072 commented Mar 10, 2026

Summary

Adds GET /api/dashboard — a single endpoint returning aggregated health metrics for all tracked PRs.

Problem

Getting a system-wide overview required multiple calls (/api/prs, /api/repos, /api/authors). This consolidates all key metrics into one response.

What it returns

  • Total PRs, merge-ready %, draft and stale PR counts
  • Readiness distribution (READY_TO_MERGE → UNANALYZED)
  • CI health breakdown (passing / failing / no checks)
  • Top 5 blocked repos and most active authors

Implementation

  • Zero GitHub API calls — purely aggregates existing D1 data
  • 4 optimized SQL queries with COALESCE and conditional aggregation
  • 60s cache with stale-while-revalidate=300

Files Changed

  • src/handlers.py — added handle_dashboard()
  • src/index.py — added import and GET /api/dashboard route

Summary by CodeRabbit

  • New Features
    • Added a dashboard API delivering comprehensive pull request health metrics: summary stats (counts and percentages), readiness distribution, CI health, top blocked repositories, most active authors, and last-updated timestamp. Responses include caching headers for improved performance and freshness.

@owasp-blt
Copy link
Copy Markdown

owasp-blt bot commented Mar 10, 2026

👋 Thanks for opening this pull request, @ojaswa072!

Before your PR is reviewed, please ensure:

  • Your code follows the project's coding style and guidelines.
  • You have written or updated tests for your changes.
  • The commit messages are clear and descriptive.
  • You have linked any relevant issues (e.g., Closes #123).

🔍 Our team will review your PR shortly. If you have questions, feel free to ask in the comments.

🚀 Keep up the great work! — OWASP BLT

@owasp-blt
Copy link
Copy Markdown

owasp-blt bot commented Mar 10, 2026

📊 Monthly Leaderboard

Hi @ojaswa072! Here's how you rank for March 2026:

Rank User Open PRs PRs (merged) PRs (closed) Reviews Comments Total
🥇 #1 @Nachiket-Roy 6 47 13 11 7 519
🥈 #2 @ojaswa072 15 30 0 0 1 317
#3 @e-esakman 2 26 0 7 4 305

Scoring this month (across OWASP-BLT org): Open PRs (+1 each), Merged PRs (+10), Closed (not merged) (−2), Reviews (+5; first two per PR in-month), Comments (+2, excludes CodeRabbit). Run /leaderboard on any issue or PR to see your rank!

@owasp-blt
Copy link
Copy Markdown

owasp-blt bot commented Mar 10, 2026

👋 Hi @ojaswa072!

This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:

  • The PR author
  • coderabbitai
  • copilot

Once a valid peer review is submitted, this check will pass automatically. Thank you!

⚠️ Peer review enforcement is active.

@github-actions
Copy link
Copy Markdown

🍃 PR Readiness Check

Check the readiness of this PR on Leaf:
👉 Open on Leaf

Leaf reviews pull requests for operational readiness, security risks, and production-impacting changes before they ship.

@github-actions github-actions bot added the files-changed: 2 PR changes 2 files label Mar 10, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 10, 2026

Warning

Rate limit exceeded

@ojaswa072 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f57d4014-0792-481f-b5cd-f9eadd6d705a

📥 Commits

Reviewing files that changed from the base of the PR and between 206a160 and 7a005ce.

📒 Files selected for processing (2)
  • src/handlers.py
  • src/index.py

Walkthrough

Added a new async dashboard endpoint GET /api/dashboard that aggregates PR health metrics from the database (summary counts, readiness distribution, CI status, top blocked repos, most active authors), returns a structured JSON payload with Cache-Control headers, and notifies Slack on errors.

Changes

Cohort / File(s) Summary
Dashboard handler
src/handlers.py
New async def handle_dashboard(env) added. Runs aggregated queries to compute: total PRs, merge_ready counts/percent, draft/stale counts, readiness distribution, CI health buckets, top blocked repositories, most active authors, and last_updated timestamp. Returns JSON with Content-Type and Cache-Control: public, max-age=60, stale-while-revalidate=300. Catches exceptions, sends Slack notification, and returns 500 on error.
Route registration
src/index.py
Imported and registered new GET /api/dashboard route delegating to handle_dashboard(env) without altering existing endpoints.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant API as Dashboard Handler
  participant DB as Database
  participant Slack

  Client->>API: GET /api/dashboard
  API->>DB: run aggregated queries (summary, readiness, CI, blocked repos, active authors)
  DB-->>API: query results
  API->>API: assemble JSON payload + Cache-Control headers
  API-->>Client: 200 OK with dashboard JSON

  alt error during processing
    API->>Slack: send error notification
    API-->>Client: 500 Internal Server Error (error payload)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

quality: medium

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding a GET /api/dashboard endpoint that provides aggregated PR health metrics. It is concise, specific, and clearly summarizes the primary contribution of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/handlers.py`:
- Around line 907-911: The exception handler in handle_dashboard currently
returns internal exception details to callers; keep the notify_slack_exception
call but replace the response body with a generic 500 JSON (e.g.,
{"error":"Internal server error"}) and appropriate headers/status using
Response.new instead of echoing type(e) and str(e); update the except block
around notify_slack_exception and Response.new to remove exception content while
preserving Slack reporting via notify_slack_exception(getattr(env,
'SLACK_ERROR_WEBHOOK', ''), e, context={'handler':'handle_dashboard'}).
- Around line 791-793: Add a new aggregation for PRs that only have skipped CI
checks so they aren't left out of the CI breakdown: create a COALESCE(SUM(...),
0) CASE that checks WHEN checks_skipped > 0 AND checks_passed = 0 AND
checks_failed = 0 THEN 1 ELSE 0 END and alias it (e.g., skipped_only), alongside
the existing has_ci_failures, all_ci_passing, and no_checks aggregates; update
any downstream uses of ci buckets/ci_health to include this new skipped_only
count.
- Line 794: The SQL compares TEXT ISO-8601 timestamps (last_updated_at) against
datetime('now','-30 days') lexicographically, causing incorrect stale_prs;
update the CASE expression to normalize last_updated_at into SQLite datetime (or
a numeric time like julianday) before comparing—for example convert/replace the
"T" and strip trailing "Z" or pass last_updated_at into datetime()/julianday so
the condition in COALESCE(SUM(CASE WHEN ... THEN 1 ELSE 0 END), 0) AS stale_prs)
uses datetime(replace(last_updated_at,'T',' ','...')) or
julianday(last_updated_at) < julianday('now','-30 days') to ensure chronological
comparison.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: OWASP-BLT/coderabbit/.coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b3a1eba1-b6d0-4d5f-a5ca-97289f210eb1

📥 Commits

Reviewing files that changed from the base of the PR and between ee8eb8a and dc01fe0.

📒 Files selected for processing (2)
  • src/handlers.py
  • src/index.py

COUNT(*) AS blocked_count
FROM prs
WHERE is_merged = 0 AND state = 'open'
AND blockers IS NOT NULL
Copy link
Copy Markdown
Contributor

@swaparup36 swaparup36 Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AND blockers IS NOT NULL - This line is redundant ig

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it looks like

@owasp-blt owasp-blt bot added has-peer-review PR has received peer review and removed needs-peer-review PR needs peer review labels Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants