Skip to content

Commit

Permalink
Auto-label PRs by outside collaborators (#648)
Browse files Browse the repository at this point in the history
b/261052420
  • Loading branch information
andrewsavage1 committed Aug 7, 2023
1 parent cae93f9 commit d6d6554
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/auto_assign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR Reviewer Auto Assignment

on:
pull_request_target:
types:
- opened
- reopened

concurrency:
group: '${{ github.workflow }}-${{ github.event_name }} @ ${{ github.event.pull_request.number || github.sha }}'
cancel-in-progress: true

jobs:
assign-reviewer:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check if PR author is outside collaborator and assign reviewer
env:
PR_AUTHOR_LOGIN: ${{ github.event.pull_request.user.login }}
REPO_NAME: ${{ github.event.repository.full_name }}
PR_NUMBER: ${{ github.event.number }}
run: |
PERMISSION_LEVEL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO_NAME/collaborators/$PR_AUTHOR_LOGIN/permission" | jq -r .role_name)
if [ "$PERMISSION_LEVEL" == "none" ] || [ "$PERMISSION_LEVEL" == "read" ]; then
echo "PR author is an outside collaborator. Adding label..."
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '["outside collaborator"]' \
"https://api.github.com/repos/$REPO_NAME/issues/$PR_NUMBER/labels"
fi

0 comments on commit d6d6554

Please sign in to comment.