π OpenHands: AI-Driven Development
fix(frontend): link Azure DevOps repositories to their _git page (#18753)
Alona67e5752c30dc
diff --git a/__tests__/utils/git-and-task-utilities.test.ts b/__tests__/utils/git-and-task-utilities.test.tsindex d5a1856ba2..dfda1cf85b 100644--- a/__tests__/utils/git-and-task-utilities.test.ts+++ b/__tests__/utils/git-and-task-utilities.test.ts@@ -227,6 +227,47 @@ describe("constructRepositoryUrl", () => {).toBe("https://bitbucket.example.com/projects/PROJECT/repos/repo");});+ it("uses the _git layout for Azure DevOps", () => {+ expect(constructRepositoryUrl("azure_devops", "org/project/repo")).toBe(+ "https://dev.azure.com/org/project/_git/repo",+ );+ });++ it("percent-encodes Azure DevOps path segments such as a project with a space", () => {+ expect(constructRepositoryUrl("azure_devops", "org/Web Apps/repo")).toBe(+ "https://dev.azure.com/org/Web%20Apps/_git/repo",+ );+ });++ it("does not encode an already-encoded Azure DevOps name twice", () => {+ // Names parsed from a git remote URL keep its percent-encoding.+ expect(constructRepositoryUrl("azure_devops", "org/Web%20Apps/repo")).toBe(+ "https://dev.azure.com/org/Web%20Apps/_git/repo",+ );+ });++ it("encodes a stray % in an Azure DevOps name", () => {+ expect(constructRepositoryUrl("azure_devops", "org/100%/repo")).toBe(+ "https://dev.azure.com/org/100%25/_git/repo",+ );+ });++ it("uses a custom host for Azure DevOps", () => {+ expect(+ constructRepositoryUrl(+ "azure_devops",+ "org/project/repo",+ "ado.example.com",+ ),+ ).toBe("https://ado.example.com/org/project/_git/repo");+ });++ it("keeps the plain path for an Azure DevOps name without three parts", () => {+ expect(constructRepositoryUrl("azure_devops", "org/repo")).toBe(+ "https://dev.azure.com/org/repo",+ );+ });+it("leaves the repo segment undefined for a single-part Bitbucket Data Center name", () => {expect(constructRepositoryUrl(diff --git a/src/utils/utils.ts b/src/utils/utils.tsindex 0a3a9dc533..b0cba716ed 100644--- a/src/utils/utils.ts+++ b/src/utils/utils.ts@@ -250,6 +250,19 @@ export const constructPullRequestUrl = (}};+/**+ * Percent-encode one URL path segment. Names parsed from a remote URL arrive+ * encoded (`Web%20Apps`) while provider APIs return them raw (`Web Apps`), so+ * decode first to avoid encoding twice.+ */+const encodePathSegment = (segment: string): string => {+ try {+ return encodeURIComponent(decodeURIComponent(segment));+ } catch {+ return encodeURIComponent(segment);+ }+};+/*** Construct the repository URL for different providers* @param provider The git provider@@ -260,6 +273,7 @@ export const constructPullRequestUrl = (* constructRepositoryUrl("github", "owner/repo") // "https://github.com/owner/repo"* constructRepositoryUrl("gitlab", "owner/repo") // "https://gitlab.com/owner/repo"* constructRepositoryUrl("bitbucket", "owner/repo") // "https://bitbucket.org/owner/repo"+ * constructRepositoryUrl("azure_devops", "org/Web Apps/repo") // "https://dev.azure.com/org/Web%20Apps/_git/repo"*/export const constructRepositoryUrl = (provider: Provider,@@ -271,6 +285,14 @@ export const constructRepositoryUrl = (const [project, repo] = repositoryName.split("/");return `${baseUrl}/projects/${project}/repos/${repo}`;}+ if (provider === "azure_devops") {+ // Azure DevOps format: org/project/repo+ const parts = repositoryName.split("/");+ if (parts.length === 3) {+ const [org, project, repo] = parts.map(encodePathSegment);+ return `${baseUrl}/${org}/${project}/_git/${repo}`;+ }+ }return `${baseUrl}/${repositoryName}`;};