Properly handle Azure DevOps Server download URL

Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
Andre Wanlin
2021-08-31 10:55:37 -05:00
parent 897c66ca8b
commit 5dca42b174
3 changed files with 31 additions and 1 deletions
+5
View File
@@ -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);
});
});
});
+11 -1
View File
@@ -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}`;
}
/**