mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Fix getGitPath to handle nested GitLab group paths (#13006)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
committed by
GitHub
parent
3432bbbb88
commit
c7ff560465
28
frontend/__tests__/utils/get-git-path.test.ts
Normal file
28
frontend/__tests__/utils/get-git-path.test.ts
Normal 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");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* If a repository is selected, returns /workspace/project/{repo-name}
|
* If a repository is selected, returns /workspace/project/{repo-name}
|
||||||
* Otherwise, returns /workspace/project
|
* 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
|
* @returns The git path to use
|
||||||
*/
|
*/
|
||||||
export function getGitPath(
|
export function getGitPath(
|
||||||
@@ -13,10 +13,10 @@ export function getGitPath(
|
|||||||
return "/workspace/project";
|
return "/workspace/project";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the repository name from "owner/repo" format
|
// Extract the repository name from the path
|
||||||
// The folder name is the second part after "/"
|
// The folder name is always the last part (handles both "owner/repo" and "group/subgroup/repo" formats)
|
||||||
const parts = selectedRepository.split("/");
|
const parts = selectedRepository.split("/");
|
||||||
const repoName = parts.length > 1 ? parts[1] : parts[0];
|
const repoName = parts[parts.length - 1];
|
||||||
|
|
||||||
return `/workspace/project/${repoName}`;
|
return `/workspace/project/${repoName}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user