Download tar.gz archives for Bitbucket

Signed-off-by: Mathias Åhsberg <mathias.ahsberg@resurs.se>
This commit is contained in:
Mathias Åhsberg
2021-06-04 12:46:42 +00:00
parent 18ddc1b318
commit eda9dbd5fa
9 changed files with 27 additions and 21 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/backend-common': patch
'@backstage/integration': patch
---
Download archives as compressed tar files for Bitbucket to keep executable permissions.
@@ -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),
),
@@ -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,
@@ -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',
);
});
});
+2 -2
View File
@@ -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;
}