Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-label PRs by outside collaborators #648

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading