aboutsummaryrefslogtreecommitdiffstats
path: root/cache/filter.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-01 23:17:57 +0100
committerGitHub <noreply@github.com>2019-03-01 23:17:57 +0100
commit7260ca05bc3588c0572887a7d8f1b897c7fc13da (patch)
tree66854358df3cb9de651f7688556ec5a4b8ab1868 /cache/filter.go
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
parentb6bed784e5664819250aac20b2b9690879ee6ab1 (diff)
downloadgit-bug-7260ca05bc3588c0572887a7d8f1b897c7fc13da.tar.gz
Merge pull request #89 from MichaelMure/identity
WIP identity in git
Diffstat (limited to 'cache/filter.go')
-rw-r--r--cache/filter.go49
1 files changed, 33 insertions, 16 deletions
diff --git a/cache/filter.go b/cache/filter.go
index 033df131..022a8ff2 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -1,11 +1,13 @@
package cache
import (
+ "strings"
+
"github.com/MichaelMure/git-bug/bug"
)
-// Filter is a functor that match a subset of bugs
-type Filter func(excerpt *BugExcerpt) bool
+// Filter is a predicate that match a subset of bugs
+type Filter func(repoCache *RepoCache, excerpt *BugExcerpt) bool
// StatusFilter return a Filter that match a bug status
func StatusFilter(query string) (Filter, error) {
@@ -14,21 +16,36 @@ func StatusFilter(query string) (Filter, error) {
return nil, err
}
- return func(excerpt *BugExcerpt) bool {
+ return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
return excerpt.Status == status
}, nil
}
// AuthorFilter return a Filter that match a bug author
func AuthorFilter(query string) Filter {
- return func(excerpt *BugExcerpt) bool {
- return excerpt.Author.Match(query)
+ return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
+ query = strings.ToLower(query)
+
+ // Normal identity
+ if excerpt.AuthorId != "" {
+ author, ok := repoCache.identitiesExcerpts[excerpt.AuthorId]
+ if !ok {
+ panic("missing identity in the cache")
+ }
+
+ return strings.Contains(strings.ToLower(author.Name), query) ||
+ strings.Contains(strings.ToLower(author.Login), query)
+ }
+
+ // Legacy identity support
+ return strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Name), query) ||
+ strings.Contains(strings.ToLower(excerpt.LegacyAuthor.Login), query)
}
}
// LabelFilter return a Filter that match a label
func LabelFilter(label string) Filter {
- return func(excerpt *BugExcerpt) bool {
+ return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
for _, l := range excerpt.Labels {
if string(l) == label {
return true
@@ -40,7 +57,7 @@ func LabelFilter(label string) Filter {
// NoLabelFilter return a Filter that match the absence of labels
func NoLabelFilter() Filter {
- return func(excerpt *BugExcerpt) bool {
+ return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
return len(excerpt.Labels) == 0
}
}
@@ -54,20 +71,20 @@ type Filters struct {
}
// Match check if a bug match the set of filters
-func (f *Filters) Match(excerpt *BugExcerpt) bool {
- if match := f.orMatch(f.Status, excerpt); !match {
+func (f *Filters) Match(repoCache *RepoCache, excerpt *BugExcerpt) bool {
+ if match := f.orMatch(f.Status, repoCache, excerpt); !match {
return false
}
- if match := f.orMatch(f.Author, excerpt); !match {
+ if match := f.orMatch(f.Author, repoCache, excerpt); !match {
return false
}
- if match := f.orMatch(f.Label, excerpt); !match {
+ if match := f.orMatch(f.Label, repoCache, excerpt); !match {
return false
}
- if match := f.andMatch(f.NoFilters, excerpt); !match {
+ if match := f.andMatch(f.NoFilters, repoCache, excerpt); !match {
return false
}
@@ -75,28 +92,28 @@ func (f *Filters) Match(excerpt *BugExcerpt) bool {
}
// Check if any of the filters provided match the bug
-func (*Filters) orMatch(filters []Filter, excerpt *BugExcerpt) bool {
+func (*Filters) orMatch(filters []Filter, repoCache *RepoCache, excerpt *BugExcerpt) bool {
if len(filters) == 0 {
return true
}
match := false
for _, f := range filters {
- match = match || f(excerpt)
+ match = match || f(repoCache, excerpt)
}
return match
}
// Check if all of the filters provided match the bug
-func (*Filters) andMatch(filters []Filter, excerpt *BugExcerpt) bool {
+func (*Filters) andMatch(filters []Filter, repoCache *RepoCache, excerpt *BugExcerpt) bool {
if len(filters) == 0 {
return true
}
match := true
for _, f := range filters {
- match = match && f(excerpt)
+ match = match && f(repoCache, excerpt)
}
return match