-
Notifications
You must be signed in to change notification settings - Fork 1.7k
52 lines (45 loc) · 1.5 KB
/
autoassign-prs.yml
File metadata and controls
52 lines (45 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: PR autoassignment
on:
pull_request_target:
types: [opened]
jobs:
assign-new-issue:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
// each user has a chance of (p - (previousP ?? 0)) to be assigned
const potentialAssignees = [
["kanej", 1.0]
];
let assignee;
const r = Math.random();
console.log("r:", r);
for (const [username, p] of potentialAssignees) {
if (r < p) {
assignee = username;
break;
}
}
if (assignee === undefined) {
throw new Error("An assignee should've been set");
}
// Within the Github API PRs are issue objects
const pr = await github.rest.issues.get({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number
});
const isCollaborator = ["OWNER", "MEMBER", "COLLABORATOR"].includes(pr.data.author_association)
// we only assign PRs from external users
if (!isCollaborator) {
await github.rest.issues.addAssignees({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number,
assignees: [assignee],
});
}