Update README.md #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |