feat: add badge endpoint for shields.io#25
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a new Changes
Sequence DiagramsequenceDiagram
participant Client
participant Router as HTTP Router
participant Badge as BadgeHandler
participant Queries
participant DB as Database
Client->>Router: GET /v1/badge
Router->>Badge: Badge(w, r)
Badge->>Queries: GetInstanceCount(ctx)
Queries->>DB: SELECT COUNT(*) FROM instances
DB-->>Queries: count
Queries-->>Badge: count, error
Badge->>Badge: build shieldsio JSON (schema:1, label:"Active Instances", message:count)
Badge->>Router: write 200 + application/json + JSON body
Router-->>Client: 200 OK + badge JSON
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
badge_handler.go (1)
40-43: Log DB failures before returning 500.When
GetInstanceCountfails, adding a log at Line 40 makes this endpoint easier to operate and debug.🔧 Suggested patch
import ( "fmt" + "log/slog" "net/http" _ "embed" @@ if err != nil { + slog.Error("failed to get instance count", "error", err) w.WriteHeader(http.StatusInternalServerError) return }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@badge_handler.go` around lines 40 - 43, The handler that calls GetInstanceCount currently returns http.StatusInternalServerError on error without logging; update the error branch in the handler (the code surrounding the GetInstanceCount call) to log the error and context before w.WriteHeader(http.StatusInternalServerError) — include the error value and any identifying info (e.g., instanceID, params) using the existing logger (e.g., logger, log, or h.logger) so operators can debug failures to GetInstanceCount.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@main.go`:
- Around line 109-113: The inline HTTP handler registered with
router.Get("/robots.txt") (and any other inline handlers that call w.Write)
currently ignore the error return from w.Write; update these closures to capture
the returned error (err := w.Write(...)), check if err != nil, and handle it
(for example log the write failure with the request context and return early) so
failed writes to disconnected clients are not silently ignored; locate these in
the anonymous handler closures passed to router.Get and apply the same pattern
to any other inline handlers that write to the ResponseWriter.
---
Nitpick comments:
In `@badge_handler.go`:
- Around line 40-43: The handler that calls GetInstanceCount currently returns
http.StatusInternalServerError on error without logging; update the error branch
in the handler (the code surrounding the GetInstanceCount call) to log the error
and context before w.WriteHeader(http.StatusInternalServerError) — include the
error value and any identifying info (e.g., instanceID, params) using the
existing logger (e.g., logger, log, or h.logger) so operators can debug failures
to GetInstanceCount.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f218c775-52f3-4ad7-95e8-ae379fd50598
📒 Files selected for processing (5)
badge_handler.godashboard_handler.gomain.goqueries.sqlqueries/queries.sql.go
💤 Files with no reviewable changes (1)
- dashboard_handler.go
Summary by CodeRabbit
New Features
Documentation