Skip to content

Commit 4fa8b74

Browse files
sampathwebtensorflower-gardener
authored andcommitted
Implement auto-assignment for newly created issues.
PiperOrigin-RevId: 580745663
1 parent f20da73 commit 4fa8b74

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: auto-assignment
2+
on:
3+
issues:
4+
types:
5+
- opened
6+
pull_request_target:
7+
types: [opened]
8+
9+
10+
permissions:
11+
contents: read
12+
issues: write
13+
pull-requests: write
14+
15+
jobs:
16+
welcome:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: actions/github-script@v6
21+
with:
22+
script: |
23+
const script = require('./\.github/workflows/scripts/auto-assignment.js')
24+
script({github, context})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* =============================================================================
16+
*/
17+
18+
/** Automatically assign issues and PRs to users in the `assigneesList`
19+
* on a rotating basis.
20+
21+
@param {!object}
22+
GitHub objects can call GitHub APIs using their built-in library functions.
23+
The context object contains issue and PR details.
24+
*/
25+
26+
module.exports = async ({ github, context }) => {
27+
let issueNumber;
28+
let assigneesList;
29+
// Is this an issue? If so, assign the issue number. Otherwise, assign the PR number.
30+
if (context.payload.issue) {
31+
//assignee List for issues.
32+
assigneesList = ["tilakrayal"];
33+
issueNumber = context.payload.issue.number;
34+
} else {
35+
//assignee List for PRs.
36+
assigneesList = ['tilakrayal'];
37+
issueNumber = context.payload.number;
38+
}
39+
console.log("assignee list", assigneesList);
40+
console.log("entered auto assignment for this issue: ", issueNumber);
41+
if (!assigneesList.length) {
42+
console.log("No assignees found for this repo.");
43+
return;
44+
}
45+
let noOfAssignees = assigneesList.length;
46+
let selection = issueNumber % noOfAssignees;
47+
let assigneeForIssue = assigneesList[selection];
48+
49+
console.log(
50+
"issue Number = ",
51+
issueNumber + " , assigning to: ",
52+
assigneeForIssue
53+
);
54+
return github.rest.issues.addAssignees({
55+
issue_number: context.issue.number,
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
assignees: [assigneeForIssue],
59+
});
60+
};

0 commit comments

Comments
 (0)