diff --git a/.changeset/fuzzy-pigs-wash.md b/.changeset/fuzzy-pigs-wash.md new file mode 100644 index 0000000000..d4a0ce4602 --- /dev/null +++ b/.changeset/fuzzy-pigs-wash.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Update to properly handle Azure DevOps Server download URL diff --git a/packages/integration/src/azure/core.test.ts b/packages/integration/src/azure/core.test.ts index 9937008b61..37fe50f3ea 100644 --- a/packages/integration/src/azure/core.test.ts +++ b/packages/integration/src/azure/core.test.ts @@ -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); + }); }); }); diff --git a/packages/integration/src/azure/core.ts b/packages/integration/src/azure/core.ts index 18de5aa1d2..e22764f643 100644 --- a/packages/integration/src/azure/core.ts +++ b/packages/integration/src/azure/core.ts @@ -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}`; } /**