Skip to content

Commit bfae0bf

Browse files
sizhit2The tunix Authors
authored andcommitted
Update issue auto-assignment script to async and clean up logic.
PiperOrigin-RevId: 879449680
1 parent b3de6ec commit bfae0bf

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

.github/workflows/issue-auto-assign.js

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,23 @@
1919
* @returns {!Promise<void>}
2020
*/
2121
module.exports = async ({github, context}) => {
22+
// Define the list once to keep things clean and easy to update
23+
const assigneesList = [
24+
"tianshub",
25+
"wang2yn84",
26+
"lc5211",
27+
"hgao327",
28+
"sizhit2",
29+
"abheesht17",
30+
"jiangyangmu"
31+
];
32+
2233
let issueNumber;
23-
let assigneesList;
2434

35+
// Grab the correct number depending on the event type
2536
if (context.payload.issue) {
26-
assigneesList = [
27-
"tianshub",
28-
"wang2yn84",
29-
"lc5211",
30-
"hgao327",
31-
"sizhit2",
32-
"abheesht17",
33-
"jiangyangmu"
34-
]; // for issues
3537
issueNumber = context.payload.issue.number;
3638
} else if (context.payload.pull_request) {
37-
assigneesList = [
38-
"tianshub",
39-
"wang2yn84",
40-
"lc5211",
41-
"hgao327",
42-
"sizhit2",
43-
"abheesht17",
44-
"jiangyangmu"
45-
]; // for PRs
4639
issueNumber = context.payload.pull_request.number;
4740
} else {
4841
console.log('Not an issue or PR');
@@ -52,24 +45,17 @@ module.exports = async ({github, context}) => {
5245
console.log('Assignee list:', assigneesList);
5346
console.log('Entered auto assignment for this issue/PR:', issueNumber);
5447

55-
if (!assigneesList.length) {
56-
console.log('No assignees found for this repo.');
57-
return;
58-
}
59-
60-
// To assign issue or PRs on Weekly Rotation basis
61-
const now = new Date();
6248
// Calculate total weeks since Unix Epoch (Jan 1, 1970)
63-
// 604800000 is the number of milliseconds in a week
49+
const now = new Date();
6450
const weekCount = Math.floor(now.getTime() / 604800000);
6551

66-
const noOfAssignees = assigneesList.length;
67-
const selection = weekCount % noOfAssignees;
52+
// Pick the assignee
53+
const selection = weekCount % assigneesList.length;
6854
const assigneeForIssue = assigneesList[selection];
6955

70-
console.log(
71-
`Issue/PR Number = ${issueNumber}, assigning to: ${assigneeForIssue}`);
56+
console.log(`Issue/PR Number = ${issueNumber}, assigning to: ${assigneeForIssue}`);
7257

58+
// Return the API call so the YAML 'await' works correctly
7359
return github.rest.issues.addAssignees({
7460
issue_number: issueNumber,
7561
owner: context.repo.owner,

.github/workflows/issue-auto-assign.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
with:
2323
script: |
2424
const script = require('./\.github/workflows/issue-auto-assign.js')
25-
script({github, context})
25+
await script({github, context})

0 commit comments

Comments
 (0)