Avoid double encoding in bitbucket integration

Signed-off-by: Namco <namco1992@gmail.com>
This commit is contained in:
Namco
2022-07-22 14:22:12 +08:00
parent 795a804111
commit c4b460a47d
3 changed files with 22 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/integration': patch
---
Avoid double encoding of the file path in `getBitbucketDownloadUrl`
@@ -139,6 +139,20 @@ describe('bitbucket core', () => {
);
});
it('does not double encode the filepath', async () => {
const config: BitbucketIntegrationConfig = {
host: 'bitbucket.mycompany.net',
apiBaseUrl: 'https://api.bitbucket.mycompany.net/rest/api/1.0',
};
const result = await getBitbucketDownloadUrl(
'https://bitbucket.mycompany.net/projects/backstage/repos/mock/browse/%2Fdocs?at=some-branch',
config,
);
expect(result).toEqual(
'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&at=some-branch&prefix=backstage-mock&path=%2Fdocs',
);
});
it('do not add path param if no path is specified for Bitbucket Server', async () => {
const defaultBranchResponse = {
displayId: 'main',
+3 -1
View File
@@ -100,7 +100,9 @@ export async function getBitbucketDownloadUrl(
// path will limit the downloaded content
// /docs will only download the docs folder and everything below it
// /docs/index.md will download the docs folder and everything below it
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : '';
const path = filepath
? `&path=${encodeURIComponent(decodeURIComponent(filepath))}`
: '';
const archiveUrl = isHosted
? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`
: `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;