From 88d742eb83e002943c79e254941118e6392aa63a Mon Sep 17 00:00:00 2001 From: Jingchao Zhang Date: Mon, 28 Jun 2021 17:33:24 -0400 Subject: [PATCH] Download tar.gz archives for Gitlab Signed-off-by: Jingchao Zhang --- .changeset/gold-avocados-thank.md | 5 +++++ .../src/reading/GitlabUrlReader.test.ts | 16 ++++++++-------- .../src/reading/GitlabUrlReader.ts | 4 ++-- .../reading/__fixtures__/gitlab-archive.tar.gz | Bin 0 -> 257 bytes 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 .changeset/gold-avocados-thank.md create mode 100644 packages/backend-common/src/reading/__fixtures__/gitlab-archive.tar.gz diff --git a/.changeset/gold-avocados-thank.md b/.changeset/gold-avocados-thank.md new file mode 100644 index 0000000000..bd97499629 --- /dev/null +++ b/.changeset/gold-avocados-thank.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': patch +--- + +Download archives as compressed tar files for Gitlab to fix the readtree bug in TODO Plugin. diff --git a/packages/backend-common/src/reading/GitlabUrlReader.test.ts b/packages/backend-common/src/reading/GitlabUrlReader.test.ts index a76b898aaf..5ed151c5c2 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.test.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.test.ts @@ -182,7 +182,7 @@ describe('GitlabUrlReader', () => { describe('readTree', () => { const archiveBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.zip'), + path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.tar.gz'), ); const projectGitlabApiResponse = { @@ -205,7 +205,7 @@ describe('GitlabUrlReader', () => { beforeEach(() => { worker.use( rest.get( - 'https://gitlab.com/api/v4/projects/backstage%2Fmock/repository/archive.zip?sha=main', + 'https://gitlab.com/api/v4/projects/backstage%2Fmock/repository/archive?sha=main', (_, res, ctx) => res( ctx.status(200), @@ -283,7 +283,7 @@ describe('GitlabUrlReader', () => { }, ), rest.get( - 'https://gitlab.mycompany.com/api/v4/projects/backstage%2Fmock/repository/archive.zip?sha=main', + 'https://gitlab.mycompany.com/api/v4/projects/backstage%2Fmock/repository/archive?sha=main', (_, res, ctx) => res( ctx.status(200), @@ -306,8 +306,8 @@ describe('GitlabUrlReader', () => { const files = await response.files(); expect(files.length).toBe(2); - const mkDocsFile = await files[0].content(); - const indexMarkdownFile = await files[1].content(); + const indexMarkdownFile = await files[0].content(); + const mkDocsFile = await files[1].content(); expect(mkDocsFile.toString()).toBe('site_name: Test\n'); expect(indexMarkdownFile.toString()).toBe('# Test\n'); @@ -331,7 +331,7 @@ describe('GitlabUrlReader', () => { it('returns the wanted files from hosted gitlab', async () => { worker.use( rest.get( - 'https://gitlab.mycompany.com/backstage/mock/-/archive/main.zip', + 'https://gitlab.mycompany.com/backstage/mock/-/archive/main.tar.gz', (_, res, ctx) => res( ctx.status(200), @@ -454,7 +454,7 @@ describe('GitlabUrlReader', () => { describe('search', () => { const archiveBuffer = fs.readFileSync( - path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.zip'), + path.resolve('src', 'reading', '__fixtures__', 'gitlab-archive.tar.gz'), ); const projectGitlabApiResponse = { @@ -471,7 +471,7 @@ describe('GitlabUrlReader', () => { beforeEach(() => { worker.use( rest.get( - 'https://gitlab.com/api/v4/projects/backstage%2Fmock/repository/archive.zip?sha=main', + 'https://gitlab.com/api/v4/projects/backstage%2Fmock/repository/archive?sha=main', (_, res, ctx) => res( ctx.status(200), diff --git a/packages/backend-common/src/reading/GitlabUrlReader.ts b/packages/backend-common/src/reading/GitlabUrlReader.ts index 13764a5312..aa215aee47 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.ts @@ -139,7 +139,7 @@ export class GitlabUrlReader implements UrlReader { const archiveGitLabResponse = await fetch( `${this.integration.config.apiBaseUrl}/projects/${encodeURIComponent( full_name, - )}/repository/archive.zip?sha=${branch}`, + )}/repository/archive?sha=${branch}`, getGitLabRequestOptions(this.integration.config), ); if (!archiveGitLabResponse.ok) { @@ -150,7 +150,7 @@ export class GitlabUrlReader implements UrlReader { throw new Error(message); } - return await this.deps.treeResponseFactory.fromZipArchive({ + return await this.deps.treeResponseFactory.fromTarArchive({ stream: (archiveGitLabResponse.body as unknown) as Readable, subpath: filepath, etag: commitSha, diff --git a/packages/backend-common/src/reading/__fixtures__/gitlab-archive.tar.gz b/packages/backend-common/src/reading/__fixtures__/gitlab-archive.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..c078e07e7e1255d7b6da4abe961aa8a79ac63781 GIT binary patch literal 257 zcmV+c0sj6UiwFP!000001MSt(YQiuS#_?SH6a}x>otSeH*mLY&VjJ3Qwu0@3?&+6` z2orG(YTelPqZg$&3H*DKD)wu?dhpw#j_=`7-2x>}M2Qi0)+#2_={bBqQkuzHCdaZ+ zq>U^{Wpb0R?O$$+ZuFnvNBy;={><#qe+rlS z$F>Z+yeY?8V+d@Suk?3H8^<=~H$tg@dQ1IjtPNcA&->4_=g{@Ddv62om> H04M+e6!wJ_ literal 0 HcmV?d00001