diff --git a/backport/action.yml b/backport/action.yml index c70af66..698aecc 100644 --- a/backport/action.yml +++ b/backport/action.yml @@ -5,7 +5,7 @@ inputs: description: | GitHub token with read and write permissions for issues, comments, and labels. - Additionally, the token needs read permissions for organization members. + Additionally, the token needs read permissions for organization members if `removeDefaultReviewers` is set to `true`. default: ${{ github.token }} title: description: Title for the backport PR @@ -13,6 +13,10 @@ inputs: labelsToAdd: description: Comma separated list of labels to add to the backport PR. required: false + removeDefaultReviewers: + default: true + description: Whether to remove default reviewers from the backport PRs. + type: boolean metricsWriteAPIKey: description: Grfanaa Cloud metrics api key required: false diff --git a/backport/backport.js b/backport/backport.js index c205772..8e1375d 100644 --- a/backport/backport.js +++ b/backport/backport.js @@ -53,7 +53,7 @@ const isBettererConflict = async (gitUnmergedPaths) => { return gitUnmergedPaths.length === 1 && gitUnmergedPaths[0] === exports.BETTERER_RESULTS_PATH; }; exports.isBettererConflict = isBettererConflict; -const backportOnce = async ({ base, body, commitToBackport, github, head, labelsToAdd, owner, repo, title, mergedBy, }) => { +const backportOnce = async ({ base, body, commitToBackport, github, head, labelsToAdd, removeDefaultReviewers, owner, repo, title, mergedBy, }) => { const git = async (...args) => { await (0, exec_1.exec)('git', args, { cwd: repo }); }; @@ -126,7 +126,7 @@ const backportOnce = async ({ base, body, commitToBackport, github, head, labels }); } // Remove default reviewers - if (createRsp.data.requested_reviewers) { + if (removeDefaultReviewers && createRsp.data.requested_reviewers) { const reviewers = createRsp.data.requested_reviewers.map((user) => user.login); await github.pulls.deleteReviewRequest({ pull_number: pullRequestNumber, @@ -206,7 +206,7 @@ const getFailedBackportCommentBody = ({ base, commitToBackport, errorMessage, he return lines.join('\n'); }; exports.getFailedBackportCommentBody = getFailedBackportCommentBody; -const backport = async ({ issue, labelsToAdd, payload: { action, label, pull_request: { labels, merge_commit_sha: mergeCommitSha, merged, number: pullRequestNumber, title: originalTitle, merged_by, }, repository: { name: repo, owner: { login: owner }, }, }, titleTemplate, token, github, sender, }) => { +const backport = async ({ issue, labelsToAdd, payload: { action, label, pull_request: { labels, merge_commit_sha: mergeCommitSha, merged, number: pullRequestNumber, title: originalTitle, merged_by, }, repository: { name: repo, owner: { login: owner }, }, }, titleTemplate, removeDefaultReviewers, token, github, sender, }) => { const payload = github_1.context.payload; console.log('payloadAction: ' + payload.action); if (payload.action !== 'closed') { @@ -322,6 +322,7 @@ const backport = async ({ issue, labelsToAdd, payload: { action, label, pull_req github: github, head, labelsToAdd: prLabels, + removeDefaultReviewers, owner, repo, title, diff --git a/backport/backport.ts b/backport/backport.ts index 876f45e..2a0c0aa 100644 --- a/backport/backport.ts +++ b/backport/backport.ts @@ -83,6 +83,7 @@ const backportOnce = async ({ github, head, labelsToAdd, + removeDefaultReviewers, owner, repo, title, @@ -94,6 +95,7 @@ const backportOnce = async ({ github: InstanceType head: string labelsToAdd: string[] + removeDefaultReviewers: boolean owner: string repo: string title: string @@ -154,7 +156,9 @@ const backportOnce = async ({ if (/^v\d+\.\d+\.x$/.test(base)) { const milestoneName = base.substring(1) const allMilestones = await github.issues.listMilestonesForRepo({ owner, repo, state: 'open' }) - const milestone = allMilestones.data.find((milestone) => milestone.title === milestoneName) + const milestone = allMilestones.data.find( + (milestone: { title: string }) => milestone.title === milestoneName, + ) if (milestone) { await github.issues.update({ repo, @@ -177,8 +181,8 @@ const backportOnce = async ({ } // Remove default reviewers - if (createRsp.data.requested_reviewers) { - const reviewers = createRsp.data.requested_reviewers.map((user) => user.login) + if (removeDefaultReviewers && createRsp.data.requested_reviewers) { + const reviewers = createRsp.data.requested_reviewers.map((user: { login: string }) => user.login) await github.pulls.deleteReviewRequest({ pull_number: pullRequestNumber, repo, @@ -284,6 +288,7 @@ interface BackportArgs { labelsToAdd: string[] payload: EventPayloads.WebhookPayloadPullRequest titleTemplate: string + removeDefaultReviewers: boolean token: string github: GitHub sender: EventPayloads.PayloadSender @@ -309,6 +314,7 @@ const backport = async ({ }, }, titleTemplate, + removeDefaultReviewers, token, github, sender, @@ -442,6 +448,7 @@ const backport = async ({ github: github, head, labelsToAdd: prLabels, + removeDefaultReviewers, owner, repo, title, diff --git a/backport/index.js b/backport/index.js index 7ab9765..945f76f 100644 --- a/backport/index.js +++ b/backport/index.js @@ -24,6 +24,7 @@ class Backport extends Action_1.Action { labelsToAdd: (0, exports.getLabelsToAdd)((0, core_1.getInput)('labelsToAdd')), payload: github_1.context.payload, titleTemplate: (0, core_1.getInput)('title'), + removeDefaultReviewers: (0, core_1.getBooleanInput)('removeDefaultReviewers'), github: issue.octokit, token: this.getToken(), sender: github_1.context.payload.sender, diff --git a/backport/index.ts b/backport/index.ts index 15f0e6e..40702b7 100644 --- a/backport/index.ts +++ b/backport/index.ts @@ -1,4 +1,4 @@ -import { error as logError, getInput, setFailed } from '@actions/core' +import { error as logError, getBooleanInput, getInput, setFailed } from '@actions/core' import { context } from '@actions/github' import { EventPayloads } from '@octokit/webhooks' import { OctoKitIssue } from '../api/octokit' @@ -23,6 +23,7 @@ class Backport extends Action { labelsToAdd: getLabelsToAdd(getInput('labelsToAdd')), payload: context.payload as EventPayloads.WebhookPayloadPullRequest, titleTemplate: getInput('title'), + removeDefaultReviewers: getBooleanInput('removeDefaultReviewers'), github: issue.octokit, token: this.getToken(), sender: context.payload.sender as EventPayloads.PayloadSender,