mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 05:33:47 +00:00
feat: integrate with codeberg (#80)
This commit is contained in:
parent
eecbff34b7
commit
9f0fbc0b2f
11 changed files with 72 additions and 25 deletions
|
@ -43,6 +43,9 @@ export default class GitClientFactory {
|
|||
case GitClientType.GITLAB:
|
||||
GitClientFactory.instance = new GitLabClient(authToken, apiUrl);
|
||||
break;
|
||||
case GitClientType.CODEBERG:
|
||||
GitClientFactory.instance = new GitHubService(authToken, apiUrl);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid git service type received: ${type}`);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ export const inferGitClient = (prUrl: string): GitClientType => {
|
|||
return GitClientType.GITHUB;
|
||||
} else if (stdPrUrl.includes(GitClientType.GITLAB.toString())) {
|
||||
return GitClientType.GITLAB;
|
||||
} else if (stdPrUrl.includes(GitClientType.CODEBERG.toString())) {
|
||||
return GitClientType.CODEBERG;
|
||||
}
|
||||
|
||||
throw new Error(`Remote git service not recognized from pr url: ${prUrl}`);
|
||||
|
|
|
@ -41,6 +41,7 @@ export interface BackportPullRequest {
|
|||
export enum GitClientType {
|
||||
GITHUB = "github",
|
||||
GITLAB = "gitlab",
|
||||
CODEBERG = "codeberg",
|
||||
}
|
||||
|
||||
export enum GitRepoState {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import GitClient from "@bp/service/git/git-client";
|
||||
import { BackportPullRequest, GitPullRequest } from "@bp/service/git/git.types";
|
||||
import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/git/git.types";
|
||||
import GitHubMapper from "@bp/service/git/github/github-mapper";
|
||||
import OctokitFactory from "@bp/service/git/github/octokit-factory";
|
||||
import LoggerService from "@bp/service/logger/logger-service";
|
||||
|
@ -24,7 +24,7 @@ export default class GitHubClient implements GitClient {
|
|||
// READ
|
||||
|
||||
getDefaultGitUser(): string {
|
||||
return "GitHub";
|
||||
return this.apiUrl.includes(GitClientType.CODEBERG.toString()) ? "Codeberg" : "GitHub";
|
||||
}
|
||||
|
||||
getDefaultGitEmail(): string {
|
||||
|
|
|
@ -24,9 +24,9 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
|
|||
state: this.mapGitState(pr.state), // TODO fix using custom mapper
|
||||
merged: pr.merged ?? false,
|
||||
mergedBy: pr.merged_by?.login,
|
||||
reviewers: pr.requested_reviewers.filter(r => "login" in r).map((r => (r as User)?.login)),
|
||||
assignees: pr.assignees.filter(r => "login" in r).map(r => r.login),
|
||||
labels: pr.labels.map(l => l.name),
|
||||
reviewers: pr.requested_reviewers?.filter(r => "login" in r).map((r => (r as User)?.login)) ?? [],
|
||||
assignees: pr.assignees?.filter(r => "login" in r).map(r => r.login) ?? [],
|
||||
labels: pr.labels?.map(l => l.name) ?? [],
|
||||
sourceRepo: await this.mapSourceRepo(pr),
|
||||
targetRepo: await this.mapTargetRepo(pr),
|
||||
nCommits: pr.commits,
|
||||
|
|
|
@ -61,8 +61,8 @@ export default class Runner {
|
|||
|
||||
// 2. init git service
|
||||
const gitClientType: GitClientType = inferGitClient(args.pullRequest);
|
||||
// right now the apiVersion is set to v4
|
||||
const apiUrl = inferGitApiUrl(args.pullRequest);
|
||||
// the api version is ignored in case of github
|
||||
const apiUrl = inferGitApiUrl(args.pullRequest, gitClientType === GitClientType.CODEBERG ? "v1" : undefined);
|
||||
const gitApi: GitClient = GitClientFactory.getOrCreate(gitClientType, args.auth, apiUrl);
|
||||
|
||||
// 3. parse configs
|
||||
|
@ -112,7 +112,7 @@ export default class Runner {
|
|||
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
|
||||
configs.originalPullRequest.state === "open") {
|
||||
this.logger.debug("Fetching pull request remote..");
|
||||
const prefix = git.gitClientType === GitClientType.GITHUB ? "pull" : "merge-requests"; // default is for gitlab
|
||||
const prefix = git.gitClientType === GitClientType.GITLAB ? "merge-requests" : "pull" ; // default is for gitlab
|
||||
await git.gitCli.fetch(configs.folder, `${prefix}/${configs.originalPullRequest.number}/head:pr/${configs.originalPullRequest.number}`);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue