11/// <reference path="../env.d.ts" />
2- // import { Octokit } from "@octokit/rest"
32import { tool } from "@opencode-ai/plugin"
43import DESCRIPTION from "./github-triage.txt"
54
5+ const TEAM = {
6+ desktop : [ "adamdotdevin" , "iamdavidhill" , "Brendonovich" , "nexxeln" ] ,
7+ zen : [ "fwang" , "MrMushrooooom" ] ,
8+ tui : [ "thdxr" , "kommander" , "rekram1-node" ] ,
9+ core : [ "thdxr" , "rekram1-node" , "jlongster" ] ,
10+ docs : [ "R44VC0RP" ] ,
11+ windows : [ "Hona" ] ,
12+ } as const
13+
14+ const ASSIGNEES = [ ...new Set ( Object . values ( TEAM ) . flat ( ) ) ]
15+
16+ function pick < T > ( items : readonly T [ ] ) {
17+ return items [ Math . floor ( Math . random ( ) * items . length ) ] !
18+ }
19+
620function getIssueNumber ( ) : number {
721 const issue = parseInt ( process . env . ISSUE_NUMBER ?? "" , 10 )
822 if ( ! issue ) throw new Error ( "ISSUE_NUMBER env var not set" )
@@ -29,60 +43,69 @@ export default tool({
2943 description : DESCRIPTION ,
3044 args : {
3145 assignee : tool . schema
32- . enum ( [ "thdxr" , "adamdotdevin" , "rekram1-node" , "fwang" , "jayair" , "kommander" ] )
46+ . enum ( ASSIGNEES as [ string , ... string [ ] ] )
3347 . describe ( "The username of the assignee" )
3448 . default ( "rekram1-node" ) ,
3549 labels : tool . schema
36- . array ( tool . schema . enum ( [ "nix" , "opentui" , "perf" , "desktop" , "zen" , "docs" , "windows" ] ) )
50+ . array ( tool . schema . enum ( [ "nix" , "opentui" , "perf" , "web" , " desktop", "zen" , "docs" , "windows" , "core "] ) )
3751 . describe ( "The labels(s) to add to the issue" )
3852 . default ( [ ] ) ,
3953 } ,
4054 async execute ( args ) {
4155 const issue = getIssueNumber ( )
42- // const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
4356 const owner = "anomalyco"
4457 const repo = "opencode"
4558
4659 const results : string [ ] = [ ]
60+ let labels = [ ...new Set ( args . labels . map ( ( x ) => ( x === "desktop" ? "web" : x ) ) ) ]
61+ const web = labels . includes ( "web" )
62+ const text = `${ process . env . ISSUE_TITLE ?? "" } \n${ process . env . ISSUE_BODY ?? "" } ` . toLowerCase ( )
63+ const zen = / \b z e n \b / . test ( text ) || text . includes ( "opencode black" )
64+ const nix = / \b n i x ( o s ) ? \b / . test ( text )
65+
66+ if ( labels . includes ( "nix" ) && ! nix ) {
67+ labels = labels . filter ( ( x ) => x !== "nix" )
68+ results . push ( "Dropped label: nix (issue does not mention nix)" )
69+ }
70+
71+ const assignee = nix ? "rekram1-node" : web ? pick ( TEAM . desktop ) : args . assignee
4772
48- if ( args . assignee === "adamdotdevin" && ! args . labels . includes ( "desktop" ) ) {
49- throw new Error ( "Only desktop issues should be assigned to adamdotdevin " )
73+ if ( labels . includes ( "zen" ) && ! zen ) {
74+ throw new Error ( "Only add the zen label when issue title/body contains 'zen' " )
5075 }
5176
52- if ( args . assignee === "fwang" && ! args . labels . includes ( "zen" ) ) {
53- throw new Error ( "Only zen issues should be assigned to fwang " )
77+ if ( web && ! nix && ! ( TEAM . desktop as readonly string [ ] ) . includes ( assignee ) ) {
78+ throw new Error ( "Web issues must be assigned to adamdotdevin, iamdavidhill, Brendonovich, or nexxeln " )
5479 }
5580
56- if ( args . assignee === "kommander" && ! args . labels . includes ( "opentui" ) ) {
81+ if ( ( TEAM . zen as readonly string [ ] ) . includes ( assignee ) && ! labels . includes ( "zen" ) ) {
82+ throw new Error ( "Only zen issues should be assigned to fwang or MrMushrooooom" )
83+ }
84+
85+ if ( assignee === "Hona" && ! labels . includes ( "windows" ) ) {
86+ throw new Error ( "Only windows issues should be assigned to Hona" )
87+ }
88+
89+ if ( assignee === "R44VC0RP" && ! labels . includes ( "docs" ) ) {
90+ throw new Error ( "Only docs issues should be assigned to R44VC0RP" )
91+ }
92+
93+ if ( assignee === "kommander" && ! labels . includes ( "opentui" ) ) {
5794 throw new Error ( "Only opentui issues should be assigned to kommander" )
5895 }
5996
60- // await octokit.rest.issues.addAssignees({
61- // owner,
62- // repo,
63- // issue_number: issue,
64- // assignees: [args.assignee],
65- // })
6697 await githubFetch ( `/repos/${ owner } /${ repo } /issues/${ issue } /assignees` , {
6798 method : "POST" ,
68- body : JSON . stringify ( { assignees : [ args . assignee ] } ) ,
99+ body : JSON . stringify ( { assignees : [ assignee ] } ) ,
69100 } )
70- results . push ( `Assigned @${ args . assignee } to issue #${ issue } ` )
71-
72- const labels : string [ ] = args . labels . map ( ( label ) => ( label === "desktop" ? "web" : label ) )
101+ results . push ( `Assigned @${ assignee } to issue #${ issue } ` )
73102
74103 if ( labels . length > 0 ) {
75- // await octokit.rest.issues.addLabels({
76- // owner,
77- // repo,
78- // issue_number: issue,
79- // labels,
80- // })
81104 await githubFetch ( `/repos/${ owner } /${ repo } /issues/${ issue } /labels` , {
82105 method : "POST" ,
83106 body : JSON . stringify ( { labels } ) ,
84107 } )
85- results . push ( `Added labels: ${ args . labels . join ( ", " ) } ` )
108+ results . push ( `Added labels: ${ labels . join ( ", " ) } ` )
86109 }
87110
88111 return results . join ( "\n" )
0 commit comments