Properly handle Azure DevOps Server download URL
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/integration': patch
|
||||
---
|
||||
|
||||
Update to properly handle Azure DevOps Server download URL
|
||||
@@ -97,5 +97,20 @@ describe('azure core', () => {
|
||||
);
|
||||
expect(new URL(result).searchParams.get('scopePath')).toEqual('docs');
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
url: 'https://dev.azure.com/org-name/project-name/_git/repo-name',
|
||||
result:
|
||||
'https://dev.azure.com/org-name/project-name/_apis/git/repositories/repo-name/items?recursionLevel=full&download=true&api-version=6.0',
|
||||
},
|
||||
{
|
||||
url: 'https://api.com/org-name/project-name/_git/repo-name',
|
||||
result:
|
||||
'https://api.com/org-name/project-name/_apis/git/repositories/repo-name/items?recursionLevel=full&download=true&api-version=6.0',
|
||||
},
|
||||
])('should handle happy path %#', async ({ url, result }) => {
|
||||
expect(getAzureDownloadUrl(url)).toBe(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,7 +100,17 @@ export function getAzureDownloadUrl(url: string): string {
|
||||
? `&scopePath=${encodeURIComponent(filepath)}`
|
||||
: '';
|
||||
|
||||
return `${protocol}://${resource}/${organization}/${project}/_apis/git/repositories/${repoName}/items?recursionLevel=full&download=true&api-version=6.0${scopePath}`;
|
||||
if (url.includes('dev.azure.com')) {
|
||||
return `${protocol}://${resource}/${organization}/${project}/_apis/git/repositories/${repoName}/items?recursionLevel=full&download=true&api-version=6.0${scopePath}`;
|
||||
}
|
||||
|
||||
// For Azure DevOps Server `parseGitUrl` returns the same values
|
||||
// for `organization` and `project` like this: `organization/project/_git`
|
||||
// so we drop `project` and then strip `/_git` from `organization`
|
||||
return `${protocol}://${resource}/${organization.replace(
|
||||
'/_git',
|
||||
'',
|
||||
)}/_apis/git/repositories/${repoName}/items?recursionLevel=full&download=true&api-version=6.0${scopePath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user