From 08386c85b52e666ff72e8d6737df2186aadfcf25 Mon Sep 17 00:00:00 2001 From: Arthur Dzieniszewski Date: Wed, 22 Dec 2021 11:24:01 -0500 Subject: [PATCH] added reviewers with test --- .github/workflows/debug.yml | 1 + .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ README.md | 1 + action.yml | 3 +++ index.js | 17 +++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 04fd4bb8..c70d18d5 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -22,3 +22,4 @@ jobs: path: "test.txt" commit-message: "debug" author: "Gregor Martynus <39992+gr2m@users.noreply.github.com>" + reviewers: gr2m diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77acd72f..28052348 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -209,3 +209,39 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: ${{ fromJson(steps.get-pull-request.outputs.data).title != 'Updated test pull request' }} run: 'echo "Pull request title is \"${{ fromJson(steps.get-pull-request.outputs.data).title }}\" but expected \"Updated test pull request\"" && exit 1' + + addReviewers: + name: "[TEST] Add Reviewers" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + - run: "date > test.txt" + - run: "npm ci" + - run: "npm run build" + - uses: ./ + id: run + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ACTIONS_STEP_DEBUG: true + with: + title: Test Add Reviewers + body: This pull request is part of the CI - please ignore. + branch: test-add-reviewers-${{ github.run_number }} + commit-message: "Just testing [skip ci]" + reviewers: gr2m + - uses: octokit/request-action@v2.x + id: get-pull-request + with: + route: GET /repos/{owner}/{repo}/pulls/{pull_number} + owner: gr2m + repo: create-or-update-pull-request-action + pull_number: ${{ steps.run.outputs.pull-request-number }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git :test-add-reviewers-${{ github.run_number }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - if: ${{ !contains(toJson(fromJson(steps.get-pull-request.outputs.data).requested_reviewers.*.login), 'gr2m') }} + run: 'echo "Requested reviewers are \"${{ toJson(fromJson(steps.get-pull-request.outputs.data).requested_reviewers.*.login) }}\" but expected \"[\n gr2m \n]\"" && exit 1' diff --git a/README.md b/README.md index 5c2bb5b2..a5c773d1 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ with: author: "Lorem J. Ipsum " labels: label1, label2 assignees: user1, user2 + reviewers: user1, user2 auto-merge: squash update-pull-request-title-and-body: false ``` diff --git a/action.yml b/action.yml index 1e9dc310..d7cee0cd 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: assignees: description: Comma separated list of assignees to apply to the pull request required: false + reviewers: + description: Comma separated list of 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 58987d25..6b667c8b 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ async function main() { author: core.getInput("author"), labels: core.getInput("labels"), assignees: core.getInput("assignees"), + reviewers: core.getInput("reviewers"), autoMerge: core.getInput("auto-merge"), updatePRTitleAndBody: core.getInput("update-pull-request-title-and-body"), }; @@ -221,6 +222,22 @@ async function main() { core.info(`Assignees added: ${assignees.join(", ")}`); core.debug(inspect(data)); } + + if (inputs.reviewers) { + core.debug(`Adding reviewers: ${inputs.reviewers}`); + const reviewers = inputs.reviewers.trim().split(/\s*,\s*/); + const { data } = await octokit.request( + `POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers`, + { + owner, + repo, + pull_number: number, + reviewers, + } + ); + core.info(`Reviewers added: ${reviewers.join(", ")}`); + core.debug(inspect(data)); + } if (inputs.autoMerge) { const query = `