aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-10 12:47:05 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-10 12:47:05 +0200
commitc8239a990b9babe071f08b78ad0195f01550d628 (patch)
treecce35c80f584a66fde4b659b5be15857e1b2e6d4
parentece9e39461bb40df979c22092873eff014fc1648 (diff)
downloadgit-bug-c8239a990b9babe071f08b78ad0195f01550d628.tar.gz
cache: doc & cleaning
-rw-r--r--cache/filter.go6
-rw-r--r--cache/query.go2
-rw-r--r--cache/query_test.go5
-rw-r--r--cache/repo_cache.go4
4 files changed, 12 insertions, 5 deletions
diff --git a/cache/filter.go b/cache/filter.go
index 91ab20c0..3bcfe13e 100644
--- a/cache/filter.go
+++ b/cache/filter.go
@@ -6,8 +6,10 @@ import (
"github.com/MichaelMure/git-bug/bug"
)
+// Filter is a functor that match a subset of bugs
type Filter func(excerpt *BugExcerpt) bool
+// StatusFilter return a Filter that match a bug status
func StatusFilter(query string) (Filter, error) {
status, err := bug.StatusFromString(query)
if err != nil {
@@ -19,6 +21,7 @@ func StatusFilter(query string) (Filter, error) {
}, nil
}
+// AuthorFilter return a Filter that match a bug author
func AuthorFilter(query string) Filter {
cleaned := strings.TrimFunc(query, func(r rune) bool {
return r == '"' || r == '\''
@@ -29,6 +32,7 @@ func AuthorFilter(query string) Filter {
}
}
+// LabelFilter return a Filter that match a label
func LabelFilter(label string) Filter {
return func(excerpt *BugExcerpt) bool {
for _, l := range excerpt.Labels {
@@ -40,12 +44,14 @@ func LabelFilter(label string) Filter {
}
}
+// NoLabelFilter return a Filter that match the absence of labels
func NoLabelFilter() Filter {
return func(excerpt *BugExcerpt) bool {
return len(excerpt.Labels) == 0
}
}
+// Filters is a collection of Filter that implement a complex filter
type Filters struct {
Status []Filter
Author []Filter
diff --git a/cache/query.go b/cache/query.go
index 14ef0bae..5be8f43d 100644
--- a/cache/query.go
+++ b/cache/query.go
@@ -16,7 +16,7 @@ type Query struct {
//
// Ex: "status:open author:descartes sort:edit-asc"
//
-// Supported filter fields and syntax are described in docs/queries.md
+// Supported filter qualifiers and syntax are described in docs/queries.md
func ParseQuery(query string) (*Query, error) {
fields := splitQuery(query)
diff --git a/cache/query_test.go b/cache/query_test.go
index 646a6d73..29d2f585 100644
--- a/cache/query_test.go
+++ b/cache/query_test.go
@@ -3,6 +3,7 @@ package cache
import "testing"
func TestQueryParse(t *testing.T) {
+
var tests = []struct {
input string
ok bool
@@ -16,10 +17,10 @@ func TestQueryParse(t *testing.T) {
{"status:unknown", false},
{"author:rene", true},
- {"author:\"René Descartes\"", true},
+ {`author:"René Descartes"`, true},
{"label:hello", true},
- {"label:\"Good first issue\"", true},
+ {`label:"Good first issue"`, true},
{"sort:edit", true},
{"sort:unknown", false},
diff --git a/cache/repo_cache.go b/cache/repo_cache.go
index af9c5070..f0c9ac4a 100644
--- a/cache/repo_cache.go
+++ b/cache/repo_cache.go
@@ -387,7 +387,7 @@ func repoIsAvailable(repo repository.Repo) error {
return err
}
if len(buf) == 10 {
- return fmt.Errorf("The lock file should be < 10 bytes")
+ return fmt.Errorf("the lock file should be < 10 bytes")
}
pid, err := strconv.Atoi(string(buf))
@@ -396,7 +396,7 @@ func repoIsAvailable(repo repository.Repo) error {
}
if util.ProcessIsRunning(pid) {
- return fmt.Errorf("The repository you want to access is already locked by the process pid %d", pid)
+ return fmt.Errorf("the repository you want to access is already locked by the process pid %d", pid)
}
// The lock file is just laying there after a crash, clean it