From da3ef2a53801c6b4dea186000826e91de8494e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dundar=20G=C3=B6c?= Date: Sun, 27 Mar 2022 21:48:28 +0200 Subject: [PATCH] ci: remove reviewers when drafting or closing a PR --- .github/scripts/remove-reviewers.js | 16 ++++++++++++++++ .github/workflows/remove-reviewers-on-draft.yml | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .github/scripts/remove-reviewers.js create mode 100644 .github/workflows/remove-reviewers-on-draft.yml diff --git a/.github/scripts/remove-reviewers.js b/.github/scripts/remove-reviewers.js new file mode 100644 index 0000000000..631f08e57d --- /dev/null +++ b/.github/scripts/remove-reviewers.js @@ -0,0 +1,16 @@ +module.exports = async ({github, context}) => { + const requestedReviewers = await github.rest.pulls.listRequestedReviewers({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + const reviewers = requestedReviewers.data.users.map(e => e.login) + + github.rest.pulls.removeRequestedReviewers({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + reviewers: reviewers + }); +} diff --git a/.github/workflows/remove-reviewers-on-draft.yml b/.github/workflows/remove-reviewers-on-draft.yml new file mode 100644 index 0000000000..64474618b8 --- /dev/null +++ b/.github/workflows/remove-reviewers-on-draft.yml @@ -0,0 +1,17 @@ +name: "Remove reviewers" +on: + pull_request_target: + types: [converted_to_draft, closed] +jobs: + remove-reviewers: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v2 + - name: 'Remove reviewers' + uses: actions/github-script@v6 + with: + script: | + const script = require('./.github/scripts/remove-reviewers.js') + await script({github, context})