mirror of
https://github.com/taigrr/github-to-signal.git
synced 2026-04-17 10:54:44 -07:00
feat: add event type and action filtering
Configure which events to forward via comma-separated 'events' config.
Supports event-level ('push', 'pull_request') or event:action-level
('pull_request:opened', 'issues:closed') filtering.
Empty/omitted = forward everything (backwards compatible).
This commit is contained in:
32
filter_test.go
Normal file
32
filter_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEventFilter(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
filters []string
|
||||
event string
|
||||
action string
|
||||
want bool
|
||||
}{
|
||||
{"empty allows all", nil, "push", "", true},
|
||||
{"event only", []string{"push"}, "push", "", true},
|
||||
{"event only blocks other", []string{"push"}, "issues", "opened", false},
|
||||
{"event:action match", []string{"pull_request:opened"}, "pull_request", "opened", true},
|
||||
{"event:action no match", []string{"pull_request:opened"}, "pull_request", "closed", false},
|
||||
{"multiple actions", []string{"pull_request:opened", "pull_request:closed"}, "pull_request", "closed", true},
|
||||
{"mixed event and action", []string{"push", "pull_request:opened"}, "push", "", true},
|
||||
{"mixed blocks filtered", []string{"push", "pull_request:opened"}, "pull_request", "closed", false},
|
||||
{"case insensitive", []string{"Pull_Request:Opened"}, "pull_request", "opened", true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ef := ParseEventFilter(tt.filters)
|
||||
if got := ef.Allowed(tt.event, tt.action); got != tt.want {
|
||||
t.Errorf("Allowed(%q, %q) = %v, want %v", tt.event, tt.action, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user