Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues auto-assigner #131

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/issue-auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: "Auto assign maintainer to issue"
on:
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 assigneeCount = 1;

const core = {
assignees: ['mstoykov', 'codebien', 'olegbespalov', 'oleiade', 'joanlopez'],
keywords: ['utils', 'summary', 'httpx', 'url'],
}
const frontend = {
assignees: ['legander', 'w1kman', 'allansson', 'going-confetti', '2Steaks', 'e-fisher', 'EdvinasDaugirdas'],
keywords: ['jsonpath', 'urlencoded', 'chaijs', 'paparse', 'ajv'],
}

const teams = [core, frontend]
const allAssignees = teams.flatMap((team) => team.assignees);

// Do not automatically assign users if someone was already assigned or it was opened by a maintainer
if (context.payload.issue.assignees.length > 0 || allAssignees.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;
}

const pickAssignees = (n, teams, title) => {
let assignees = teams
.filter((team) => team.keywords.some((keyword) => title.includes(keyword)))
.flatMap((team) => team.assignees)

if (assignees.length == 0) {
assignees = teams.flatMap((team) => team.assignees)
}

return getNRandom(n, assignees)
}

github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ["triage"]
});

github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: pickAssignees(assigneeCount, teams, context.issue.title),
});

Loading