From b61a5bbdf320ac2cb02506b55566f0704056f1fb Mon Sep 17 00:00:00 2001 From: Minn Soe Date: Tue, 7 Dec 2021 13:36:28 +0000 Subject: [PATCH] feat: add gitlab self managed check method Signed-off-by: Minn Soe --- .../processors/gitlab/client.test.ts | 28 +++++++++++++++++++ .../src/ingestion/processors/gitlab/client.ts | 7 +++++ 2 files changed, 35 insertions(+) diff --git a/plugins/catalog-backend/src/ingestion/processors/gitlab/client.test.ts b/plugins/catalog-backend/src/ingestion/processors/gitlab/client.test.ts index 92ee65e5e7..b249137740 100644 --- a/plugins/catalog-backend/src/ingestion/processors/gitlab/client.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/gitlab/client.test.ts @@ -104,6 +104,34 @@ function setupFakeInstanceProjectsEndpoint( } describe('GitLabClient', () => { + describe('isSelfManaged', () => { + it('returns true if self managed instance', () => { + const client = new GitLabClient({ + config: readGitLabIntegrationConfig( + new ConfigReader({ + host: 'example.com', + token: 'test-token', + apiBaseUrl: 'https://example.com/api/v4', + }), + ), + logger: getVoidLogger(), + }); + expect(client.isSelfManaged()).toBeTruthy(); + }); + it('returns false if gitlab.com', () => { + const client = new GitLabClient({ + config: readGitLabIntegrationConfig( + new ConfigReader({ + host: 'gitlab.com', + token: 'test-token', + }), + ), + logger: getVoidLogger(), + }); + expect(client.isSelfManaged()).toBeFalsy(); + }); + }); + describe('pagedRequest', () => { beforeEach(() => { // setup fake paginated endpoint with 4 pages each returning one item diff --git a/plugins/catalog-backend/src/ingestion/processors/gitlab/client.ts b/plugins/catalog-backend/src/ingestion/processors/gitlab/client.ts index 1df5ce962f..4d42f5e068 100644 --- a/plugins/catalog-backend/src/ingestion/processors/gitlab/client.ts +++ b/plugins/catalog-backend/src/ingestion/processors/gitlab/client.ts @@ -42,6 +42,13 @@ export class GitLabClient { this.logger = options.logger; } + /** + * Indicates whether the client is for a SaaS or self managed GitLab instance. + */ + isSelfManaged(): boolean { + return this.config.host !== 'gitlab.com'; + } + async listProjects(options?: ListOptions): Promise> { if (options?.group) { return this.pagedRequest(