mirror of
https://github.com/grafana/grafana.git
synced 2026-02-18 18:20:52 -05:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
910624ecd2
commit
883b6e9417
3 changed files with 9 additions and 8 deletions
|
|
@ -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 '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue