@@ -20,6 +20,9 @@ export interface LinearAutoCreateDependencies {
2020 fetchIssues ?: typeof fetchAssignedIssues ;
2121 /** Optional handler for the `webmux_oneshot` label variant. When omitted, oneshot triggering is skipped. */
2222 runOneshotForIssue ?: ( issueId : string ) => Promise < void > ;
23+ /** Restrict triggering to issues whose team.key is in this list (uppercase).
24+ * Undefined or empty → no team filter (all teams). */
25+ watchTeamKeys ?: string [ ] ;
2326}
2427
2528export interface LinearAutoCreateMonitorOptions {
@@ -37,16 +40,25 @@ function hasLabel(issue: LinearIssue, name: string): boolean {
3740 return issue . labels . some ( ( l ) => l . name . toLowerCase ( ) === name ) ;
3841}
3942
43+ function matchesTeamFilter ( issue : LinearIssue , watchTeamKeys : string [ ] | undefined ) : boolean {
44+ if ( ! watchTeamKeys || watchTeamKeys . length === 0 ) return true ;
45+ const issueKey = issue . team . key . toUpperCase ( ) ;
46+ return watchTeamKeys . some ( ( key ) => key . toUpperCase ( ) === issueKey ) ;
47+ }
48+
4049/** Shared filter: Todo state, the label rule supplied by the caller, not yet
41- * processed, and no existing worktree on the branch. */
50+ * processed, no existing worktree on the branch, and (when configured) the
51+ * issue's team is in the watch list. */
4252function filterTriggerableIssues (
4353 issues : LinearIssue [ ] ,
4454 existingBranches : string [ ] ,
4555 matchesLabelRule : ( issue : LinearIssue ) => boolean ,
56+ watchTeamKeys ?: string [ ] ,
4657) : LinearIssue [ ] {
4758 return issues . filter ( ( issue ) => {
4859 if ( issue . state . name !== "Todo" ) return false ;
4960 if ( ! matchesLabelRule ( issue ) ) return false ;
61+ if ( ! matchesTeamFilter ( issue , watchTeamKeys ) ) return false ;
5062 if ( processedIssueIds . has ( issue . id ) ) return false ;
5163 return ! existingBranches . some ( ( branch ) => branchMatchesIssue ( branch , issue . branchName ) ) ;
5264 } ) ;
@@ -57,11 +69,13 @@ function filterTriggerableIssues(
5769export function filterAutoCreateIssues (
5870 issues : LinearIssue [ ] ,
5971 existingBranches : string [ ] ,
72+ watchTeamKeys ?: string [ ] ,
6073) : LinearIssue [ ] {
6174 return filterTriggerableIssues (
6275 issues ,
6376 existingBranches ,
6477 ( issue ) => hasLabel ( issue , AUTO_CREATE_LABEL ) && ! hasLabel ( issue , AUTO_ONESHOT_LABEL ) ,
78+ watchTeamKeys ,
6579 ) ;
6680}
6781
@@ -71,11 +85,13 @@ export function filterAutoCreateIssues(
7185export function filterAutoOneshotIssues (
7286 issues : LinearIssue [ ] ,
7387 existingBranches : string [ ] ,
88+ watchTeamKeys ?: string [ ] ,
7489) : LinearIssue [ ] {
7590 return filterTriggerableIssues (
7691 issues ,
7792 existingBranches ,
7893 ( issue ) => hasLabel ( issue , AUTO_ONESHOT_LABEL ) ,
94+ watchTeamKeys ,
7995 ) ;
8096}
8197
@@ -114,9 +130,9 @@ export async function runLinearAutoCreateOnce(deps: LinearAutoCreateDependencies
114130 . map ( ( entry ) => entry . branch as string ) ;
115131
116132 const oneshotIssues = deps . runOneshotForIssue
117- ? filterAutoOneshotIssues ( result . data , existingBranches )
133+ ? filterAutoOneshotIssues ( result . data , existingBranches , deps . watchTeamKeys )
118134 : [ ] ;
119- const createIssues = filterAutoCreateIssues ( result . data , existingBranches ) ;
135+ const createIssues = filterAutoCreateIssues ( result . data , existingBranches , deps . watchTeamKeys ) ;
120136
121137 if ( oneshotIssues . length === 0 && createIssues . length === 0 ) {
122138 log . debug ( `[linear-auto-create] no new labeled issues (${ result . data . length } assigned, ${ existingBranches . length } worktrees)` ) ;
0 commit comments