diff --git a/.github/workflows/scripts/auto-assignment.js b/.github/workflows/scripts/auto-assignment.js index d9e7956426..953d47d85a 100644 --- a/.github/workflows/scripts/auto-assignment.js +++ b/.github/workflows/scripts/auto-assignment.js @@ -1,43 +1,66 @@ /** Automatically assign issues and PRs to users in the `assigneesList` * on a rotating basis. - - @param {!object} - GitHub objects can call GitHub APIs using their built-in library functions. - The context object contains issue and PR details. */ module.exports = async ({ github, context }) => { - let issueNumber; - let assigneesList; - // Is this an issue? If so, assign the issue number. Otherwise, assign the PR number. - if (context.payload.issue) { - //assignee List for issues. - assigneesList = ["mehtamansi29", "sonali-kumari1", "dhantule", "sachinprasadhs"]; - issueNumber = context.payload.issue.number; + const isIssue = !!context.payload.issue; + const isPr = !!context.payload.pull_request; + + let candidates = []; + let itemNumber; + let author; + + // 1. Determine if this is an Issue or PR and select the list + if (isIssue) { + candidates = ["dhantule", "sachinprasadhs", "LakshmiKalaKadali", "maitry63"]; + itemNumber = context.payload.issue.number; + author = context.payload.issue.user.login; + } else if (isPr) { + // Reviewer list for PRs + candidates = ["sachinprasadhs", "divyashreepathihalli"]; + itemNumber = context.payload.pull_request.number; + author = context.payload.pull_request.user.login; } else { - //assignee List for PRs. - assigneesList = [mattdangerw]; - issueNumber = context.payload.number; + console.log("Not an issue or PR payload."); + return; } - console.log("assignee list", assigneesList); - console.log("entered auto assignment for this issue: ", issueNumber); - if (!assigneesList.length) { - console.log("No assignees found for this repo."); + + if (!candidates.length) { + console.log("No candidates found."); return; } - let noOfAssignees = assigneesList.length; - let selection = issueNumber % noOfAssignees; - let assigneeForIssue = assigneesList[selection]; - console.log( - "issue Number = ", - issueNumber + " , assigning to: ", - assigneeForIssue - ); - return github.rest.issues.addAssignees({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - assignees: [assigneeForIssue], - }); -}; + // 2. Select a candidate based on the Issue/PR number (Rotation) + let selectionIndex = itemNumber % candidates.length; + let selectedUser = candidates[selectionIndex]; + + // 3. No author restriction: allow assigning any candidate (including the PR author) + if (isPr) { + console.log(`Processing #${itemNumber}. Reviewers: ${candidates.join(', ')}`); + } else { + console.log(`Processing #${itemNumber}. Selected: ${selectedUser}`); + } + + // 4. Perform the action + try { + if (isPr) { + // For PRs: Request Reviews from all reviewers in the PR list + await github.rest.pulls.requestReviewers({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: itemNumber, + reviewers: candidates, + }); + } else { + // For Issues: Add an Assignee + await github.rest.issues.addAssignees({ + issue_number: itemNumber, + owner: context.repo.owner, + repo: context.repo.repo, + assignees: [selectedUser], + }); + } + } catch (err) { + console.log("Error adding assignee/reviewer:", err.message); + } +}; \ No newline at end of file