From 3ac4522537266ec26d20e093ac0ca5ae25cf31dc Mon Sep 17 00:00:00 2001 From: qu Date: Wed, 11 May 2022 17:36:30 +0500 Subject: [PATCH 1/5] feat(catalog-backend-module-gitlab): create url location only if file exists (#12) Signed-off-by: Ruslan.Nasyrov --- .changeset/real-beers-type.md | 5 + .../src/GitLabDiscoveryProcessor.test.ts | 142 +++++++++++++++--- .../src/GitLabDiscoveryProcessor.ts | 22 ++- .../src/lib/client.ts | 30 ++++ 4 files changed, 175 insertions(+), 24 deletions(-) create mode 100644 .changeset/real-beers-type.md diff --git a/.changeset/real-beers-type.md b/.changeset/real-beers-type.md new file mode 100644 index 0000000000..106a97bffb --- /dev/null +++ b/.changeset/real-beers-type.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': patch +--- + +do not creating url location object if file with component definition do not exists in project, that decrease count of request to gitlab with 404 status code diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts index dc4ffb7251..3f4534ad48 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts @@ -24,26 +24,36 @@ import { GitLabProject } from './lib'; const server = setupServer(); -const PROJECTS_URL = 'https://gitlab.fake/api/v4/projects'; -const GROUP_PROJECTS_URL = - 'https://gitlab.fake/api/v4/groups/group%2Fsubgroup/projects'; +const DOMAIN = 'gitlab.fake'; +const SERVER_URL = `https://${DOMAIN}`; +const API_URL = `${SERVER_URL}/api/v4`; +const PROJECTS_URL = `${API_URL}/projects`; +const GROUP_PROJECTS_URL = `${API_URL}/groups/group%2Fsubgroup/projects`; const PROJECT_LOCATION: LocationSpec = { type: 'gitlab-discovery', - target: 'https://gitlab.fake/blob/*/catalog-info.yaml', + target: `${SERVER_URL}/blob/*/catalog-info.yaml`, }; const PROJECT_LOCATION_MASTER_BRANCH: LocationSpec = { type: 'gitlab-discovery', - target: 'https://gitlab.fake/blob/master/catalog-info.yaml', + target: `${SERVER_URL}/blob/master/catalog-info.yaml`, }; const GROUP_LOCATION: LocationSpec = { type: 'gitlab-discovery', - target: 'https://gitlab.fake/group/subgroup/blob/*/catalog-info.yaml', + target: `${SERVER_URL}/group/subgroup/blob/*/catalog-info.yaml`, +}; + +const GROUP_LOCATION_CUSTOM_BRANCH: LocationSpec = { + type: 'gitlab-discovery', + target: `${SERVER_URL}/group/subgroup/blob/test/catalog-info.yaml`, }; function setupFakeServer( url: string, - callback: (request: { page: number; include_subgroups: boolean }) => { + list_projects_callback: (request: { + page: number; + include_subgroups: boolean; + }) => { data: GitLabProject[]; nextPage?: number; }, @@ -55,7 +65,7 @@ function setupFakeServer( } const page = req.url.searchParams.get('page'); const include_subgroups = req.url.searchParams.get('include_subgroups'); - const response = callback({ + const response = list_projects_callback({ page: parseInt(page!, 10), include_subgroups: include_subgroups === 'true', }); @@ -75,6 +85,20 @@ function setupFakeServer( ctx.json(filteredData), ); }), + rest.head( + `${API_URL}/projects/:project_path/repository/files/:file_path`, + (req, res, ctx) => { + if (req.headers.get('private-token') !== 'test-token') { + return res(ctx.status(401), ctx.json({})); + } + const ref = req.url.searchParams.get('ref'); + + if (ref === 'main' || ref === 'master') { + return res(ctx.status(200)); + } + return res(ctx.status(404)); + }, + ), ); } @@ -86,8 +110,8 @@ function getConfig(): any { integrations: { gitlab: [ { - host: 'gitlab.fake', - apiBaseUrl: 'https://gitlab.fake/api/v4', + host: DOMAIN, + apiBaseUrl: API_URL, token: 'test-token', }, ], @@ -95,11 +119,18 @@ function getConfig(): any { }; } -function getProcessor(config?: any): GitLabDiscoveryProcessor { +function getProcessor({ + config, + options, +}: { + config?: any; + options?: Partial[1]>; +} = {}): GitLabDiscoveryProcessor { return GitLabDiscoveryProcessor.fromConfig( new ConfigReader(config || getConfig()), { logger: getVoidLogger(), + ...options, }, ); } @@ -163,6 +194,15 @@ describe('GitlabDiscoveryProcessor', () => { default_branch: 'main', last_activity_at: '2021-08-05T11:03:05.774Z', web_url: 'https://gitlab.fake/1', + path_with_namespace: '1', + }, + { + id: 2, + archived: false, + default_branch: 'main', + last_activity_at: '2021-08-05T11:03:05.774Z', + web_url: 'https://gitlab.fake/g/2', + path_with_namespace: 'g/2', }, ], nextPage: 2, @@ -170,26 +210,29 @@ describe('GitlabDiscoveryProcessor', () => { case 2: return { data: [ - { - id: 2, - archived: false, - default_branch: 'master', - last_activity_at: '2021-08-05T11:03:05.774Z', - web_url: 'https://gitlab.fake/2', - }, { id: 3, - archived: true, // ARCHIVED + archived: false, default_branch: 'master', last_activity_at: '2021-08-05T11:03:05.774Z', web_url: 'https://gitlab.fake/3', + path_with_namespace: '3', }, { id: 4, + archived: true, // ARCHIVED + default_branch: 'master', + last_activity_at: '2021-08-05T11:03:05.774Z', + web_url: 'https://gitlab.fake/4', + path_with_namespace: '4', + }, + { + id: 5, archived: false, default_branch: undefined, // MISSING DEFAULT BRANCH last_activity_at: '2021-08-05T11:03:05.774Z', - web_url: 'https://gitlab.fake/4', + web_url: 'https://gitlab.fake/g/5', + path_with_namespace: 'g/5', }, ], }; @@ -215,7 +258,15 @@ describe('GitlabDiscoveryProcessor', () => { type: 'location', location: { type: 'url', - target: 'https://gitlab.fake/2/-/blob/master/catalog-info.yaml', + target: 'https://gitlab.fake/g/2/-/blob/main/catalog-info.yaml', + presence: 'optional', + }, + }, + { + type: 'location', + location: { + type: 'url', + target: 'https://gitlab.fake/3/-/blob/master/catalog-info.yaml', presence: 'optional', }, }, @@ -235,6 +286,7 @@ describe('GitlabDiscoveryProcessor', () => { default_branch: 'main', last_activity_at: '2021-08-05T11:03:05.774Z', web_url: 'https://gitlab.fake/1', + path_with_namespace: '1', }, ], }; @@ -275,6 +327,7 @@ describe('GitlabDiscoveryProcessor', () => { default_branch: 'main', last_activity_at: '2021-08-05T11:03:05.774Z', web_url: 'https://gitlab.fake/1', + path_with_namespace: '1', }, ], }; @@ -291,6 +344,47 @@ describe('GitlabDiscoveryProcessor', () => { expect(result).toHaveLength(1); }); + it('can filter based on file existing', async () => { + const processor = getProcessor({ options: { checkFileExistence: true } }); + setupFakeServer(GROUP_PROJECTS_URL, request => { + if (!request.include_subgroups) { + throw new Error('include_subgroups should be set'); + } + switch (request.page) { + case 1: + return { + data: [ + { + id: 1, + archived: false, + default_branch: 'main', + last_activity_at: '2021-08-05T11:03:05.774Z', + web_url: 'https://gitlab.fake/1', + path_with_namespace: '1', + }, + { + id: 1, + archived: false, + default_branch: 'main', + last_activity_at: '2021-08-05T11:03:05.774Z', + web_url: 'https://gitlab.fake/g/2', + path_with_namespace: 'g/2', + }, + ], + }; + default: + throw new Error('Invalid request'); + } + }); + + const result: any[] = []; + await processor.readLocation(GROUP_LOCATION_CUSTOM_BRANCH, false, e => { + result.push(e); + }); + // If everything was set up correctly, we should have received the fake repo specified above + expect(result).toHaveLength(0); + }); + it('uses the previous scan timestamp to filter', async () => { const processor = getProcessor(); setupFakeServer(PROJECTS_URL, request => { @@ -304,6 +398,7 @@ describe('GitlabDiscoveryProcessor', () => { default_branch: 'main', last_activity_at: '2000-01-01T00:00:00Z', web_url: 'https://gitlab.fake/1', + path_with_namespace: '1', }, { id: 2, @@ -311,6 +406,7 @@ describe('GitlabDiscoveryProcessor', () => { default_branch: 'main', last_activity_at: '2002-01-01T00:00:00Z', web_url: 'https://gitlab.fake/2', + path_with_namespace: '2', }, ], }; @@ -349,7 +445,7 @@ describe('GitlabDiscoveryProcessor', () => { const config = getConfig(); config.integrations.gitlab[0].token = 'invalid'; await expect( - getProcessor(config).readLocation(PROJECT_LOCATION, false, _ => {}), + getProcessor({ config }).readLocation(PROJECT_LOCATION, false, _ => {}), ).rejects.toThrow(/Unauthorized/); }); @@ -357,7 +453,7 @@ describe('GitlabDiscoveryProcessor', () => { const config = getConfig(); delete config.integrations; await expect( - getProcessor(config).readLocation(PROJECT_LOCATION, false, _ => {}), + getProcessor({ config }).readLocation(PROJECT_LOCATION, false, _ => {}), ).rejects.toThrow(/no GitLab integration/); }); diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index 01de1f12a0..e5cb7b15db 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -41,8 +41,12 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { private readonly integrations: ScmIntegrationRegistry; private readonly logger: Logger; private readonly cache: CacheClient; + private readonly checkFileExistence: boolean; - static fromConfig(config: Config, options: { logger: Logger }) { + static fromConfig( + config: Config, + options: { logger: Logger; checkFileExistence?: boolean }, + ): GitLabDiscoveryProcessor { const integrations = ScmIntegrations.fromConfig(config); const pluginCache = CacheManager.fromConfig(config).forPlugin('gitlab-discovery'); @@ -58,10 +62,12 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { integrations: ScmIntegrationRegistry; pluginCache: PluginCacheManager; logger: Logger; + checkFileExistence?: boolean; }) { this.integrations = options.integrations; this.cache = options.pluginCache.getClient(); this.logger = options.logger; + this.checkFileExistence = options.checkFileExistence || false; } getProcessorName(): string { @@ -114,6 +120,20 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { continue; } + if (this.checkFileExistence) { + const project_branch = branch === '*' ? project.default_branch : branch; + + const projectHasFile: boolean = await client.hasFile( + project.path_with_namespace, + project_branch, + catalogPath, + ); + + if (!projectHasFile) { + continue; + } + } + res.matches.push(project); } diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.ts index 4d42f5e068..aa8eb22c19 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.ts @@ -63,6 +63,36 @@ export class GitLabClient { return this.pagedRequest(`/projects`, options); } + async hasFile( + projectPath: string, + branch: string, + filePath: string, + ): Promise { + const endpoint: string = `/projects/${encodeURIComponent( + projectPath, + )}/repository/files/${encodeURIComponent(filePath)}`; + const request = new URL(`${this.config.apiBaseUrl}${endpoint}`); + request.searchParams.append('ref', branch); + + this.logger.debug(`Fetching: ${request.toString()}`); + + const response = await fetch(request.toString(), { + headers: getGitLabRequestOptions(this.config).headers, + method: 'HEAD', + }); + + if (!response.ok) { + this.logger.debug( + `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${ + response.status + } - ${response.statusText}`, + ); + return false; + } + + return true; + } + /** * Performs a request against a given paginated GitLab endpoint. * From ba95c81bff16e2fc506148ddbf0858d7c30dd074 Mon Sep 17 00:00:00 2001 From: "Ruslan.Nasyrov" Date: Fri, 13 May 2022 14:55:05 +0500 Subject: [PATCH 2/5] feat/catalog-backend-module-gitlab: create url location only if file exists (fixes #1) Signed-off-by: Ruslan.Nasyrov --- .changeset/real-beers-type.md | 11 +++++++++- .../src/GitLabDiscoveryProcessor.test.ts | 20 +++++++++++++------ .../src/GitLabDiscoveryProcessor.ts | 11 +++++----- .../src/lib/client.ts | 7 ------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/.changeset/real-beers-type.md b/.changeset/real-beers-type.md index 106a97bffb..e3ab67cfca 100644 --- a/.changeset/real-beers-type.md +++ b/.changeset/real-beers-type.md @@ -2,4 +2,13 @@ '@backstage/plugin-catalog-backend-module-gitlab': patch --- -do not creating url location object if file with component definition do not exists in project, that decrease count of request to gitlab with 404 status code +do not create url location object if file with component definition do not exists in project, that decrease count of request to gitlab with 404 status code. Now we can create processor with new flag to enable this logic: + +```ts +const processor = GitLabDiscoveryProcessor.fromConfig(config, { + logger, + skipReposWithoutExactFileMatch: true, +}); +``` + +**WARNING:** This new functionality does not support globs in the repo filepath diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts index 3f4534ad48..278efe8036 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.test.ts @@ -29,6 +29,7 @@ const SERVER_URL = `https://${DOMAIN}`; const API_URL = `${SERVER_URL}/api/v4`; const PROJECTS_URL = `${API_URL}/projects`; const GROUP_PROJECTS_URL = `${API_URL}/groups/group%2Fsubgroup/projects`; +const EXISTING_PROJECT_PATH = 'exist'; const PROJECT_LOCATION: LocationSpec = { type: 'gitlab-discovery', @@ -50,7 +51,7 @@ const GROUP_LOCATION_CUSTOM_BRANCH: LocationSpec = { function setupFakeServer( url: string, - list_projects_callback: (request: { + listProjectsCallback: (request: { page: number; include_subgroups: boolean; }) => { @@ -65,7 +66,7 @@ function setupFakeServer( } const page = req.url.searchParams.get('page'); const include_subgroups = req.url.searchParams.get('include_subgroups'); - const response = list_projects_callback({ + const response = listProjectsCallback({ page: parseInt(page!, 10), include_subgroups: include_subgroups === 'true', }); @@ -96,6 +97,11 @@ function setupFakeServer( if (ref === 'main' || ref === 'master') { return res(ctx.status(200)); } + + if (EXISTING_PROJECT_PATH === req.params.project_path) { + return res(ctx.status(200)); + } + return res(ctx.status(404)); }, ), @@ -345,7 +351,9 @@ describe('GitlabDiscoveryProcessor', () => { }); it('can filter based on file existing', async () => { - const processor = getProcessor({ options: { checkFileExistence: true } }); + const processor = getProcessor({ + options: { skipReposWithoutExactFileMatch: true }, + }); setupFakeServer(GROUP_PROJECTS_URL, request => { if (!request.include_subgroups) { throw new Error('include_subgroups should be set'); @@ -367,8 +375,8 @@ describe('GitlabDiscoveryProcessor', () => { archived: false, default_branch: 'main', last_activity_at: '2021-08-05T11:03:05.774Z', - web_url: 'https://gitlab.fake/g/2', - path_with_namespace: 'g/2', + web_url: `https://gitlab.fake/${EXISTING_PROJECT_PATH}`, + path_with_namespace: EXISTING_PROJECT_PATH, }, ], }; @@ -382,7 +390,7 @@ describe('GitlabDiscoveryProcessor', () => { result.push(e); }); // If everything was set up correctly, we should have received the fake repo specified above - expect(result).toHaveLength(0); + expect(result).toHaveLength(1); }); it('uses the previous scan timestamp to filter', async () => { diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index e5cb7b15db..73b8c52358 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -41,11 +41,11 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { private readonly integrations: ScmIntegrationRegistry; private readonly logger: Logger; private readonly cache: CacheClient; - private readonly checkFileExistence: boolean; + private readonly skipReposWithoutExactFileMatch: boolean; static fromConfig( config: Config, - options: { logger: Logger; checkFileExistence?: boolean }, + options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean }, ): GitLabDiscoveryProcessor { const integrations = ScmIntegrations.fromConfig(config); const pluginCache = @@ -62,12 +62,13 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { integrations: ScmIntegrationRegistry; pluginCache: PluginCacheManager; logger: Logger; - checkFileExistence?: boolean; + skipReposWithoutExactFileMatch?: boolean; }) { this.integrations = options.integrations; this.cache = options.pluginCache.getClient(); this.logger = options.logger; - this.checkFileExistence = options.checkFileExistence || false; + this.skipReposWithoutExactFileMatch = + options.skipReposWithoutExactFileMatch || false; } getProcessorName(): string { @@ -120,7 +121,7 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { continue; } - if (this.checkFileExistence) { + if (this.skipReposWithoutExactFileMatch) { const project_branch = branch === '*' ? project.default_branch : branch; const projectHasFile: boolean = await client.hasFile( diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.ts index aa8eb22c19..5c43db6e68 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.ts @@ -74,19 +74,12 @@ export class GitLabClient { const request = new URL(`${this.config.apiBaseUrl}${endpoint}`); request.searchParams.append('ref', branch); - this.logger.debug(`Fetching: ${request.toString()}`); - const response = await fetch(request.toString(), { headers: getGitLabRequestOptions(this.config).headers, method: 'HEAD', }); if (!response.ok) { - this.logger.debug( - `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${ - response.status - } - ${response.statusText}`, - ); return false; } From cf864e9e25489b5cdad46ab7849c68d67eff8a9f Mon Sep 17 00:00:00 2001 From: "Ruslan.Nasyrov" Date: Tue, 17 May 2022 13:43:00 +0500 Subject: [PATCH 3/5] feat/catalog-backend-module-gitlab: create url location only if file exists (fixes #2) Signed-off-by: Ruslan.Nasyrov --- .changeset/real-beers-type.md | 4 ++-- docs/integrations/gitlab/discovery.md | 5 ++++- plugins/catalog-backend-module-gitlab/api-report.md | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.changeset/real-beers-type.md b/.changeset/real-beers-type.md index e3ab67cfca..f09aafe007 100644 --- a/.changeset/real-beers-type.md +++ b/.changeset/real-beers-type.md @@ -2,7 +2,7 @@ '@backstage/plugin-catalog-backend-module-gitlab': patch --- -do not create url location object if file with component definition do not exists in project, that decrease count of request to gitlab with 404 status code. Now we can create processor with new flag to enable this logic: +do not create location object if file with component definition do not exists in project, that decrease count of request to gitlab with 404 status code. Now we can create processor with new flag to enable this logic: ```ts const processor = GitLabDiscoveryProcessor.fromConfig(config, { @@ -11,4 +11,4 @@ const processor = GitLabDiscoveryProcessor.fromConfig(config, { }); ``` -**WARNING:** This new functionality does not support globs in the repo filepath +**WARNING:** This new functionality does not support globs in the repo file path diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 8d805fa362..2ce4b59ca6 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -47,6 +47,9 @@ of your backend. ): Promise { const builder = await CatalogBuilder.create(env); + builder.addProcessor( -+ GitLabDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }) ++ GitLabDiscoveryProcessor.fromConfig(env.config, { ++ logger: env.logger, ++ skipReposWithoutExactFileMatch: true, ++ }) + ); ``` diff --git a/plugins/catalog-backend-module-gitlab/api-report.md b/plugins/catalog-backend-module-gitlab/api-report.md index ec10f80939..63e6fe7ccb 100644 --- a/plugins/catalog-backend-module-gitlab/api-report.md +++ b/plugins/catalog-backend-module-gitlab/api-report.md @@ -16,6 +16,7 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { config: Config, options: { logger: Logger; + skipReposWithoutExactFileMatch?: boolean; }, ): GitLabDiscoveryProcessor; // (undocumented) From 6f8dfe10713f089214651324f5460b9d2ca9f32a Mon Sep 17 00:00:00 2001 From: "Ruslan.Nasyrov" Date: Wed, 18 May 2022 15:04:19 +0500 Subject: [PATCH 4/5] feat/catalog-backend-module-gitlab: create url location only if file exists (fixes #3) Signed-off-by: Ruslan.Nasyrov --- docs/integrations/gitlab/discovery.md | 2 +- plugins/catalog-backend-module-gitlab/src/lib/client.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 2ce4b59ca6..5a5fdb1d92 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -49,7 +49,7 @@ of your backend. + builder.addProcessor( + GitLabDiscoveryProcessor.fromConfig(env.config, { + logger: env.logger, -+ skipReposWithoutExactFileMatch: true, ++ skipReposWithoutExactFileMatch: false, + }) + ); ``` diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.ts index 5c43db6e68..27214f3be8 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.ts @@ -80,6 +80,13 @@ export class GitLabClient { }); if (!response.ok) { + if (response.status >= 500) { + this.logger.debug( + `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${ + response.status + } - ${response.statusText}`, + ); + } return false; } From 30824042f103aee5ec4cdd2473d375a847ae71cf Mon Sep 17 00:00:00 2001 From: "Ruslan.Nasyrov" Date: Thu, 19 May 2022 11:11:02 +0500 Subject: [PATCH 5/5] feat/catalog-backend-module-gitlab: create url location only if file exists (fixes #4) Signed-off-by: Ruslan.Nasyrov --- docs/integrations/gitlab/discovery.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 5a5fdb1d92..3715b89920 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -47,9 +47,8 @@ of your backend. ): Promise { const builder = await CatalogBuilder.create(env); + builder.addProcessor( -+ GitLabDiscoveryProcessor.fromConfig(env.config, { -+ logger: env.logger, -+ skipReposWithoutExactFileMatch: false, -+ }) ++ GitLabDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }) + ); ``` + +If you don't want create location object if file with component definition do not exists in project, you can set the `skipReposWithoutExactFileMatch` option. That can reduce count of request to gitlab with 404 status code.