Skip to content
Merged
Show file tree
Hide file tree
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
48 changes: 17 additions & 31 deletions .github/workflows/issue-auto-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,23 @@
* @returns {!Promise<void>}
*/
module.exports = async ({github, context}) => {
// Define the list once to keep things clean and easy to update
const assigneesList = [
"tianshub",
"wang2yn84",
"lc5211",
"hgao327",
"sizhit2",
"abheesht17",
"jiangyangmu"
];

let issueNumber;
let assigneesList;

// Grab the correct number depending on the event type
if (context.payload.issue) {
assigneesList = [
"tianshub",
"wang2yn84",
"lc5211",
"hgao327",
"sizhit2",
"abheesht17",
"jiangyangmu"
]; // for issues
issueNumber = context.payload.issue.number;
} else if (context.payload.pull_request) {
assigneesList = [
"tianshub",
"wang2yn84",
"lc5211",
"hgao327",
"sizhit2",
"abheesht17",
"jiangyangmu"
]; // for PRs
issueNumber = context.payload.pull_request.number;
} else {
console.log('Not an issue or PR');
Expand All @@ -52,24 +45,17 @@ module.exports = async ({github, context}) => {
console.log('Assignee list:', assigneesList);
console.log('Entered auto assignment for this issue/PR:', issueNumber);

if (!assigneesList.length) {
console.log('No assignees found for this repo.');
return;
}

// To assign issue or PRs on Weekly Rotation basis
const now = new Date();
// Calculate total weeks since Unix Epoch (Jan 1, 1970)
// 604800000 is the number of milliseconds in a week
const now = new Date();
const weekCount = Math.floor(now.getTime() / 604800000);

const noOfAssignees = assigneesList.length;
const selection = weekCount % noOfAssignees;
// Pick the assignee
const selection = weekCount % assigneesList.length;
const assigneeForIssue = assigneesList[selection];

console.log(
`Issue/PR Number = ${issueNumber}, assigning to: ${assigneeForIssue}`);
console.log(`Issue/PR Number = ${issueNumber}, assigning to: ${assigneeForIssue}`);

// Return the API call so the YAML 'await' works correctly
return github.rest.issues.addAssignees({
issue_number: issueNumber,
owner: context.repo.owner,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issue-auto-assign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
with:
script: |
const script = require('./\.github/workflows/issue-auto-assign.js')
script({github, context})
await script({github, context})