diff --git a/.changeset/tame-hotels-itch.md b/.changeset/tame-hotels-itch.md new file mode 100644 index 0000000000..2ae7b005a6 --- /dev/null +++ b/.changeset/tame-hotels-itch.md @@ -0,0 +1,6 @@ +--- +'@backstage/backend-common': patch +'@backstage/integration': patch +--- + +Download archives as compressed tar files for Bitbucket to keep executable permissions. diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts index e06122e04b..470f6e35b9 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts @@ -90,7 +90,7 @@ describe('BitbucketUrlReader', () => { 'src', 'reading', '__fixtures__', - 'bitbucket-repo-with-commit-hash.zip', + 'bitbucket-repo-with-commit-hash.tar.gz', ), ); @@ -99,7 +99,7 @@ describe('BitbucketUrlReader', () => { 'src', 'reading', '__fixtures__', - 'bitbucket-server-repo.zip', + 'bitbucket-server-repo.tar.gz', ), ); @@ -119,14 +119,14 @@ describe('BitbucketUrlReader', () => { ), ), rest.get( - 'https://bitbucket.org/backstage/mock/get/master.zip', + 'https://bitbucket.org/backstage/mock/get/master.tgz', (_, res, ctx) => res( ctx.status(200), ctx.set('Content-Type', 'application/zip'), ctx.set( 'content-disposition', - 'attachment; filename=backstage-mock-12ab34cd56ef.zip', + 'attachment; filename=backstage-mock-12ab34cd56ef.tgz', ), ctx.body(repoBuffer), ), @@ -142,14 +142,14 @@ describe('BitbucketUrlReader', () => { ), ), rest.get( - 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=zip&prefix=mock&path=docs', + 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&prefix=mock&path=docs', (_, res, ctx) => res( ctx.status(200), ctx.set('Content-Type', 'application/zip'), ctx.set( 'content-disposition', - 'attachment; filename=backstage-mock.zip', + 'attachment; filename=backstage-mock.tgz', ), ctx.body(privateBitbucketRepoBuffer), ), @@ -177,8 +177,8 @@ describe('BitbucketUrlReader', () => { const files = await response.files(); expect(files.length).toBe(2); - const indexMarkdownFile = await files[0].content(); - const mkDocsFile = await files[1].content(); + const mkDocsFile = await files[0].content(); + const indexMarkdownFile = await files[1].content(); expect(indexMarkdownFile.toString()).toBe('# Test\n'); expect(mkDocsFile.toString()).toBe('site_name: Test\n'); @@ -284,7 +284,7 @@ describe('BitbucketUrlReader', () => { 'src', 'reading', '__fixtures__', - 'bitbucket-repo-with-commit-hash.zip', + 'bitbucket-repo-with-commit-hash.tar.gz', ), ); @@ -304,14 +304,14 @@ describe('BitbucketUrlReader', () => { ), ), rest.get( - 'https://bitbucket.org/backstage/mock/get/master.zip', + 'https://bitbucket.org/backstage/mock/get/master.tgz', (_, res, ctx) => res( ctx.status(200), ctx.set('Content-Type', 'application/zip'), ctx.set( 'content-disposition', - 'attachment; filename=backstage-mock-12ab34cd56ef.zip', + 'attachment; filename=backstage-mock-12ab34cd56ef.tgz', ), ctx.body(repoBuffer), ), @@ -359,21 +359,21 @@ describe('BitbucketUrlReader', () => { 'src', 'reading', '__fixtures__', - 'bitbucket-server-repo.zip', + 'bitbucket-server-repo.tar.gz', ), ); beforeEach(() => { worker.use( rest.get( - 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=zip&prefix=mock&path=docs', + 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&prefix=mock&path=docs', (_, res, ctx) => res( ctx.status(200), ctx.set('Content-Type', 'application/zip'), ctx.set( 'content-disposition', - 'attachment; filename=backstage-mock.zip', + 'attachment; filename=backstage-mock.tgz', ), ctx.body(privateBitbucketRepoBuffer), ), diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.ts b/packages/backend-common/src/reading/BitbucketUrlReader.ts index 251743cb25..009b81bc28 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.ts @@ -126,7 +126,7 @@ export class BitbucketUrlReader implements UrlReader { throw new Error(message); } - return await this.deps.treeResponseFactory.fromZipArchive({ + return await this.deps.treeResponseFactory.fromTarArchive({ stream: (archiveBitbucketResponse.body as unknown) as Readable, subpath: filepath, etag: lastCommitShortHash, diff --git a/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.tar.gz b/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.tar.gz new file mode 100644 index 0000000000..24175a5e16 Binary files /dev/null and b/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.tar.gz differ diff --git a/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.zip b/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.zip deleted file mode 100644 index 135860afd3..0000000000 Binary files a/packages/backend-common/src/reading/__fixtures__/bitbucket-repo-with-commit-hash.zip and /dev/null differ diff --git a/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.tar.gz b/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.tar.gz new file mode 100644 index 0000000000..fba107dd51 Binary files /dev/null and b/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.tar.gz differ diff --git a/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.zip b/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.zip deleted file mode 100644 index be6b20d127..0000000000 Binary files a/packages/backend-common/src/reading/__fixtures__/bitbucket-server-repo.zip and /dev/null differ diff --git a/packages/integration/src/bitbucket/core.test.ts b/packages/integration/src/bitbucket/core.test.ts index 22b17d51fa..87236277a2 100644 --- a/packages/integration/src/bitbucket/core.test.ts +++ b/packages/integration/src/bitbucket/core.test.ts @@ -135,7 +135,7 @@ describe('bitbucket core', () => { config, ); expect(result).toEqual( - 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=zip&at=main&prefix=backstage-mock&path=docs', + 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&at=main&prefix=backstage-mock&path=docs', ); }); @@ -164,7 +164,7 @@ describe('bitbucket core', () => { ); expect(result).toEqual( - 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=zip&at=main&prefix=backstage-mock', + 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&at=main&prefix=backstage-mock', ); }); @@ -178,7 +178,7 @@ describe('bitbucket core', () => { config, ); expect(result).toEqual( - 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=zip&at=some-branch&prefix=backstage-mock&path=docs', + 'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&at=some-branch&prefix=backstage-mock&path=docs', ); }); @@ -192,7 +192,7 @@ describe('bitbucket core', () => { config, ); expect(result).toEqual( - 'https://bitbucket.org/backstage/mock/get/master.zip', + 'https://bitbucket.org/backstage/mock/get/master.tgz', ); }); }); diff --git a/packages/integration/src/bitbucket/core.ts b/packages/integration/src/bitbucket/core.ts index 8b1d7d6b18..825d656c7c 100644 --- a/packages/integration/src/bitbucket/core.ts +++ b/packages/integration/src/bitbucket/core.ts @@ -98,8 +98,8 @@ export async function getBitbucketDownloadUrl( // /docs/index.md will download the docs folder and everything below it const path = filepath ? `&path=${encodeURIComponent(filepath)}` : ''; const archiveUrl = isHosted - ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.zip` - : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=zip&at=${branch}&prefix=${project}-${repoName}${path}`; + ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tgz` + : `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`; return archiveUrl; }