aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-04-04 12:58:20 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-04-04 17:21:40 +0200
commit682da55271b92deb148438450284403feaa21dcc (patch)
tree6d4ebcfd002c9c8b564eb0c102cbdaba0c2f7a0c /cache
parent2a5fbc4dc988d2eea76fe5e844ccf6425f9386ee (diff)
downloadgit-bug-682da55271b92deb148438450284403feaa21dcc.tar.gz
Improve actor/participant query filters
Lower case identity login
Diffstat (limited to 'cache')
-rw-r--r--cache/filter.go44
1 files changed, 26 insertions, 18 deletions
diff --git a/cache/filter.go b/cache/filter.go
index 48ee6678..7b1a6054 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -56,35 +56,43 @@ func LabelFilter(label string) Filter {
}
// ActorFilter return a Filter that match a bug actor
-func ActorFilter(actor string) Filter {
+func ActorFilter(query string) Filter {
return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
- for _, identityExcerpt := range repoCache.identitiesExcerpts {
- if strings.Contains(strings.ToLower(identityExcerpt.Name), actor) ||
- actor == identityExcerpt.Id || actor == identityExcerpt.Login {
- for _, actorId := range excerpt.Actors {
- if identityExcerpt.Id == actorId {
- return true
- }
- }
+ query = strings.ToLower(query)
+
+ for _, id := range excerpt.Actors {
+ identityExcerpt, ok := repoCache.identitiesExcerpts[id]
+ if !ok {
+ panic("missing identity in the cache")
+ }
+
+ if strings.Contains(strings.ToLower(identityExcerpt.Name), query) ||
+ query == identityExcerpt.Id || query == strings.ToLower(identityExcerpt.Login) {
+ return true
}
}
+
return false
}
}
// ParticipantFilter return a Filter that match a bug participant
-func ParticipantFilter(participant string) Filter {
+func ParticipantFilter(query string) Filter {
return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
- for _, identityExcerpt := range repoCache.identitiesExcerpts {
- if strings.Contains(strings.ToLower(identityExcerpt.Name), participant) ||
- participant == identityExcerpt.Id || participant == identityExcerpt.Login {
- for _, participantId := range excerpt.Participants {
- if identityExcerpt.Id == participantId {
- return true
- }
- }
+ query = strings.ToLower(query)
+
+ for _, id := range excerpt.Participants {
+ identityExcerpt, ok := repoCache.identitiesExcerpts[id]
+ if !ok {
+ panic("missing identity in the cache")
+ }
+
+ if strings.Contains(strings.ToLower(identityExcerpt.Name), query) ||
+ query == identityExcerpt.Id || query == strings.ToLower(identityExcerpt.Login) {
+ return true
}
}
+
return false
}
}