feat: integrate tool with gitlab service (#39)

* feat: integrate tool with gitlab service

Fix https://github.com/lampajr/backporting/issues/30
This commit is contained in:
Andrea Lamparelli 2023-07-02 00:05:17 +02:00 committed by GitHub
parent 8a007941d1
commit 107f5e52d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 17821 additions and 1553 deletions

View file

@ -0,0 +1,56 @@
import GitClient from "@bp/service/git/git-client";
import { GitClientType } from "@bp/service/git/git.types";
import GitHubService from "@bp/service/git/github/github-client";
import LoggerService from "@bp/service/logger/logger-service";
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
import GitLabClient from "./gitlab/gitlab-client";
/**
* Singleton git service factory class
*/
export default class GitClientFactory {
private static logger: LoggerService = LoggerServiceFactory.getLogger();
private static instance?: GitClient;
public static getClient(): GitClient {
if (!GitClientFactory.instance) {
throw new Error("You must call `getOrCreate` method first!");
}
return GitClientFactory.instance;
}
/**
* Initialize the singleton git management service
* @param type git management service type
* @param authToken authentication token, like github/gitlab token
*/
public static getOrCreate(type: GitClientType, authToken: string, apiUrl: string): GitClient {
if (GitClientFactory.instance) {
GitClientFactory.logger.warn("Git service already initialized!");
return GitClientFactory.instance;
}
this.logger.debug(`Setting up ${type} client: apiUrl=${apiUrl}, token=****`);
switch(type) {
case GitClientType.GITHUB:
GitClientFactory.instance = new GitHubService(authToken, apiUrl);
break;
case GitClientType.GITLAB:
GitClientFactory.instance = new GitLabClient(authToken, apiUrl);
break;
default:
throw new Error(`Invalid git service type received: ${type}`);
}
return GitClientFactory.instance;
}
public static reset(): void {
GitClientFactory.logger.warn("Resetting git service!");
GitClientFactory.instance = undefined;
}
}