aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cache/filter.go9
-rw-r--r--cache/filter_test.go34
-rw-r--r--doc/man/git-bug-ls.14
-rw-r--r--doc/md/git-bug_ls.md1
-rw-r--r--misc/bash_completion/git-bug3
5 files changed, 48 insertions, 3 deletions
diff --git a/cache/filter.go b/cache/filter.go
index fe6d200a..b6872508 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -55,10 +55,13 @@ func LabelFilter(label string) Filter {
}
}
-// TitleFilter return a Filter that match if the title contains the given pattern
-func TitleFilter(title 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(excerpt.Title, title)
+ return strings.Contains(
+ strings.ToLower(excerpt.Title),
+ strings.ToLower(query),
+ )
}
}
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/doc/man/git-bug-ls.1 b/doc/man/git-bug-ls.1
index eb985fd2..7b3a0aa6 100644
--- a/doc/man/git-bug-ls.1
+++ b/doc/man/git-bug-ls.1
@@ -35,6 +35,10 @@ You can pass an additional query to filter and order the list. This query can be
Filter by label
.PP
+\fB\-t\fP, \fB\-\-title\fP=[]
+ Filter by title
+
+.PP
\fB\-n\fP, \fB\-\-no\fP=[]
Filter by absence of something. Valid values are [label]
diff --git a/doc/md/git-bug_ls.md b/doc/md/git-bug_ls.md
index 18ac5d61..9ab71884 100644
--- a/doc/md/git-bug_ls.md
+++ b/doc/md/git-bug_ls.md
@@ -29,6 +29,7 @@ git bug ls --status closed --by creation
-s, --status strings Filter by status. Valid values are [open,closed]
-a, --author strings Filter by author
-l, --label strings Filter by label
+ -t, --title strings Filter by title
-n, --no strings Filter by absence of something. Valid values are [label]
-b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation")
-d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc")
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index a0ac545c..ec8c64ea 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -535,6 +535,9 @@ _git-bug_ls()
flags+=("--label=")
two_word_flags+=("-l")
local_nonpersistent_flags+=("--label=")
+ flags+=("--title=")
+ two_word_flags+=("-t")
+ local_nonpersistent_flags+=("--title=")
flags+=("--no=")
two_word_flags+=("-n")
local_nonpersistent_flags+=("--no=")