microsoft / microsoft/FluidFramework

Duplicate Code: GitRest route FS manager + soft-delete check

Open
#26,873 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.9k
Forks
586
Avg merge
1d 15h
Merged PRs (30d)
146

Description

🔍 Duplicate Code Detected: GitRest route FS manager + soft-delete check

Analysis of commit edf996f5e3b26fc2478218abdaee30e68b4af010

Assignee: @copilot

Summary

Several GitRest route handlers repeat the same multi-step block to:

  1. choose a filesystem manager factory (getFilesystemManagerFactory),
  2. create an fsManager rooted at repoManager.path, and
  3. await checkSoftDeleted(...) before performing the actual repo operation.

This is >10 lines per instance and appears repeatedly across multiple routes, increasing the risk of inconsistent future changes (e.g., changing soft-delete behavior, params, or ephemeral handling).

Duplication Details

Pattern: getFilesystemManagerFactory + fsManager.create(...) + checkSoftDeleted(...)
  • Severity: Medium

  • Occurrences: 15 (across 8 files)

  • Locations:

    • server/gitrest/packages/gitrest-base/src/routes/git/blobs.ts (lines 37-48, 67-78)
    • server/gitrest/packages/gitrest-base/src/routes/git/commits.ts (lines 40-51)
    • server/gitrest/packages/gitrest-base/src/routes/git/refs.ts (lines 48-59, 74-85, 107-118, 137-148, 167-178)
    • server/gitrest/packages/gitrest-base/src/routes/git/tags.ts (lines 40-51, 66-77)
    • server/gitrest/packages/gitrest-base/src/routes/git/trees.ts (lines 38-49, 64-75)
    • server/gitrest/packages/gitrest-base/src/routes/repository/commits.ts (lines 41-52)
    • server/gitrest/packages/gitrest-base/src/routes/repository/contents.ts (lines 33-44)
    • server/gitrest/packages/gitrest-base/src/routes/summaries.ts (lines 293-304)
  • Code Sample (from server/gitrest/packages/gitrest-base/src/routes/git/refs.ts):

    const fileSystemManagerFactory = getFilesystemManagerFactory(
    	fileSystemManagerFactories,
    	repoManagerParams.isEphemeralContainer ?? false,
    );
    const fsManager = fileSystemManagerFactory.create({
    	...repoManagerParams.fileSystemManagerParams,
    	rootDir: repoManager.path,
    });
    await checkSoftDeleted(
    	fsManager,
    	repoManager.path,
    	repoManagerParams,
    	repoPerDocEnabled,
    );
    

Impact Analysis

  • Maintainability: Any change to soft-delete enforcement, filesystem initialization, or routing params must be repeated in many route handlers.
  • Bug Risk: Higher chance of drift (some routes updated, others missed), especially across open(...) vs getRepoManagerFromWriteAPI(...) call sites.
  • Code Bloat: 15 near-identical blocks across related routes.

Refactoring Recommendations

  1. Extract a shared helper for “open repo + create fsManager + soft-delete check”

    • Suggested location: server/gitrest/packages/gitrest-base/src/utils (near existing checkSoftDeleted / filesystem helpers)
    • Shape idea: a helper that takes (repoManagerParams, repoPerDocEnabled, fileSystemManagerFactories, repoManagerFactory, openMode) and returns { repoManager, fsManager }.
    • Benefits: single place to adjust soft-delete behavior and fsManager creation.
  2. Optionally provide an inline wrapper to reduce boilerplate per route

    • Example: withRepoAndFsManager(repoManagerFactory, fileSystemManagerFactories, repoManagerParams, repoPerDocEnabled, async ({repoManager, fsManager}) => { ... })
    • Benefits: keeps route handlers focused on request-specific logic.

Implementation Checklist

  • Confirm intended behavior differences between repoManagerFactory.open(...) and getRepoManagerFromWriteAPI(...) and encode that in the helper API
  • Implement helper and migrate the 8 affected route modules
  • Ensure error handling (logAndThrowApiError) continues to include repoManagerParams
  • Run server/gitrest tests (if present) and validate endpoints

Analysis Metadata

  • Analyzed Files: 2,792 non-test .ts/.mjs/.cjs tracked files (excluded .d.ts, tests, and .github/workflows)
  • Detection Method: Serena-assisted semantic review + duplicate 12-line block detection
  • Commit: edf996f5e3b26fc2478218abdaee30e68b4af010
  • Analysis Date: 2026-03-28

Generated by Duplicate Code Detector ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with checkSoftDeleted and the filesystem helpers under server/gitrest/packages/gitrest-base/src/utils, then compare the repeated blocks in the eight listed route modules, especially repoManagerFactory.open(...) and getRepoManagerFromWriteAPI(...) call sites. Define and implement a shared helper that preserves their behavior, migrate all 15 occurrences, retain error context, and run the server/gitrest tests and endpoint validation if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.