Skip to content

[infra] Fix automated reviewers assignment workflow #4

[infra] Fix automated reviewers assignment workflow

[infra] Fix automated reviewers assignment workflow #4

name: Add reviewers to release PRs
on:
pull_request_target:
branches: ['master', 'next']
types: ['labeled']
permissions: {}
jobs:
add-reviewers:
# Tests that label is added on the PR
if: ${{ github.event.label.name == 'release' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- id: get-members
run: |
echo ::setOutput name=data::$(\
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/orgs/${{ORG}}/teams/${{TEAM_SLUG}}/members \
| jq 'reduce inputs as $i (.; . += $i)')
env:
ORG: ${{ github.event.organization }}
TEAM_SLUG: x
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# parse return value and construct a string of login values
- id: construct-members
run: echo '::setOutput name=members::${{ join(fromJson(steps.get-members.outputs.data).*.login) }}'
# assign reviewers
- id: assign-reviewers
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{GITHUB_TOKEN}}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ORG}}/${{REPO}}/pulls/${{PR_NUMBER}}/requested_reviewers \
-d '{"reviewers":[${{ steps.construct-members.outputs.members }}]}' \
env:
ORG: ${{ github.event.organization }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}