Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author filter #267

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/hubbub/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
26 changes: 26 additions & 0 deletions pkg/provider/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pkg/triage/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down