Skip to content

Commit

Permalink
refactor: moving issue-assigning logic to make it re-usable
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Aug 23, 2023
1 parent 0928c79 commit e21589c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
34 changes: 34 additions & 0 deletions .github/actions/issue-assigner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: assign-k6-maintainer
description: Assign a k6 maintainer to an issue

runs:
using: composite
steps:
- uses: actions/github-script@v6
with:
script: |
const assignees = ['mstoykov', 'codebien', 'olegbespalov', 'oleiade'];
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.payload.issue.user.login)) {
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),
});
30 changes: 2 additions & 28 deletions .github/workflows/issue-auto-assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,5 @@ jobs:
assign-user:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const assignees = ['mstoykov', 'codebien', 'olegbespalov', 'oleiade'];
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.payload.issue.user.login)) {
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),
});
- name: Assign k6's maintainer to issue
uses: ./.github/actions/issue-assigner/

0 comments on commit e21589c

Please sign in to comment.