aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-03 15:27:29 +0100
committerGitHub <noreply@github.com>2019-03-03 15:27:29 +0100
commitfe8b0659c9bc1cb074a5acfbafcabd603e533f9f (patch)
treeb3d8db1596b7347fdcf39cfdc9614a3c09464b36 /cache
parent7260ca05bc3588c0572887a7d8f1b897c7fc13da (diff)
parent408654514ea813933f45d383d949611d138084e1 (diff)
downloadgit-bug-fe8b0659c9bc1cb074a5acfbafcabd603e533f9f.tar.gz
Merge pull request #100 from sladyn98/faster_ls
`git bug ls` should be faster
Diffstat (limited to 'cache')
-rw-r--r--cache/bug_excerpt.go8
-rw-r--r--cache/filter.go15
-rw-r--r--cache/filter_test.go34
-rw-r--r--cache/query.go4
-rw-r--r--cache/query_test.go3
5 files changed, 62 insertions, 2 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go
index fd06e51b..a50d8c66 100644
--- a/cache/bug_excerpt.go
+++ b/cache/bug_excerpt.go
@@ -23,8 +23,10 @@ type BugExcerpt struct {
CreateUnixTime int64
EditUnixTime int64
- Status bug.Status
- Labels []bug.Label
+ Status bug.Status
+ Labels []bug.Label
+ Title string
+ LenComments int
// If author is identity.Bare, LegacyAuthor is set
// If author is identity.Identity, AuthorId is set and data is deported
@@ -50,6 +52,8 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt {
EditUnixTime: snap.LastEditUnix(),
Status: snap.Status,
Labels: snap.Labels,
+ Title: snap.Title,
+ LenComments: len(snap.Comments),
CreateMetadata: b.FirstOp().AllMetadata(),
}
diff --git a/cache/filter.go b/cache/filter.go
index 022a8ff2..b6872508 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -55,6 +55,16 @@ func LabelFilter(label string) Filter {
}
}
+// TitleFilter return a Filter that match if the title contains the given query
+func TitleFilter(query string) Filter {
+ return func(repo *RepoCache, excerpt *BugExcerpt) bool {
+ return strings.Contains(
+ strings.ToLower(excerpt.Title),
+ strings.ToLower(query),
+ )
+ }
+}
+
// NoLabelFilter return a Filter that match the absence of labels
func NoLabelFilter() Filter {
return func(repoCache *RepoCache, excerpt *BugExcerpt) bool {
@@ -67,6 +77,7 @@ type Filters struct {
Status []Filter
Author []Filter
Label []Filter
+ Title []Filter
NoFilters []Filter
}
@@ -88,6 +99,10 @@ func (f *Filters) Match(repoCache *RepoCache, excerpt *BugExcerpt) bool {
return false
}
+ if match := f.andMatch(f.Title, repoCache, excerpt); !match {
+ return false
+ }
+
return true
}
diff --git a/cache/filter_test.go b/cache/filter_test.go
new file mode 100644
index 00000000..a47d2ad7
--- /dev/null
+++ b/cache/filter_test.go
@@ -0,0 +1,34 @@
+package cache
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestTitleFilter(t *testing.T) {
+ tests := []struct {
+ name string
+ title string
+ query string
+ match bool
+ }{
+ {name: "complete match", title: "hello world", query: "hello world", match: true},
+ {name: "partial match", title: "hello world", query: "hello", match: true},
+ {name: "no match", title: "hello world", query: "foo", match: false},
+ {name: "cased title", title: "Hello World", query: "hello", match: true},
+ {name: "cased query", title: "hello world", query: "Hello", match: true},
+
+ // Those following tests should work eventually but are left for a future iteration.
+
+ // {name: "cased accents", title: "ÑOÑO", query: "ñoño", match: true},
+ // {name: "natural language matching", title: "Århus", query: "Aarhus", match: true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filter := TitleFilter(tt.query)
+ excerpt := &BugExcerpt{Title: tt.title}
+ assert.Equal(t, tt.match, filter(nil, excerpt))
+ })
+ }
+}
diff --git a/cache/query.go b/cache/query.go
index 6ffa6510..39815d32 100644
--- a/cache/query.go
+++ b/cache/query.go
@@ -60,6 +60,10 @@ func ParseQuery(query string) (*Query, error) {
f := LabelFilter(qualifierQuery)
result.Label = append(result.Label, f)
+ case "title":
+ f := TitleFilter(qualifierQuery)
+ result.Label = append(result.Title, f)
+
case "no":
err := result.parseNoFilter(qualifierQuery)
if err != nil {
diff --git a/cache/query_test.go b/cache/query_test.go
index 29d2f585..f34b3e6a 100644
--- a/cache/query_test.go
+++ b/cache/query_test.go
@@ -22,6 +22,9 @@ func TestQueryParse(t *testing.T) {
{"label:hello", true},
{`label:"Good first issue"`, true},
+ {"title:titleOne", true},
+ {`title:"Bug titleTwo"`, true},
+
{"sort:edit", true},
{"sort:unknown", false},
}