|
3 | 3 | * Licensed under the MIT License. See LICENSE in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { OctoKitIssue } from '../api/octokit'; |
| 6 | +import { getInput } from '@actions/core'; |
| 7 | +import { OctoKit, OctoKitIssue } from '../api/octokit'; |
7 | 8 | import { VSCodeToolsAPIManager } from '../api/vscodeTools'; |
8 | | -import { Action } from '../common/Action'; |
9 | | -import { getRequiredInput, safeLog } from '../common/utils'; |
| 9 | +import { Action, getAuthenticationToken } from '../common/Action'; |
| 10 | +import { daysAgoToHumanReadbleDate, getRequiredInput, safeLog } from '../common/utils'; |
10 | 11 |
|
11 | 12 | class IssueTriageAction extends Action { |
12 | 13 | id = 'IssueTriageAction'; |
13 | 14 |
|
14 | | - private async triage(issue: OctoKitIssue) { |
| 15 | + private async triage(issue: OctoKitIssue, skipTeamCheck = false): Promise<void> { |
15 | 16 | try { |
16 | 17 | const githubIssue = await issue.getIssue(); |
17 | 18 | if (!githubIssue) return; |
18 | 19 |
|
19 | 20 | const vscodeToolsAPI = new VSCodeToolsAPIManager(); |
20 | 21 | const teamMembers = new Set((await vscodeToolsAPI.getTeamMembers()).map((t) => t.id)); |
21 | | - if (teamMembers.has(githubIssue.author.name)) { |
| 22 | + if (!skipTeamCheck && teamMembers.has(githubIssue.author.name)) { |
| 23 | + if (githubIssue.assignees.length === 0) { |
| 24 | + const link = getInput('workingAreasLink'); |
| 25 | + if (link) { |
| 26 | + await issue.postComment( |
| 27 | + `Hi ${githubIssue.author.name}. As a member of the team, you can help us triage this issue by referring to ${link}`, |
| 28 | + ); |
| 29 | + } else { |
| 30 | + await issue.postComment( |
| 31 | + `Hi ${githubIssue.author.name}. You can help us triage this issue by assigning it to the appropriate person.`, |
| 32 | + ); |
| 33 | + } |
| 34 | + } |
22 | 35 | safeLog('Author is a team member, skipping triaging', githubIssue.author.name); |
23 | 36 | return; |
24 | 37 | } |
@@ -62,10 +75,31 @@ class IssueTriageAction extends Action { |
62 | 75 | } |
63 | 76 |
|
64 | 77 | protected override async onOpened(issue: OctoKitIssue): Promise<void> { |
65 | | - // wait 30 seconds before triaging |
66 | | - await new Promise((resolve) => setTimeout(resolve, 30000)); |
| 78 | + // wait 1 minute before triaging |
| 79 | + await new Promise((resolve) => setTimeout(resolve, 60000)); |
67 | 80 | await this.triage(issue); |
68 | 81 | } |
| 82 | + |
| 83 | + protected override async onTriggered(_octokit: OctoKit): Promise<void> { |
| 84 | + const owner = getRequiredInput('owner'); |
| 85 | + const repo = getRequiredInput('repo'); |
| 86 | + const token = await getAuthenticationToken(); |
| 87 | + |
| 88 | + const staleIssues = _octokit.query({ |
| 89 | + q: `is:issue is:open no:assignee no:label updated:<${daysAgoToHumanReadbleDate(7)}`, |
| 90 | + }); |
| 91 | + |
| 92 | + // Loop through issues which are not assigned and no labels and updated more than 7 days ago |
| 93 | + for await (const page of staleIssues) { |
| 94 | + for (const issueData of page) { |
| 95 | + const issue = await issueData.getIssue(); |
| 96 | + if (!issue) continue; |
| 97 | + const octokitIssue = new OctoKitIssue(token, { owner, repo }, { number: issue?.number }); |
| 98 | + await this.triage(octokitIssue, true); |
| 99 | + } |
| 100 | + } |
| 101 | + safeLog('Completed triaging stale issues.'); |
| 102 | + } |
69 | 103 | } |
70 | 104 |
|
71 | 105 | new IssueTriageAction().run(); // eslint-disable-line |
0 commit comments