feat(web): add GET /api/diff endpoint#1063
Conversation
Adds a new public API endpoint for retrieving structured diffs between two git refs. Includes OpenAPI documentation with descriptions for all request/response fields. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
This comment has been minimized.
This comment has been minimized.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds a new public GET /api/diff endpoint: OpenAPI docs and schemas, a Next.js API route, Zod request/response schemas, a service implementation that runs Changes
Sequence DiagramsequenceDiagram
participant Client
participant RouteHandler as API Route Handler
participant Service as getDiff Service
participant DB as Database
participant Git as Git Process
participant Parser as parse-diff
Client->>RouteHandler: GET /api/diff?repo=R&base=B&head=H
RouteHandler->>RouteHandler: Validate query (Zod)
alt invalid params
RouteHandler->>Client: 400 ServiceError
else
RouteHandler->>Service: getDiff({repo:R, base:B, head:H})
Service->>Service: Validate refs
alt invalid refs
Service->>RouteHandler: invalidGitRef error
RouteHandler->>Client: 400 ServiceError
else
Service->>DB: find repo by name/org
alt repo not found
Service->>RouteHandler: notFound error
RouteHandler->>Client: 404 ServiceError
else
Service->>Git: git diff B H (cwd repo)
Git->>Service: raw diff text / error
alt git error (bad/unknown rev)
Service->>RouteHandler: invalidGitRef error
RouteHandler->>Client: 400 ServiceError
else
Service->>Parser: parse raw diff
Parser->>Service: structured files & hunks
Service->>RouteHandler: GetDiffResult
RouteHandler->>Client: 200 JSON(GetDiffResult)
end
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/web/src/app/api/(server)/diff/route.ts (1)
8-12: Consider reusing the existing request schema.This local schema duplicates
getDiffRequestSchemafrom@/features/git/schemas.ts. Reusing the existing schema would ensure consistency and reduce maintenance burden.♻️ Proposed refactor
-import { z } from "zod"; +import { getDiffRequestSchema } from "@/features/git/schemas"; -const getDiffQueryParamsSchema = z.object({ - repo: z.string(), - base: z.string(), - head: z.string(), -}); +const getDiffQueryParamsSchema = getDiffRequestSchema;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web/src/app/api/`(server)/diff/route.ts around lines 8 - 12, The local duplicate schema getDiffQueryParamsSchema should be removed and the existing getDiffRequestSchema reused: import getDiffRequestSchema from the module that defines it, replace usages of getDiffQueryParamsSchema with getDiffRequestSchema (or derive from it if you only need a subset), and update any parsing/validation calls to call getDiffRequestSchema.parse(...) (or .partial/.pick if needed) so the code uses the single shared schema rather than duplicating validation logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/web/src/app/api/`(server)/diff/route.ts:
- Around line 8-12: The local duplicate schema getDiffQueryParamsSchema should
be removed and the existing getDiffRequestSchema reused: import
getDiffRequestSchema from the module that defines it, replace usages of
getDiffQueryParamsSchema with getDiffRequestSchema (or derive from it if you
only need a subset), and update any parsing/validation calls to call
getDiffRequestSchema.parse(...) (or .partial/.pick if needed) so the code uses
the single shared schema rather than duplicating validation logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 14fe17ce-9836-47ea-8387-f376e74fea20
📒 Files selected for processing (8)
CHANGELOG.mddocs/api-reference/sourcebot-public.openapi.jsonpackages/web/src/app/api/(server)/diff/route.tspackages/web/src/features/git/getDiffApi.tspackages/web/src/features/git/index.tspackages/web/src/features/git/schemas.tspackages/web/src/openapi/publicApiDocument.tspackages/web/src/openapi/publicApiSchemas.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/web/src/openapi/publicApiDocument.ts`:
- Around line 247-265: The new OpenAPI path registered via registry.registerPath
for path '/api/diff' is missing an operationId; add a unique operationId (e.g.,
'getDiff' or 'getDiffBetweenCommits') to the object passed into
registry.registerPath so it matches other endpoints and enables codegen and
clearer docs—update the registration for the '/api/diff' endpoint to include
operationId alongside method, path, tags, summary, request, and responses.
🪄 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
Run ID: 23d0f39d-5ed4-4c5a-b5a8-08854f01a31d
📒 Files selected for processing (3)
docs/api-reference/sourcebot-public.openapi.jsonpackages/web/src/openapi/publicApiDocument.tspackages/web/src/openapi/publicApiSchemas.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/api-reference/sourcebot-public.openapi.json
Summary
GET /api/diff?repo=...&base=...&head=...endpoint that returns a structured diff between two git refs using a two-dot comparisonoldPath/newPathand structured hunks witholdRange,newRange,heading, andbodyGittagCloses SOU-833
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation