feat: add gitlab self managed check method

Signed-off-by: Minn Soe <contributions@minn.io>
This commit is contained in:
Minn Soe
2021-12-07 13:36:28 +00:00
parent 91b3ad3553
commit b61a5bbdf3
2 changed files with 35 additions and 0 deletions
@@ -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
@@ -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<PagedResponse<any>> {
if (options?.group) {
return this.pagedRequest(