Skip to content

Conversation

@brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Jan 31, 2026

Re-orgs much of the git related apis into features/git.

Also Fixes #830

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed issue where files with a comma in their name would not render correctly in the file tree.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions

This comment has been minimized.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

Warning

Rate limit exceeded

@brendan-kellam has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 32 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.

Walkthrough

This pull request refactors Git-related APIs and types by consolidating them into a new @/features/git module, moving functionality previously scattered across @/features/fileTree and @/features/search. Import paths are updated across the codebase accordingly. A changelog entry documents a bug fix for files with commas in filenames.

Changes

Cohort / File(s) Summary
New Git Feature Module
packages/web/src/features/git/getFileSourceApi.ts, packages/web/src/features/git/getFilesApi.ts, packages/web/src/features/git/getFolderContentsApi.ts, packages/web/src/features/git/getTreeApi.ts, packages/web/src/features/git/types.ts, packages/web/src/features/git/utils.ts, packages/web/src/features/git/index.ts
New centralized APIs and types for file-tree and file-source operations, with request/response schemas, utility functions for path validation and tree building, and a barrel export consolidating the module's public surface.
Deleted Legacy Modules
packages/web/src/features/fileTree/api.ts, packages/web/src/features/fileTree/types.ts, packages/web/src/features/search/fileSourceApi.ts, packages/web/src/features/search/types.ts
Removed old APIs (getTree, getFiles, getFolderContents, getFileSource) and associated schemas/types that are now re-implemented in the new git module.
Import Updates — Browse Components
packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx, packages/web/src/app/[domain]/browse/[...path]/components/pureTreePreviewPanel.tsx, packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx, packages/web/src/app/[domain]/browse/components/fileTreeItemComponent.tsx, packages/web/src/app/[domain]/browse/components/fileTreeItemIcon.tsx, packages/web/src/app/[domain]/browse/components/fileTreePanel.tsx, packages/web/src/app/[domain]/browse/components/pureFileTreePanel.tsx, packages/web/src/app/[domain]/browse/layout.tsx, packages/web/src/app/[domain]/browse/components/fileSearchCommandDialog.tsx
Updated import paths to resolve FileTreeItem, FileTreeNode, getFileSource, getFolderContents, and getTree from the new @/features/git module instead of previous locations.
Import Updates — API Routes
packages/web/src/app/api/(server)/files/route.ts, packages/web/src/app/api/(server)/tree/route.ts, packages/web/src/app/api/(server)/source/route.ts, packages/web/src/app/api/(server)/commits/route.ts, packages/web/src/app/api/(client)/client.ts
Updated imports for getFiles, getTree, getFileSource, and related schemas to resolve from @/features/git instead of fileTree/search modules; consolidated type imports where applicable.
Import Updates — Features
packages/web/src/features/agents/review-agent/nodes/fetchFileContent.ts, packages/web/src/features/chat/agent.ts, packages/web/src/features/chat/tools.ts
Updated imports for getFileSource and FileSourceResponse to resolve from @/features/git.
Tests and Utilities
packages/web/src/features/git/listCommitsApi.test.ts, packages/web/src/features/git/utils.test.ts
Updated test module reference for listCommitsApi; added test case for empty file-tree handling.
Documentation
CHANGELOG.md
Added entry documenting bug fix for files with commas not rendering correctly in file tree (issue #831).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #739: Implements minimal-subtree loading using the same backend APIs (getTree, getFolderContents, getFiles) and utilities (normalizePath, buildFileTree, compareFileTreeItems) that are being consolidated into the git module here.
  • PR #829: Related to movement and reimplementation of getFileSource from search-based to git-based approach with git show logic.
  • PR #813: Updates callers of getFileSource function with refactored parameter names (path, repo, ref) that are part of this API consolidation.

Suggested labels

sourcebot-team

Suggested reviewers

  • msukkari
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR addresses issue #830 (filenames with commas rendering incorrectly) by reorganizing git APIs which likely resolves the underlying cause, though the mechanism is not explicitly documented in the code changes. Add explicit documentation or comments explaining how the API reorganization fixes the comma-in-filename rendering bug to clarify the connection between changes and the fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'chore(web): Reorganize git apis' accurately describes the primary change: moving git-related APIs from scattered feature modules into a centralized @/features/git module.
Out of Scope Changes check ✅ Passed All changes are in-scope, consistently focused on reorganizing git-related APIs from @/features/fileTree and @/features/search modules into a new @/features/git module with updated imports throughout.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bkellam/chore-git-api-reorg

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.

@claude
Copy link

claude bot commented Jan 31, 2026

Code Review

I found 3 issues where notFound is incorrectly imported from next/navigation instead of @/lib/serviceError. This will cause the functions to throw exceptions instead of returning proper ServiceError objects when repositories are not found.

Issues Found

  1. packages/web/src/features/git/getFilesApi.ts:6 - Incorrect notFound import
  2. packages/web/src/features/git/getFolderContentsApi.ts:6 - Incorrect notFound import
  3. packages/web/src/features/git/getTreeApi.ts:5 - Incorrect notFound import

The notFound() function from next/navigation throws an exception to trigger Next.js's 404 page rendering, while the one from @/lib/serviceError returns a ServiceError object.

Other files in this PR (getFileSourceApi.ts, listCommitsApi.ts) correctly import notFound from @/lib/serviceError.

Fix: Change from import { notFound } from 'next/navigation'; to import { unexpectedError, notFound } from '@/lib/serviceError'; and remove the separate next/navigation import line.

Reference:

import { detectLanguageFromFilename } from '@/lib/languageDetection';
import { ServiceError, notFound, fileNotFound, unexpectedError } from '@/lib/serviceError';
import { getCodeHostBrowseFileAtBranchUrl } from '@/lib/utils';
import { withOptionalAuthV2 } from '@/withAuthV2';
import { getRepoPath } from '@sourcebot/shared';
import simpleGit from 'simple-git';
import z from 'zod';
import { CodeHostType } from '@sourcebot/db';

Copy link
Contributor

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/web/src/features/git/utils.test.ts (1)

34-42: ⚠️ Potential issue | 🟡 Minor

Minor typo in test name.

The test name contains a grammatical error: "a empty" should be "an empty".

📝 Proposed fix
-test('buildFileTree handles a empty flat list', () => {
+test('buildFileTree handles an empty flat list', () => {
🤖 Fix all issues with AI agents
In `@packages/web/src/features/git/getFilesApi.ts`:
- Around line 6-31: The current getFiles function (and similar logic in
getTreeApi and getFolderContentsApi) calls Next.js's notFound() which throws and
results in a 500; instead import and return the service-error notFound value so
the handler returns a ServiceError with 404. Replace usage of next/navigation's
notFound() in getFiles (and the occurrences in getTreeApi and
getFolderContentsApi) with the service-error variant (import the notFound from
the service-error module) and return it (e.g., return notFound) rather than
calling the Next.js function that throws.

In `@packages/web/src/features/git/getFileSourceApi.ts`:
- Around line 45-88: The code resolves the effective git reference into gitRef
but still uses the original ref when building metadata (e.g., getBrowsePath's
revisionName and the returned branch property), causing drift when ref is
undefined; update usages to use the resolved gitRef instead of ref —
specifically pass gitRef into getBrowsePath's revisionName and set the returned
object's branch to gitRef (the other call getCodeHostBrowseFileAtBranchUrl
already uses gitRef for branchName), ensuring the response metadata matches the
actual file content.

In `@packages/web/src/features/git/getFolderContentsApi.ts`:
- Around line 61-64: The lines.map parsing in getFolderContentsApi.ts currently
assumes every `line` contains a comma; check `commaIndex` returned by
`line.indexOf(',')` and handle `-1` explicitly (e.g., skip the malformed line,
or throw/log an error) before computing `type` and `path`; ensure the resulting
`contents: FileTreeItem[]` excludes or marks malformed entries and preserves
proper parsing for valid lines.
- Around line 6-40: The getFolderContents flow uses notFound imported from
next/navigation which throws and gets wrapped into an unexpectedError by sew;
replace that import with the service-error version (import notFound from
'@/lib/serviceError') so calls to notFound inside getFolderContents (and any
early returns inside sew/withOptionalAuthV2) will produce a proper 404
ServiceError; update the top-level import statement and keep all existing uses
(e.g., the notFound() checks after repo lookup and isPathValid) unchanged so sew
will propagate the ServiceError rather than converting it to a 500.

In `@packages/web/src/features/git/getTreeApi.ts`:
- Around line 75-78: Guard against malformed git ls-tree lines in the mapping
that builds flatList: inside the lines.map callback that computes commaIndex,
type and path, check if commaIndex === -1 and handle explicitly (e.g., throw a
clear Error or skip the line with logging) so you don't create empty type or
malformed path values; update the mapping in getTreeApi (the lines.map lambda
that references commaIndex, type, path) to validate the comma and surface a
helpful message including the offending line when it fails.
- Around line 5-46: The getTree handler currently imports notFound from
'next/navigation' which, when thrown inside the sew(...) wrapper, is converted
into a 500; replace that import with the 404 variant from '@/lib/serviceError'
and ensure all uses inside the getTree function (and any other uses in this
file) call the service error notFound so the sew-wrapped API returns a proper
404; update the top-level import and keep calls like return notFound() in the
getTree flow (e.g., the repo existence check and path validation) to use the new
serviceError notFound.
🧹 Nitpick comments (1)
packages/web/src/app/api/(server)/tree/route.ts (1)

3-4: Consider using consistent import style.

getTree is imported from the direct module path while getTreeRequestSchema uses the barrel export. For consistency, both could be imported from @/features/git:

♻️ Proposed fix for consistent imports
-import { getTree } from "@/features/git/getTreeApi";
-import { getTreeRequestSchema } from "@/features/git";
+import { getTree, getTreeRequestSchema } from "@/features/git";

brendan-kellam and others added 3 commits January 30, 2026 21:22
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@brendan-kellam brendan-kellam merged commit 80dd075 into main Jan 31, 2026
9 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/chore-git-api-reorg branch January 31, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] filenames with a comma in them will render incorrectly in the file tree

2 participants