Skip to content

Update README.md

Update README.md #3

name: Assign Suggested Reviewers or Default Reviewers
on:
pull_request:
types: [opened, reopened, synchronize] # Trigger on PR open, reopen, or sync
jobs:
assign-reviewers:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Retrieve Suggested Reviewers
id: get-reviewers
run: |
# Use GitHub API to retrieve suggested reviewers for the PR
suggestedReviewers=$(curl -s -X GET \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers")
echo "::set-output name=suggestedReviewers::$suggestedReviewers"
- name: Check and Assign Reviewers
run: |
suggestedReviewers="${{ steps.get-reviewers.outputs.suggestedReviewers }}"
if [ "$suggestedReviewers" != 'null' ]; then
reviewers=$(echo "$suggestedReviewers" | jq -r '.users[].login')
for reviewer in $reviewers; do
# Use GitHub API to assign suggested reviewers to the PR
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"reviewers\": [\"$reviewer\"]}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers"
done
else
# If there are no suggested reviewers, assign default reviewers
defaultReviewers='["Alexander-Da-Great "]'
for defaultReviewer in $defaultReviewers; do
# Use GitHub API to assign default reviewers to the PR
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"reviewers\": [\"@$defaultReviewer\"]}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers"
done
fi