From b570f78e22072a788d3fef8f18babd8ac9e27478 Mon Sep 17 00:00:00 2001 From: Sebastian Qvarfordt Date: Thu, 3 Dec 2020 16:24:29 +0100 Subject: [PATCH] Use resource instead of source when building github repo tar url (#3552) * Use resource instead of source when building github repo tar url * Changed the right part of the url... * Added test to make sure we include subdomains in githubs readtree * Fixed wopsie --- .../src/reading/GithubUrlReader.test.ts | 34 +++++++++++++++++++ .../src/reading/GithubUrlReader.ts | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/backend-common/src/reading/GithubUrlReader.test.ts b/packages/backend-common/src/reading/GithubUrlReader.test.ts index eb87d339ea..abe8b4f640 100644 --- a/packages/backend-common/src/reading/GithubUrlReader.test.ts +++ b/packages/backend-common/src/reading/GithubUrlReader.test.ts @@ -235,6 +235,40 @@ describe('GithubUrlReader', () => { expect(indexMarkdownFile.toString()).toBe('# Test\n'); }); + it('includes the subdomain in the github url', async () => { + worker.resetHandlers(); + worker.use( + rest.get( + 'https://ghe.github.com/backstage/mock/archive/repo.tar.gz', + (_, res, ctx) => + res( + ctx.status(200), + ctx.set('Content-Type', 'application/x-gzip'), + ctx.body(repoBuffer), + ), + ), + ); + + const processor = new GithubUrlReader( + { + host: 'ghe.github.com', + apiBaseUrl: 'https://api.github.com', + }, + { treeResponseFactory }, + ); + + const response = await processor.readTree( + 'https://ghe.github.com/backstage/mock/tree/repo/docs', + ); + + const files = await response.files(); + + expect(files.length).toBe(1); + const indexMarkdownFile = await files[0].content(); + + expect(indexMarkdownFile.toString()).toBe('# Test\n'); + }); + it('must specify a branch', async () => { const processor = new GithubUrlReader( { diff --git a/packages/backend-common/src/reading/GithubUrlReader.ts b/packages/backend-common/src/reading/GithubUrlReader.ts index 907f2ada7a..692a3c6dd8 100644 --- a/packages/backend-common/src/reading/GithubUrlReader.ts +++ b/packages/backend-common/src/reading/GithubUrlReader.ts @@ -179,7 +179,7 @@ export class GithubUrlReader implements UrlReader { name: repoName, ref, protocol, - source, + resource, full_name, filepath, } = parseGitUri(url); @@ -194,7 +194,7 @@ export class GithubUrlReader implements UrlReader { // TODO(Rugvip): use API to fetch URL instead const response = await fetch( new URL( - `${protocol}://${source}/${full_name}/archive/${ref}.tar.gz`, + `${protocol}://${resource}/${full_name}/archive/${ref}.tar.gz`, ).toString(), ); if (!response.ok) {