-
Notifications
You must be signed in to change notification settings - Fork 1.3k
53 lines (48 loc) · 1.74 KB
/
issue-auto-assign.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
name: "Auto assign maintainer to issue"
on:
# makes this workflow re-usable
workflow_call:
issues:
types: [opened]
issue_comment:
types: [created]
permissions:
issues: write
jobs:
assign-user:
runs-on: ubuntu-latest
# issue_comment triggers for both, issues and prs,
# as we need to run only on issues, it filter out prs.
if: ${{ !github.event.issue.pull_request }}
steps:
- uses: actions/github-script@v7
with:
script: |
const assignees = ['mstoykov', 'olegbespalov', 'oleiade', 'joanlopez', 'ankur22', 'inancgumus'];
const assigneeCount = 1;
// Do not automatically assign users if someone was already assigned or it was opened by a maintainer
if (context.payload.issue.assignees.length > 0 || assignees.includes(context.actor)) {
return;
}
const crypto = require("node:crypto");
const getNRandom = (n, array) => {
let result = new Array();
for (;n > 0 && array.length > 0; n--) {
const chosen = array[crypto.randomInt(array.length)];
result.push(chosen);
array = array.filter(el => el != chosen);
}
return result;
}
github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: getNRandom(assigneeCount, assignees),
});
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["triage"]
});