mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 21:53:47 +00:00
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:
parent
8a007941d1
commit
107f5e52d6
35 changed files with 17821 additions and 1553 deletions
56
src/service/git/git-client-factory.ts
Normal file
56
src/service/git/git-client-factory.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue