Merge pull request #6252 from Jerry4013/jingchao/download-targz-archive-for-Gitlab

Download tar.gz archives for Gitlab
This commit is contained in:
Fredrik Adelöw
2021-06-29 14:42:50 +02:00
committed by GitHub
4 changed files with 15 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Download archives as compressed tar files for GitLab to fix the `readTree` bug in TODO Plugin.
@@ -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),
@@ -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,