Fix getGitPath to handle nested GitLab group paths (#13006)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
John-Mason P. Shackelford
2026-03-10 12:12:08 -04:00
committed by GitHub
parent 3432bbbb88
commit c7ff560465
2 changed files with 32 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
import { describe, it, expect } from "vitest";
import { getGitPath } from "#/utils/get-git-path";
describe("getGitPath", () => {
it("should return /workspace/project when no repository is selected", () => {
expect(getGitPath(null)).toBe("/workspace/project");
expect(getGitPath(undefined)).toBe("/workspace/project");
});
it("should handle standard owner/repo format (GitHub)", () => {
expect(getGitPath("OpenHands/OpenHands")).toBe("/workspace/project/OpenHands");
expect(getGitPath("facebook/react")).toBe("/workspace/project/react");
});
it("should handle nested group paths (GitLab)", () => {
expect(getGitPath("modernhealth/frontend-guild/pan")).toBe("/workspace/project/pan");
expect(getGitPath("group/subgroup/repo")).toBe("/workspace/project/repo");
expect(getGitPath("a/b/c/d/repo")).toBe("/workspace/project/repo");
});
it("should handle single segment paths", () => {
expect(getGitPath("repo")).toBe("/workspace/project/repo");
});
it("should handle empty string", () => {
expect(getGitPath("")).toBe("/workspace/project");
});
});

View File

@@ -3,7 +3,7 @@
* If a repository is selected, returns /workspace/project/{repo-name}
* Otherwise, returns /workspace/project
*
* @param selectedRepository The selected repository (e.g., "OpenHands/OpenHands" or "owner/repo")
* @param selectedRepository The selected repository (e.g., "OpenHands/OpenHands", "owner/repo", or "group/subgroup/repo")
* @returns The git path to use
*/
export function getGitPath(
@@ -13,10 +13,10 @@ export function getGitPath(
return "/workspace/project";
}
// Extract the repository name from "owner/repo" format
// The folder name is the second part after "/"
// Extract the repository name from the path
// The folder name is always the last part (handles both "owner/repo" and "group/subgroup/repo" formats)
const parts = selectedRepository.split("/");
const repoName = parts.length > 1 ? parts[1] : parts[0];
const repoName = parts[parts.length - 1];
return `/workspace/project/${repoName}`;
}