Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to opt out of removal of default reviewers #227

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backport/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ 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
default: "[Backport to {{base}}] {{originalTitle}}"
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
Expand Down
7 changes: 4 additions & 3 deletions backport/backport.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions backport/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const backportOnce = async ({
github,
head,
labelsToAdd,
removeDefaultReviewers,
owner,
repo,
title,
Expand All @@ -94,6 +95,7 @@ const backportOnce = async ({
github: InstanceType<typeof GitHub>
head: string
labelsToAdd: string[]
removeDefaultReviewers: boolean
owner: string
repo: string
title: string
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -284,6 +288,7 @@ interface BackportArgs {
labelsToAdd: string[]
payload: EventPayloads.WebhookPayloadPullRequest
titleTemplate: string
removeDefaultReviewers: boolean
token: string
github: GitHub
sender: EventPayloads.PayloadSender
Expand All @@ -309,6 +314,7 @@ const backport = async ({
},
},
titleTemplate,
removeDefaultReviewers,
token,
github,
sender,
Expand Down Expand Up @@ -442,6 +448,7 @@ const backport = async ({
github: github,
head,
labelsToAdd: prLabels,
removeDefaultReviewers,
owner,
repo,
title,
Expand Down
1 change: 1 addition & 0 deletions backport/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backport/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down
Loading