From 3a2a0fced162dcceb954f3cc976ef64b313a4d5a Mon Sep 17 00:00:00 2001 From: jonathan keinan Date: Sun, 6 Oct 2024 11:02:50 +0300 Subject: [PATCH] * initial commit --- README.md | 6 ++++++ action.yml | 4 ++++ dist/index.js | 2 ++ src/backport.ts | 36 ++++++++++++++++++++---------------- src/main.ts | 2 ++ 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0f52cfe..9861170 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,12 @@ Controls whether to copy the requested reviewers from the original pull request Note that this does not request reviews from those users who already reviewed the original pull request. By default, the requested reviewers are not copied. +### `additional_reviewers` + +Default: `''` (disabled) + +Comma-separated list of GitHub usernames to add as reviewers to the backport pull request. + ### `experimental` Default: diff --git a/action.yml b/action.yml index 1f4cca8..1b1cc29 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,10 @@ inputs: Note that this does not request reviews from those users who already reviewed the original pull request. By default, the requested reviewers are not copied. default: false + additional_reviewers: + description: > + Comma-separated list of GitHub usernames to add as reviewers to the backport pull request. + By default, no additional reviewers are added. experimental: description: > Configure experimental features by passing a JSON object. diff --git a/dist/index.js b/dist/index.js index 3fe7a73..91f0963 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1079,6 +1079,7 @@ function run() { const copy_assignees = core.getInput("copy_assignees"); const copy_milestone = core.getInput("copy_milestone"); const copy_requested_reviewers = core.getInput("copy_requested_reviewers"); + const additional_reviewers = core.getInput("additional_reviewers"); const experimental = JSON.parse(core.getInput("experimental")); const source_pr_number = core.getInput("source_pr_number"); if (cherry_picking !== "auto" && cherry_picking !== "pull_request_head") { @@ -1126,6 +1127,7 @@ function run() { copy_assignees: copy_assignees === "true", copy_milestone: copy_milestone === "true", copy_requested_reviewers: copy_requested_reviewers === "true", + additional_reviewers: additional_reviewers === "" ? undefined : additional_reviewers.split(","), experimental: Object.assign(Object.assign({}, backport_1.experimentalDefaults), experimental), source_pr_number: source_pr_number === "" ? undefined : parseInt(source_pr_number), }; diff --git a/src/backport.ts b/src/backport.ts index feaa10b..c608bca 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -35,6 +35,7 @@ export type Config = { copy_milestone: boolean; copy_assignees: boolean; copy_requested_reviewers: boolean; + additional_reviewers: string[]; experimental: Experimental; }; @@ -418,23 +419,26 @@ export class Backport { } } + let reviewers: string [] = this.config.additional_reviewers || [] if (this.config.copy_requested_reviewers == true) { - const reviewers = mainpr.requested_reviewers?.map( - (reviewer) => reviewer.login, - ); - if (reviewers?.length > 0) { - console.info("Setting reviewers " + reviewers); - const reviewRequest = { - owner, - repo, - pull_number: new_pr.number, - reviewers: reviewers, - }; - const set_reviewers_response = - await this.github.requestReviewers(reviewRequest); - if (set_reviewers_response.status != 201) { - console.error(JSON.stringify(set_reviewers_response)); - } + const requested_reviewers = mainpr.requested_reviewers?.map( + (reviewer) => reviewer.login, + ) || []; + reviewers = reviewers.concat(requested_reviewers) + } + reviewers = [...new Set(reviewers)]; + if (reviewers?.length > 0) { + console.info("Setting reviewers " + reviewers); + const reviewRequest = { + owner, + repo, + pull_number: new_pr.number, + reviewers: reviewers, + }; + const set_reviewers_response = + await this.github.requestReviewers(reviewRequest); + if (set_reviewers_response.status != 201) { + console.error(JSON.stringify(set_reviewers_response)); } } diff --git a/src/main.ts b/src/main.ts index 8833099..dc7d087 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,7 @@ async function run(): Promise { const copy_assignees = core.getInput("copy_assignees"); const copy_milestone = core.getInput("copy_milestone"); const copy_requested_reviewers = core.getInput("copy_requested_reviewers"); + const additional_reviewers = core.getInput("additional_reviewers"); const experimental = JSON.parse(core.getInput("experimental")); const source_pr_number = core.getInput("source_pr_number"); @@ -85,6 +86,7 @@ async function run(): Promise { copy_assignees: copy_assignees === "true", copy_milestone: copy_milestone === "true", copy_requested_reviewers: copy_requested_reviewers === "true", + additional_reviewers: additional_reviewers === "" ? undefined : additional_reviewers.split(","), experimental: { ...experimentalDefaults, ...experimental }, source_pr_number: source_pr_number === "" ? undefined : parseInt(source_pr_number),