@@ -2,7 +2,7 @@ import { z } from "zod";
22import { AutomodTriggerBlueprint , AutomodTriggerMatchResult , automodTrigger } from "../helpers.js" ;
33
44interface NotTriggerMatchResultExtra {
5- triggerName : string ;
5+ triggerNames : string [ ] ;
66}
77
88interface CreateNotTriggerOpts {
@@ -21,8 +21,8 @@ export function createNotTrigger({ getAvailableTriggers }: CreateNotTriggerOpts)
2121 return z
2222 . strictObject ( schemaShape )
2323 . partial ( )
24- . refine ( ( val ) => Object . values ( val ) . filter ( ( v ) => v !== undefined ) . length === 1 , {
25- message : "Not trigger must specify exactly one trigger" ,
24+ . refine ( ( val ) => Object . values ( val ) . some ( ( v ) => v !== undefined ) , {
25+ message : "Not trigger must specify at least one trigger" ,
2626 } ) ;
2727 } ) ;
2828
@@ -33,38 +33,52 @@ export function createNotTrigger({ getAvailableTriggers }: CreateNotTriggerOpts)
3333
3434 async match ( { ruleName, pluginData, context, triggerConfig } ) {
3535 const definedEntries = Object . entries ( triggerConfig . trigger ) . filter ( ( [ , v ] ) => v !== undefined ) ;
36- if ( definedEntries . length !== 1 ) {
36+ if ( definedEntries . length < 1 ) {
3737 return null ;
3838 }
3939
40- const [ subTriggerName , subTriggerConfig ] = definedEntries [ 0 ] ! ;
41- const subTrigger = getAvailableTriggers ( ) [ subTriggerName ] ;
42- if ( ! subTrigger ) {
43- return null ;
44- }
40+ const testedNames : string [ ] = [ ] ;
4541
46- const subMatch = await subTrigger . match ( {
47- ruleName,
48- pluginData,
49- context,
50- triggerConfig : subTriggerConfig ,
51- } ) ;
42+ for ( const [ subTriggerName , subTriggerConfig ] of definedEntries ) {
43+ const subTrigger = getAvailableTriggers ( ) [ subTriggerName ] ;
44+ if ( ! subTrigger ) {
45+ continue ;
46+ }
47+
48+ testedNames . push ( subTriggerName ) ;
49+
50+ const subMatch = await subTrigger . match ( {
51+ ruleName,
52+ pluginData,
53+ context,
54+ triggerConfig : subTriggerConfig ,
55+ } ) ;
5256
53- if ( subMatch ) {
57+ if ( subMatch ) {
58+ return null ;
59+ }
60+ }
61+
62+ if ( testedNames . length === 0 ) {
5463 return null ;
5564 }
5665
5766 const result : AutomodTriggerMatchResult < NotTriggerMatchResultExtra > = {
5867 extra : {
59- triggerName : subTriggerName ,
68+ triggerNames : testedNames ,
6069 } ,
6170 } ;
6271
6372 return result ;
6473 } ,
6574
6675 async renderMatchInformation ( { matchResult } ) {
67- return `Did not match ${ matchResult . extra . triggerName } ` ;
76+ const names = matchResult . extra . triggerNames ;
77+ if ( names . length === 1 ) {
78+ return `Did not match ${ names [ 0 ] } ` ;
79+ }
80+
81+ return `Did not match any of: ${ names . join ( ", " ) } ` ;
6882 } ,
6983 } ) ;
7084}
0 commit comments