Push rule evaluation tweaks (#2897)

This tweaks push rule evaluation:

1. to be more strict around pattern matching and to not match empty
patterns
3. to bail if we come across a `dont_notify`, since cycles after that
are wasted
4. refactors `ActionsToTweaks` to make a bit more sense
This commit is contained in:
Neil Alexander 2022-11-30 12:54:37 +00:00 committed by GitHub
parent ac5f3f025e
commit f009e54181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 19 deletions

View file

@ -11,22 +11,27 @@ import (
// kind and a tweaks map. Returns a nil map if it would have been
// empty.
func ActionsToTweaks(as []*Action) (ActionKind, map[string]interface{}, error) {
kind := UnknownAction
tweaks := map[string]interface{}{}
var kind ActionKind
var tweaks map[string]interface{}
for _, a := range as {
if a.Kind == SetTweakAction {
tweaks[string(a.Tweak)] = a.Value
continue
}
if kind != UnknownAction {
return UnknownAction, nil, fmt.Errorf("got multiple primary actions: already had %q, got %s", kind, a.Kind)
}
kind = a.Kind
}
switch a.Kind {
case DontNotifyAction:
// Don't bother processing any further
return DontNotifyAction, nil, nil
if len(tweaks) == 0 {
tweaks = nil
case SetTweakAction:
if tweaks == nil {
tweaks = map[string]interface{}{}
}
tweaks[string(a.Tweak)] = a.Value
default:
if kind != UnknownAction {
return UnknownAction, nil, fmt.Errorf("got multiple primary actions: already had %q, got %s", kind, a.Kind)
}
kind = a.Kind
}
}
return kind, tweaks, nil