Merge pull request #7017 from awanlin/topic/handle-azure-devops-server

Properly handle Azure DevOps Server download URL
This commit is contained in:
Fredrik Adelöw
2021-09-01 10:30:22 +02:00
committed by GitHub
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 (resource === '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}`;
}
/**