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

ci: add auto assign job #21939

Merged
merged 7 commits into from
Sep 26, 2024
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
60 changes: 60 additions & 0 deletions .github/workflows/auto-assign-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Auto Assign Reviewers

on:
pull_request:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for external reviewers, but that's fine, I'll go assign reviewers manually like we do now.
This will already help daily.

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}`);
Loading