mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-30 06:33:47 +00:00
feat(issue-32): override reviewers and assignees
This commit is contained in:
parent
ee692c3db4
commit
0d369dd612
18 changed files with 499 additions and 44 deletions
44
dist/cli/index.js
vendored
44
dist/cli/index.js
vendored
|
@ -30,6 +30,11 @@ runner.run();
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const commander_1 = __nccwpck_require__(4379);
|
||||
const package_json_1 = __nccwpck_require__(6625);
|
||||
function commaSeparatedList(value, _prev) {
|
||||
// remove all whitespaces
|
||||
const cleanedValue = value.trim();
|
||||
return cleanedValue !== "" ? cleanedValue.replace(/\s/g, "").split(",") : [];
|
||||
}
|
||||
class CLIArgsParser {
|
||||
getCommand() {
|
||||
return new commander_1.Command(package_json_1.name)
|
||||
|
@ -45,7 +50,10 @@ class CLIArgsParser {
|
|||
.option("--title <bp-title>", "backport pr title, default original pr title prefixed by target branch.", undefined)
|
||||
.option("--body <bp-body>", "backport pr title, default original pr body prefixed by bodyPrefix.", undefined)
|
||||
.option("--body-prefix <bp-body-prefix>", "backport pr body prefix, default `backport <original-pr-link>`.", undefined)
|
||||
.option("--bp-branch-name <bp-branch-name>", "backport pr branch name, default auto-generated by the commit.", undefined);
|
||||
.option("--bp-branch-name <bp-branch-name>", "backport pr branch name, default auto-generated by the commit.", undefined)
|
||||
.option("--reviewers <reviewers>", "comma separated list of reviewers for the backporting pull request.", commaSeparatedList, [])
|
||||
.option("--assignees <assignees>", "comma separated list of assignees for the backporting pull request.", commaSeparatedList, [])
|
||||
.option("--no-inherit-reviewers", "if provided and reviewers option is empty then inherit them from original pull request", true);
|
||||
}
|
||||
parse() {
|
||||
const opts = this.getCommand()
|
||||
|
@ -63,6 +71,9 @@ class CLIArgsParser {
|
|||
body: opts.body,
|
||||
bodyPrefix: opts.bodyPrefix,
|
||||
bpBranchName: opts.bpBranchName,
|
||||
reviewers: opts.reviewers,
|
||||
assignees: opts.assignees,
|
||||
inheritReviewers: opts.inheritReviewers,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -151,10 +162,13 @@ class PullRequestConfigsParser extends configs_parser_1.default {
|
|||
* @returns {GitPullRequest}
|
||||
*/
|
||||
getDefaultBackportPullRequest(originalPullRequest, args) {
|
||||
const reviewers = [];
|
||||
reviewers.push(originalPullRequest.author);
|
||||
if (originalPullRequest.mergedBy) {
|
||||
reviewers.push(originalPullRequest.mergedBy);
|
||||
const reviewers = args.reviewers ?? [];
|
||||
if (reviewers.length == 0 && args.inheritReviewers) {
|
||||
// inherit only if args.reviewers is empty and args.inheritReviewers set to true
|
||||
reviewers.push(originalPullRequest.author);
|
||||
if (originalPullRequest.mergedBy) {
|
||||
reviewers.push(originalPullRequest.mergedBy);
|
||||
}
|
||||
}
|
||||
const bodyPrefix = args.bodyPrefix ?? `**Backport:** ${originalPullRequest.htmlUrl}\r\n\r\n`;
|
||||
const body = args.body ?? `${originalPullRequest.body}\r\n\r\nPowered by [BPer](https://github.com/lampajr/backporting).`;
|
||||
|
@ -163,6 +177,7 @@ class PullRequestConfigsParser extends configs_parser_1.default {
|
|||
title: args.title ?? `[${args.targetBranch}] ${originalPullRequest.title}`,
|
||||
body: `${bodyPrefix}${body}`,
|
||||
reviewers: [...new Set(reviewers)],
|
||||
assignees: [...new Set(args.assignees)],
|
||||
targetRepo: originalPullRequest.targetRepo,
|
||||
sourceRepo: originalPullRequest.targetRepo,
|
||||
branchName: args.bpBranchName,
|
||||
|
@ -382,6 +397,7 @@ class GitHubMapper {
|
|||
merged: pr.merged ?? false,
|
||||
mergedBy: pr.merged_by?.login,
|
||||
reviewers: pr.requested_reviewers.filter(r => "login" in r).map((r => r?.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],
|
||||
|
@ -453,13 +469,26 @@ class GitHubService {
|
|||
owner: backport.owner,
|
||||
repo: backport.repo,
|
||||
pull_number: data.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.number,
|
||||
assignees: backport.assignees,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
this.logger.error(`Error setting assignees: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// UTILS
|
||||
/**
|
||||
|
@ -686,7 +715,8 @@ class Runner {
|
|||
base: configs.targetBranch,
|
||||
title: backportPR.title,
|
||||
body: backportPR.body,
|
||||
reviewers: backportPR.reviewers
|
||||
reviewers: backportPR.reviewers,
|
||||
assignees: backportPR.assignees,
|
||||
};
|
||||
if (!configs.dryRun) {
|
||||
// 8. push the new branch to origin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue