-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement auto-assignment for newly created issues.
PiperOrigin-RevId: 580745663
- Loading branch information
1 parent
f20da73
commit 4fa8b74
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: auto-assignment | ||
on: | ||
issues: | ||
types: | ||
- opened | ||
pull_request_target: | ||
types: [opened] | ||
|
||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
welcome: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const script = require('./\.github/workflows/scripts/auto-assignment.js') | ||
script({github, context}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ============================================================================= | ||
*/ | ||
|
||
/** 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 = ["tilakrayal"]; | ||
issueNumber = context.payload.issue.number; | ||
} else { | ||
//assignee List for PRs. | ||
assigneesList = ['tilakrayal']; | ||
issueNumber = context.payload.number; | ||
} | ||
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."); | ||
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], | ||
}); | ||
}; |