Skip to content

Commit e86b09c

Browse files
authored
Add auto-assign-pr Action (#11247)
Auto-assigns PRs to Technical Writers team members when they create the PRs Only assigns if no one is already assigned; does nothing otherwise Only applies to Technical Writers team members; does nothing if someone else creates the PR --- * Add auto-assign-pr action * Add logging
1 parent 9aead12 commit e86b09c

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Auto-assign PR to Technical Writers
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
7+
jobs:
8+
auto-assign:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
13+
steps:
14+
- name: Assign PR to creator if on Technical Writers team
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const creator = context.payload.pull_request.user.login;
19+
const prNumber = context.payload.pull_request.number;
20+
const assignees = context.payload.pull_request.assignees;
21+
22+
console.log(`Processing PR #${prNumber} by ${creator}`);
23+
console.log(`Current assignees: ${assignees.length > 0 ? assignees.map(a => a.login).join(', ') : 'none'}`);
24+
25+
if (assignees.length > 0) {
26+
console.log('PR already has assignees, skipping auto-assignment');
27+
return;
28+
}
29+
30+
try {
31+
console.log(`Checking if ${creator} is on technical-writers team...`);
32+
await github.rest.teams.getMembershipForUserInOrg({
33+
org: context.repo.owner,
34+
team_slug: 'technical-writers',
35+
username: creator
36+
});
37+
38+
console.log(`${creator} is on technical-writers team, assigning PR...`);
39+
await github.rest.issues.addAssignees({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
issue_number: prNumber,
43+
assignees: [creator]
44+
});
45+
console.log(`Successfully assigned PR #${prNumber} to ${creator}`);
46+
} catch (error) {
47+
console.log(`${creator} is not on technical-writers team, skipping assignment`);
48+
console.log(`Error details: ${error.message}`);
49+
}

0 commit comments

Comments
 (0)