-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc2cea5
commit 2c85694
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Auto Assign Reviewers | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, review_requested] | ||
|
||
jobs: | ||
assign-reviewers: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Assign reviewers as assignees | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.PRBOT_PAT }} | ||
script: | | ||
const { owner, repo } = context.repo; | ||
async function getCurrentPR() { | ||
if (context.payload.pull_request) { | ||
return context.payload.pull_request; | ||
} | ||
const allPRs = await github.rest.pulls.list({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
}); | ||
return allPRs.data.find(pr => pr.head.sha === context.sha); | ||
} | ||
const pr = await getCurrentPR(); | ||
if (!pr) { | ||
console.log('No matching PR found.'); | ||
return; | ||
} | ||
console.log(`Processing PR #${pr.number}`); | ||
const reviewers = pr.requested_reviewers.map(reviewer => reviewer.login); | ||
if (reviewers.length === 0) { | ||
console.log('No reviewers found for this PR.'); | ||
return; | ||
} | ||
console.log(`Current reviewers: ${reviewers.join(', ')}`); | ||
await github.rest.issues.addAssignees({ | ||
owner, | ||
repo, | ||
issue_number: pr.number, | ||
assignees: reviewers, | ||
}); | ||
console.log(`Assigned ${reviewers.join(', ')} as assignees to PR #${pr.number}`); |