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})