mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-15 02:01:43 +03:00
cache: doc & cleaning
This commit is contained in:
parent
ece9e39461
commit
c8239a990b
6
cache/filter.go
vendored
6
cache/filter.go
vendored
@ -6,8 +6,10 @@ import (
|
|||||||
"github.com/MichaelMure/git-bug/bug"
|
"github.com/MichaelMure/git-bug/bug"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Filter is a functor that match a subset of bugs
|
||||||
type Filter func(excerpt *BugExcerpt) bool
|
type Filter func(excerpt *BugExcerpt) bool
|
||||||
|
|
||||||
|
// StatusFilter return a Filter that match a bug status
|
||||||
func StatusFilter(query string) (Filter, error) {
|
func StatusFilter(query string) (Filter, error) {
|
||||||
status, err := bug.StatusFromString(query)
|
status, err := bug.StatusFromString(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -19,6 +21,7 @@ func StatusFilter(query string) (Filter, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthorFilter return a Filter that match a bug author
|
||||||
func AuthorFilter(query string) Filter {
|
func AuthorFilter(query string) Filter {
|
||||||
cleaned := strings.TrimFunc(query, func(r rune) bool {
|
cleaned := strings.TrimFunc(query, func(r rune) bool {
|
||||||
return r == '"' || r == '\''
|
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 {
|
func LabelFilter(label string) Filter {
|
||||||
return func(excerpt *BugExcerpt) bool {
|
return func(excerpt *BugExcerpt) bool {
|
||||||
for _, l := range excerpt.Labels {
|
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 {
|
func NoLabelFilter() Filter {
|
||||||
return func(excerpt *BugExcerpt) bool {
|
return func(excerpt *BugExcerpt) bool {
|
||||||
return len(excerpt.Labels) == 0
|
return len(excerpt.Labels) == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filters is a collection of Filter that implement a complex filter
|
||||||
type Filters struct {
|
type Filters struct {
|
||||||
Status []Filter
|
Status []Filter
|
||||||
Author []Filter
|
Author []Filter
|
||||||
|
2
cache/query.go
vendored
2
cache/query.go
vendored
@ -16,7 +16,7 @@ type Query struct {
|
|||||||
//
|
//
|
||||||
// Ex: "status:open author:descartes sort:edit-asc"
|
// 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) {
|
func ParseQuery(query string) (*Query, error) {
|
||||||
fields := splitQuery(query)
|
fields := splitQuery(query)
|
||||||
|
|
||||||
|
5
cache/query_test.go
vendored
5
cache/query_test.go
vendored
@ -3,6 +3,7 @@ package cache
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestQueryParse(t *testing.T) {
|
func TestQueryParse(t *testing.T) {
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
input string
|
input string
|
||||||
ok bool
|
ok bool
|
||||||
@ -16,10 +17,10 @@ func TestQueryParse(t *testing.T) {
|
|||||||
{"status:unknown", false},
|
{"status:unknown", false},
|
||||||
|
|
||||||
{"author:rene", true},
|
{"author:rene", true},
|
||||||
{"author:\"René Descartes\"", true},
|
{`author:"René Descartes"`, true},
|
||||||
|
|
||||||
{"label:hello", true},
|
{"label:hello", true},
|
||||||
{"label:\"Good first issue\"", true},
|
{`label:"Good first issue"`, true},
|
||||||
|
|
||||||
{"sort:edit", true},
|
{"sort:edit", true},
|
||||||
{"sort:unknown", false},
|
{"sort:unknown", false},
|
||||||
|
4
cache/repo_cache.go
vendored
4
cache/repo_cache.go
vendored
@ -387,7 +387,7 @@ func repoIsAvailable(repo repository.Repo) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(buf) == 10 {
|
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))
|
pid, err := strconv.Atoi(string(buf))
|
||||||
@ -396,7 +396,7 @@ func repoIsAvailable(repo repository.Repo) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if util.ProcessIsRunning(pid) {
|
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
|
// The lock file is just laying there after a crash, clean it
|
||||||
|
Loading…
Reference in New Issue
Block a user