mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-06-08 14:24:29 -04:00
feat: override backporting pr fields (#38)
* feat: override local git user config * feat(issue-32): override reviewers and assignees
This commit is contained in:
parent
22bec0c537
commit
a32e8cd34c
21 changed files with 671 additions and 107 deletions
|
@ -2,6 +2,7 @@ import LoggerService from "@bp/service/logger/logger-service";
|
|||
import LoggerServiceFactory from "@bp/service/logger/logger-service-factory";
|
||||
import simpleGit, { SimpleGit } from "simple-git";
|
||||
import fs from "fs";
|
||||
import { LocalGit } from "@bp/service/configs/configs.types";
|
||||
|
||||
/**
|
||||
* Command line git commands executor service
|
||||
|
@ -10,12 +11,12 @@ export default class GitCLIService {
|
|||
|
||||
private readonly logger: LoggerService;
|
||||
private readonly auth: string;
|
||||
private readonly author: string;
|
||||
private readonly gitData: LocalGit;
|
||||
|
||||
constructor(auth: string, author: string) {
|
||||
constructor(auth: string, gitData: LocalGit) {
|
||||
this.logger = LoggerServiceFactory.getLogger();
|
||||
this.auth = auth;
|
||||
this.author = author;
|
||||
this.gitData = gitData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,7 @@ export default class GitCLIService {
|
|||
*/
|
||||
private git(cwd?: string): SimpleGit {
|
||||
const gitConfig = { ...(cwd ? { baseDir: cwd } : {})};
|
||||
return simpleGit(gitConfig).addConfig("user.name", this.author).addConfig("user.email", "noreply@github.com");
|
||||
return simpleGit(gitConfig).addConfig("user.name", this.gitData.user).addConfig("user.email", this.gitData.email);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,8 +35,8 @@ export default class GitCLIService {
|
|||
* @param remoteURL remote link, e.g., https://github.com/lampajr/backporting-example.git
|
||||
*/
|
||||
private remoteWithAuth(remoteURL: string): string {
|
||||
if (this.auth && this.author) {
|
||||
return remoteURL.replace("://", `://${this.author}:${this.auth}@`);
|
||||
if (this.auth && this.gitData.user) {
|
||||
return remoteURL.replace("://", `://${this.gitData.user}:${this.auth}@`);
|
||||
}
|
||||
|
||||
// return remote as it is
|
||||
|
|
|
@ -9,6 +9,7 @@ export interface GitPullRequest {
|
|||
title: string,
|
||||
body: string,
|
||||
reviewers: string[],
|
||||
assignees: string[],
|
||||
targetRepo: GitRepository,
|
||||
sourceRepo: GitRepository,
|
||||
nCommits: number, // number of commits in the pr
|
||||
|
@ -30,6 +31,7 @@ export interface BackportPullRequest {
|
|||
title: string, // pr title
|
||||
body: string, // pr body
|
||||
reviewers: string[], // pr list of reviewers
|
||||
assignees: string[], // pr list of assignees
|
||||
branchName?: string,
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ export default class GitHubMapper {
|
|||
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),
|
||||
sourceRepo: {
|
||||
owner: pr.head.repo.full_name.split("/")[0],
|
||||
project: pr.head.repo.full_name.split("/")[1],
|
||||
|
|
|
@ -58,12 +58,25 @@ export default class GitHubService implements GitService {
|
|||
owner: backport.owner,
|
||||
repo: backport.repo,
|
||||
pull_number: (data as PullRequest).number,
|
||||
reviewers: backport.reviewers
|
||||
reviewers: backport.reviewers,
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error(`Error requesting reviewers: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (backport.assignees.length > 0) {
|
||||
try {
|
||||
await this.octokit.issues.addAssignees({
|
||||
owner: backport.owner,
|
||||
repo: backport.repo,
|
||||
issue_number: (data as PullRequest).number,
|
||||
assignees: backport.assignees,
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error(`Error setting assignees: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UTILS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue