From b1e2ec6d267668ddc2a5026b04c5090cdde3ba8a Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Tue, 8 Jun 2021 11:29:57 +0200 Subject: [PATCH] Add author filter --- pkg/hubbub/match.go | 7 +++++++ pkg/provider/filter.go | 26 ++++++++++++++++++++++++++ pkg/triage/triage.go | 7 +++++++ 3 files changed, 40 insertions(+) diff --git a/pkg/hubbub/match.go b/pkg/hubbub/match.go index ca279eb..1287f80 100644 --- a/pkg/hubbub/match.go +++ b/pkg/hubbub/match.go @@ -78,6 +78,13 @@ func preFetchMatch(i provider.IItem, labels []*provider.Label, fs []provider.Fil } } + if f.AuthorRegex() != nil { + if ok := matchNegateRegex(*i.GetUser().Login, f.AuthorRegex(), f.AuthorNegate()); !ok { + klog.V(2).Infof("#%d author does not meet %s", i.GetNumber(), f.AuthorRegex()) + return false + } + } + if f.LabelRegex() != nil { if ok := matchLabel(labels, f.LabelRegex(), f.LabelNegate()); !ok { klog.V(2).Infof("#%d labels do not meet %s", i.GetNumber(), f.LabelRegex()) diff --git a/pkg/provider/filter.go b/pkg/provider/filter.go index fd1b621..689126c 100644 --- a/pkg/provider/filter.go +++ b/pkg/provider/filter.go @@ -40,6 +40,10 @@ type Filter struct { milestoneRegex *regexp.Regexp milestoneNegate bool + RawAuthor string `yaml:"author,omitempty"` + authorRegex *regexp.Regexp + authorNegate bool + Created string `yaml:"created,omitempty"` Updated string `yaml:"updated,omitempty"` Closed string `yaml:"closed,omitempty"` @@ -121,6 +125,28 @@ func (f *Filter) TitleNegate() bool { return f.titleNegate } +// LoadAuthorRegex loads a new author regex +func (f *Filter) LoadAuthorRegex() error { + r, negateState := negativeMatch(f.RawAuthor) + + re, err := regex(r) + if err != nil { + return err + } + + f.authorRegex = re + f.authorNegate = negateState + return nil +} + +func (f *Filter) AuthorRegex() *regexp.Regexp { + return f.authorRegex +} + +func (f *Filter) AuthorNegate() bool { + return f.authorNegate +} + // LoadMilestoneRegex loads a new milestone regex func (f *Filter) LoadMilestoneRegex() error { r, negateState := negativeMatch(f.RawMilestone) diff --git a/pkg/triage/triage.go b/pkg/triage/triage.go index 3b10041..ebc4ba1 100644 --- a/pkg/triage/triage.go +++ b/pkg/triage/triage.go @@ -322,6 +322,13 @@ func processRules(raw map[string]Rule) (map[string]Rule, error) { } } + if f.RawAuthor != "" { + err := f.LoadAuthorRegex() + if err != nil { + return rules, fmt.Errorf("%q author: %w", id, err) + } + } + newfs = append(newfs, f) }