Conversation
Co-Authored-By: Adithyan <100783336+adithyanmkd@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📝 WalkthroughWalkthroughA new API endpoint for generating README files has been implemented. It validates GitHub URLs, fetches repository metadata and contents concurrently, constructs a detailed prompt for Gemini AI to generate comprehensive README documentation with sections for features, installation, and usage, and returns the generated markdown. Supporting library functions fetch repository contents via Octokit. Changes
Sequence DiagramsequenceDiagram
participant Client
participant APIRoute as API Route
participant GitHub as GitHub API
participant Gemini
Client->>APIRoute: POST /api/generate (GitHub URL)
APIRoute->>APIRoute: Validate & parse URL
par Concurrent Fetch
APIRoute->>GitHub: getRepoData(owner, repo)
APIRoute->>GitHub: getRepoContents(owner, repo)
end
GitHub-->>APIRoute: Metadata (stars, description, lang)
GitHub-->>APIRoute: Root files list
APIRoute->>APIRoute: Build root files string
APIRoute->>APIRoute: Construct README prompt
APIRoute->>Gemini: Generate content with model
Gemini-->>APIRoute: Generated markdown
APIRoute->>Client: JSON response with README
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@src/app/api/generate/route.ts`:
- Around line 48-51: The prompt template in route.ts interpolates
repoInfo?.language without a fallback, causing "null"/"undefined" to appear;
update the template where Primary Language is set (the block that uses Name:
${repo}, Description: ${repoInfo?.description || "A modern software project."},
Primary Language: ${repoInfo?.language}, Root Directory Files: ${fileList}) to
provide a safe default (e.g., ${repoInfo?.language || "Unknown"} or "Not
specified") so Primary Language never renders as null/undefined; keep the same
template variable names (repo, repoInfo, fileList) and only add the fallback
expression.
- Line 9: The req.json() call can throw on malformed JSON causing a 500; update
the handler to validate the request body before destructuring by reading the raw
body (e.g., await req.text()) and then JSON.parse it inside a try/catch, catch
SyntaxError and return a 400 response with a clear error message instead of
letting the outer catch produce a 500; specifically replace the line using const
{ url } = await req.json() with a safe-parse flow that assigns url only after
successful JSON.parse and handles parse failures by returning a 400 response.
- Around line 12-14: The current substring check on the incoming "url" is too
permissive; instead parse the string with the URL constructor inside the route
handler and validate the parsed hostname (e.g., allow "github.com" and
"www.github.com" only) before proceeding. In the function where "url" is read
(the route handler in src/app/api/generate/route.ts), wrap new URL(url) in a
try/catch to reject invalid URLs and then check urlObj.hostname === "github.com"
|| urlObj.hostname === "www.github.com"; if the check fails return the same
NextResponse.json({ error: "Please provide a valid GitHub URL" }, { status: 400
}). Ensure you trim the input before parsing to avoid whitespace tricks.
🧹 Nitpick comments (3)
src/lib/octokit.ts (1)
39-56: Consider adding an explicit return type to avoidanypropagation.The function returns
datafromrepos.getContent, which has a complex union type in Octokit. Without an explicit return type, consumers (likeroute.ts) receiveany[]and must define ad-hoc types likeRepoFile. Narrowing the return type here keeps the untyped surface contained in one place.♻️ Suggested improvement
-export async function getRepoContents(owner: string, repo: string) { +interface RepoContentItem { + name: string; + path: string; + type: string; +} + +export async function getRepoContents(owner: string, repo: string): Promise<RepoContentItem[]> { const client = getOctokit(); try { const { data } = await client.rest.repos.getContent({ owner, repo, path: "", // Root directory }); // Return the array of files/folders - return Array.isArray(data) ? data : []; + return Array.isArray(data) ? data.map(({ name, path, type }) => ({ name, path, type })) : []; } catch (error: unknown) { const message = error instanceof Error ? error.message : "Could not fetch contents"; console.error("Error fetching GitHub repo contents:", message); return []; } }src/app/api/generate/route.ts (2)
35-38: Inconsistent indentation —fileListblock is not indented.Lines 35–38 break the 4-space indentation used throughout the rest of the function body. This appears to be an accidental formatting issue.
Suggested fix
-const fileList = - repoContents.length > 0 - ? repoContents.map((f: RepoFile) => f.name).join(", ") - : "Standard repository structure"; + const fileList = + repoContents.length > 0 + ? repoContents.map((f: RepoFile) => f.name).join(", ") + : "Standard repository structure";
7-78: Consider adding rate limiting or request throttling for this endpoint.This route makes calls to both the GitHub API and Gemini API on every request. Without any rate limiting, it's susceptible to abuse that could exhaust API quotas or incur unexpected costs. Consider adding middleware-level rate limiting (e.g., via
next-rate-limit, Vercel's built-in rate limiting, or an upstream API gateway).
🚀 BΞYTΞFLʘW | Pull Request Protocol
PR Type: (Choose one:
feat|fix|refactor|docs|perf)Issue Link: Fixes #
📝 System Summary
Provide a concise brief of the changes introduced to the stream.
🛠️ Technical Changes
.........🧪 Quality Assurance (QA)
npm run buildexecuted without errors.🖼️ Visual Evidence
If this PR affects the UI, drop a screenshot or GIF below:
📡 Developer Authorization
Authorized by: @naheel0 @adithyanmkd
Timestamp: {{ 9/2/2026 }}