From 466b1b84c3291c6c69bc56377a6de54a1f4a297c Mon Sep 17 00:00:00 2001 From: adzienis Date: Wed, 22 Dec 2021 19:29:11 -0500 Subject: [PATCH] feat: `team_reviewers` input (#493) --- .github/workflows/test.yml | 1 + README.md | 1 + action.yml | 3 +++ index.js | 50 ++++++++++++++++++++++++++++++-------- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28052348..1fe32ac2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -231,6 +231,7 @@ jobs: branch: test-add-reviewers-${{ github.run_number }} commit-message: "Just testing [skip ci]" reviewers: gr2m + team_reviewers: test-reviewers - uses: octokit/request-action@v2.x id: get-pull-request with: diff --git a/README.md b/README.md index a5c773d1..8644b631 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ with: labels: label1, label2 assignees: user1, user2 reviewers: user1, user2 + team_reviewers: team1, team2 auto-merge: squash update-pull-request-title-and-body: false ``` diff --git a/action.yml b/action.yml index d7cee0cd..18c2e3e0 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,9 @@ inputs: reviewers: description: Comma separated list of reviewers to apply to the pull request required: false + team_reviewers: + description: Comma separated list of team reviewers to apply to the pull request + required: false auto-merge: description: "Enable auto merge for pull request. Requires auto merging to be enabled in repository settings" required: false diff --git a/index.js b/index.js index 6b667c8b..9d7269cc 100644 --- a/index.js +++ b/index.js @@ -53,6 +53,7 @@ async function main() { labels: core.getInput("labels"), assignees: core.getInput("assignees"), reviewers: core.getInput("reviewers"), + team_reviewers: core.getInput("team_reviewers"), autoMerge: core.getInput("auto-merge"), updatePRTitleAndBody: core.getInput("update-pull-request-title-and-body"), }; @@ -223,19 +224,48 @@ async function main() { core.debug(inspect(data)); } - if (inputs.reviewers) { - core.debug(`Adding reviewers: ${inputs.reviewers}`); - const reviewers = inputs.reviewers.trim().split(/\s*,\s*/); + if (inputs.reviewers || inputs.team_reviewers) { + let params = { + owner, + repo, + pull_number: number + } + let reviewers = null; + let team_reviewers = null; + + if(inputs.reviewers) { + core.debug(`Adding reviewers: ${inputs.reviewers}`) + reviewers = (inputs.reviewers || "").trim().split(/\s*,\s*/); + + params = { + ...params, + reviewers + } + }; + + if(inputs.team_reviewers) { + core.debug(`Adding team reviewers: ${inputs.team_reviewers}`) + team_reviewers = (inputs.team_reviewers || "").trim().split(/\s*,\s*/); + + params = { + ...params, + team_reviewers + } + } ; + const { data } = await octokit.request( `POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers`, - { - owner, - repo, - pull_number: number, - reviewers, - } + params ); - core.info(`Reviewers added: ${reviewers.join(", ")}`); + + if(reviewers) { + core.info(`Reviewers added: ${reviewers.join(", ")}`); + } + + if(team_reviewers) { + core.info(`Team reviewers added: ${team_reviewers.join(", ")}`); + } + core.debug(inspect(data)); }