mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-05-29 08:54:30 -04:00
feat(gh-85): take git tokens from environment (#88)
This commit is contained in:
parent
aac73bf7c5
commit
70da575afc
17 changed files with 456 additions and 24 deletions
|
@ -44,7 +44,7 @@ export default class GitClientFactory {
|
|||
GitClientFactory.instance = new GitLabClient(authToken, apiUrl);
|
||||
break;
|
||||
case GitClientType.CODEBERG:
|
||||
GitClientFactory.instance = new GitHubService(authToken, apiUrl);
|
||||
GitClientFactory.instance = new GitHubService(authToken, apiUrl, true);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid git service type received: ${type}`);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
||||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
||||
|
||||
/**
|
||||
* Git management service interface, which provides a common API for interacting
|
||||
|
@ -6,6 +6,11 @@ import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
|||
*/
|
||||
export default interface GitClient {
|
||||
|
||||
/**
|
||||
* @returns {GitClientType} specific git client enum type
|
||||
*/
|
||||
getClientType(): GitClientType
|
||||
|
||||
// READ
|
||||
|
||||
getDefaultGitUser(): string;
|
||||
|
|
|
@ -11,16 +11,22 @@ export default class GitHubClient implements GitClient {
|
|||
|
||||
private logger: LoggerService;
|
||||
private apiUrl: string;
|
||||
private isForCodeberg: boolean;
|
||||
private octokit: Octokit;
|
||||
private mapper: GitHubMapper;
|
||||
|
||||
constructor(token: string | undefined, apiUrl: string) {
|
||||
constructor(token: string | undefined, apiUrl: string, isForCodeberg = false) {
|
||||
this.apiUrl = apiUrl;
|
||||
this.isForCodeberg = isForCodeberg;
|
||||
this.logger = LoggerServiceFactory.getLogger();
|
||||
this.octokit = OctokitFactory.getOctokit(token, this.apiUrl);
|
||||
this.mapper = new GitHubMapper();
|
||||
}
|
||||
|
||||
getClientType(): GitClientType {
|
||||
return this.isForCodeberg ? GitClientType.CODEBERG : GitClientType.GITHUB;
|
||||
}
|
||||
|
||||
// READ
|
||||
|
||||
getDefaultGitUser(): string {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import LoggerService from "@bp/service/logger/logger-service";
|
||||
import GitClient from "@bp/service/git/git-client";
|
||||
import { GitPullRequest, BackportPullRequest } from "@bp/service/git/git.types";
|
||||
import { GitPullRequest, BackportPullRequest, GitClientType } from "@bp/service/git/git.types";
|
||||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||
import { CommitSchema, MergeRequestSchema, UserSchema } from "@gitbeaker/rest";
|
||||
import GitLabMapper from "@bp/service/git/gitlab/gitlab-mapper";
|
||||
|
@ -30,6 +30,10 @@ export default class GitLabClient implements GitClient {
|
|||
this.mapper = new GitLabMapper(this.client);
|
||||
}
|
||||
|
||||
getClientType(): GitClientType {
|
||||
return GitClientType.GITLAB;
|
||||
}
|
||||
|
||||
getDefaultGitUser(): string {
|
||||
return "Gitlab";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue