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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds a new public GET /api/diff endpoint with OpenAPI docs, Zod request/response schemas, a Next.js API route, a service implementation that runs Changes
Sequence DiagramsequenceDiagram
participant Client
participant RouteHandler as API Route Handler
participant ServiceLayer as getDiff Service
participant Database 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 params valid
RouteHandler->>ServiceLayer: getDiff({repo:R, base:B, head:H})
ServiceLayer->>ServiceLayer: Validate refs
alt invalid refs
ServiceLayer->>RouteHandler: invalidGitRef error
RouteHandler->>Client: 400 ServiceError
else refs valid
ServiceLayer->>Database: find repo by name/org
alt repo not found
ServiceLayer->>RouteHandler: notFound error
RouteHandler->>Client: 404 ServiceError
else repo found
ServiceLayer->>Git: git diff B H (cwd repo)
Git->>ServiceLayer: raw diff text / error
alt git error (bad/unknown rev)
ServiceLayer->>RouteHandler: invalidGitRef error
RouteHandler->>Client: 400 ServiceError
else raw diff
ServiceLayer->>Parser: parse raw diff
Parser->>ServiceLayer: structured files & hunks
ServiceLayer->>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 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
| registry.registerPath({ | ||
| method: 'get', | ||
| path: '/api/diff', | ||
| tags: [gitTag.name], | ||
| summary: 'Get diff between two commits', | ||
| description: 'Returns a structured diff between two git refs (branches, tags, or commit SHAs) using a two-dot comparison. See [git-diff](https://git-scm.com/docs/git-diff) for details.', | ||
| request: { | ||
| query: publicGetDiffRequestSchema, | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| description: 'Structured diff between the two refs.', | ||
| content: jsonContent(publicGetDiffResponseSchema), | ||
| }, | ||
| 400: errorJson('Invalid query parameters or git ref.'), | ||
| 404: errorJson('Repository not found.'), | ||
| 500: errorJson('Unexpected diff failure.'), | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Missing operationId for the new endpoint.
All other endpoints in this file define an operationId (e.g., 'search', 'getFileSource', 'listFiles'), but this new endpoint is missing it. The operationId is important for OpenAPI code generation tools and improves API documentation clarity.
🔧 Proposed fix
registry.registerPath({
method: 'get',
path: '/api/diff',
+ operationId: 'getDiff',
tags: [gitTag.name],
summary: 'Get diff between two commits',📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| registry.registerPath({ | |
| method: 'get', | |
| path: '/api/diff', | |
| tags: [gitTag.name], | |
| summary: 'Get diff between two commits', | |
| description: 'Returns a structured diff between two git refs (branches, tags, or commit SHAs) using a two-dot comparison. See [git-diff](https://git-scm.com/docs/git-diff) for details.', | |
| request: { | |
| query: publicGetDiffRequestSchema, | |
| }, | |
| responses: { | |
| 200: { | |
| description: 'Structured diff between the two refs.', | |
| content: jsonContent(publicGetDiffResponseSchema), | |
| }, | |
| 400: errorJson('Invalid query parameters or git ref.'), | |
| 404: errorJson('Repository not found.'), | |
| 500: errorJson('Unexpected diff failure.'), | |
| }, | |
| }); | |
| registry.registerPath({ | |
| method: 'get', | |
| path: '/api/diff', | |
| operationId: 'getDiff', | |
| tags: [gitTag.name], | |
| summary: 'Get diff between two commits', | |
| description: 'Returns a structured diff between two git refs (branches, tags, or commit SHAs) using a two-dot comparison. See [git-diff](https://git-scm.com/docs/git-diff) for details.', | |
| request: { | |
| query: publicGetDiffRequestSchema, | |
| }, | |
| responses: { | |
| 200: { | |
| description: 'Structured diff between the two refs.', | |
| content: jsonContent(publicGetDiffResponseSchema), | |
| }, | |
| 400: errorJson('Invalid query parameters or git ref.'), | |
| 404: errorJson('Repository not found.'), | |
| 500: errorJson('Unexpected diff failure.'), | |
| }, | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/web/src/openapi/publicApiDocument.ts` around lines 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.
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, andbodyGittagTest plan
GET /api/diff?repo=<repo>&base=<ref>&head=<ref>and verify structured response/api/openapi.jsonincludes the new endpoint with descriptionsCloses SOU-833
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation