-
Notifications
You must be signed in to change notification settings - Fork 1.4k
61 lines (53 loc) · 1.83 KB
/
autoassign-issues.yml
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
53
54
55
56
57
58
59
60
61
name: Issue autoassignment
on:
issues:
types: [opened]
jobs:
assign-new-issue:
runs-on: ubuntu-latest
permissions:
issues: 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/4],
["schaable", 2/4],
["galargh", 3/4],
["ChristopherDedominici", 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");
}
console.log("assignee:", assignee);
console.log("Fetch issue", context.issue.number);
const issue = await github.rest.issues.get({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number,
});
console.log("Author association:", issue.data.author_association);
const isCollaborator = ["OWNER", "MEMBER", "COLLABORATOR"].includes(
issue.data.author_association
);
console.log("Is collaborator?", isCollaborator);
// we only assign triage issues 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],
});
}