From 883b6e94176e024f1601a89257306a4e067deef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= Date: Wed, 18 Feb 2026 15:21:47 +0100 Subject: [PATCH] Provisioning: Fix repository URLs for generic git type (#118285) For generic git repositories (non-GitHub/GitLab/Bitbucket), remove the '/tree/{branch}' segment from URLs. Different git hosting platforms have different URL patterns, so we return just the base repository URL. Changes: - getRepoHrefForProvider: Return clean base URL for 'git' type - getBranchUrl: Return clean base URL for 'git' type instead of empty string - Updated test to expect base URL without /tree/ segment Example: Before: http://localhost:3001/owner/repo/tree/main After: http://localhost:3001/owner/repo Co-authored-by: Claude Sonnet 4.5 --- public/app/features/provisioning/components/utils/url.ts | 4 ++++ public/app/features/provisioning/utils/git.test.ts | 4 ++-- public/app/features/provisioning/utils/git.ts | 9 +++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/public/app/features/provisioning/components/utils/url.ts b/public/app/features/provisioning/components/utils/url.ts index 4675600044c..8a5b5316349 100644 --- a/public/app/features/provisioning/components/utils/url.ts +++ b/public/app/features/provisioning/components/utils/url.ts @@ -15,6 +15,10 @@ export const getBranchUrl = (baseUrl: string, branch: string, repoType?: string) return `${cleanBaseUrl}/-/tree/${branch}`; case 'bitbucket': return `${cleanBaseUrl}/src/${branch}`; + case 'git': + // Generic git repositories don't have a standard URL pattern for branches + // Just return the base URL without branch segment + return cleanBaseUrl; default: return ''; } diff --git a/public/app/features/provisioning/utils/git.test.ts b/public/app/features/provisioning/utils/git.test.ts index 05c0eef90ec..18c4b01dc0f 100644 --- a/public/app/features/provisioning/utils/git.test.ts +++ b/public/app/features/provisioning/utils/git.test.ts @@ -127,7 +127,7 @@ describe('buildRepoUrl', () => { ).toBe('https://bitbucket.org/workspace/repo/src/main'); }); - it('builds generic git href with tree segment', () => { + it('builds generic git href without tree segment', () => { expect( getRepoHrefForProvider( spec({ @@ -135,7 +135,7 @@ describe('buildRepoUrl', () => { git: { url: 'https://git.example.com/owner/repo.git', branch: 'main' }, }) ) - ).toBe('https://git.example.com/owner/repo/tree/main'); + ).toBe('https://git.example.com/owner/repo'); }); }); diff --git a/public/app/features/provisioning/utils/git.ts b/public/app/features/provisioning/utils/git.ts index 51c26239fbe..1e169601684 100644 --- a/public/app/features/provisioning/utils/git.ts +++ b/public/app/features/provisioning/utils/git.ts @@ -102,12 +102,9 @@ export const getRepoHrefForProvider = (spec?: RepositorySpec) => { path: spec.bitbucket?.path, }); case 'git': - return buildRepoUrl({ - baseUrl: spec.git?.url, - branch: spec.git?.branch, - providerSegments: ['tree'], - path: spec.git?.path, - }); + // Generic git repositories don't have a standard URL pattern + // Just return the base URL without branch/path segments + return spec.git?.url ? buildCleanBaseUrl(spec.git.url) : undefined; default: return undefined; }