Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cache/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func AuthorFilter(query string) Filter {
}
}

// MetadataFilter return a Filter that match a bug metadata at creation time
func MetadataFilter(pair query.StringPair) Filter {
return func(excerpt *BugExcerpt, resolver resolver) bool {
if value, ok := excerpt.CreateMetadata[pair.Key]; ok {
return value == pair.Value
}
return false
}
}

// LabelFilter return a Filter that match a label
func LabelFilter(label string) Filter {
return func(excerpt *BugExcerpt, resolver resolver) bool {
Expand Down Expand Up @@ -109,6 +119,7 @@ func NoLabelFilter() Filter {
type Matcher struct {
Status []Filter
Author []Filter
Metadata []Filter
Actor []Filter
Participant []Filter
Label []Filter
Expand All @@ -127,6 +138,9 @@ func compileMatcher(filters query.Filters) *Matcher {
for _, value := range filters.Author {
result.Author = append(result.Author, AuthorFilter(value))
}
for _, value := range filters.Metadata {
result.Metadata = append(result.Metadata, MetadataFilter(value))
}
for _, value := range filters.Actor {
result.Actor = append(result.Actor, ActorFilter(value))
}
Expand All @@ -153,6 +167,10 @@ func (f *Matcher) Match(excerpt *BugExcerpt, resolver resolver) bool {
return false
}

if match := f.orMatch(f.Metadata, excerpt, resolver); !match {
return false
}

if match := f.orMatch(f.Participant, excerpt, resolver); !match {
return false
}
Expand Down
13 changes: 13 additions & 0 deletions commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type lsOptions struct {
statusQuery []string
authorQuery []string
metadataQuery []string
participantQuery []string
actorQuery []string
labelQuery []string
Expand Down Expand Up @@ -65,6 +66,8 @@ git bug ls status:open --by creation "foo bar" baz
"Filter by status. Valid values are [open,closed]")
flags.StringSliceVarP(&options.authorQuery, "author", "a", nil,
"Filter by author")
flags.StringSliceVarP(&options.metadataQuery, "metadata", "m", nil,
Comment thread
MichaelMure marked this conversation as resolved.
"Filter by metadata. Example: github-url=URL")
flags.StringSliceVarP(&options.participantQuery, "participant", "p", nil,
"Filter by participant")
flags.StringSliceVarP(&options.actorQuery, "actor", "A", nil,
Expand Down Expand Up @@ -337,6 +340,16 @@ func completeQuery(q *query.Query, opts lsOptions) error {
}

q.Author = append(q.Author, opts.authorQuery...)
for _, str := range opts.metadataQuery {
tokens := strings.Split(str, "=")
if len(tokens) < 2 {
return fmt.Errorf("no \"=\" in key=value metadata markup")
}
var pair query.StringPair
pair.Key = tokens[0]
pair.Value = tokens[1]
q.Metadata = append(q.Metadata, pair)
}
q.Participant = append(q.Participant, opts.participantQuery...)
q.Actor = append(q.Actor, opts.actorQuery...)
q.Label = append(q.Label, opts.labelQuery...)
Expand Down
4 changes: 4 additions & 0 deletions doc/man/git-bug-ls.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ You can pass an additional query to filter and order the list. This query can be
\fB\-a\fP, \fB\-\-author\fP=[]
Filter by author

.PP
\fB\-m\fP, \fB\-\-metadata\fP=[]
Filter by metadata. Example: github\-url=URL

.PP
\fB\-p\fP, \fB\-\-participant\fP=[]
Filter by participant
Expand Down
1 change: 1 addition & 0 deletions doc/md/git-bug_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ git bug ls status:open --by creation "foo bar" baz
```
-s, --status strings Filter by status. Valid values are [open,closed]
-a, --author strings Filter by author
-m, --metadata strings Filter by metadata. Example: github-url=URL
-p, --participant strings Filter by participant
-A, --actor strings Filter by actor
-l, --label strings Filter by label
Expand Down
9 changes: 0 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ require (
github.com/blevesearch/bleve v1.0.14
github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9
github.com/corpix/uarand v0.1.1 // indirect
github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/fatih/color v1.10.0
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.2.0
Expand All @@ -28,17 +22,14 @@ require (
github.com/hashicorp/golang-lru v0.5.4
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/imdario/mergo v0.3.11 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.12
github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5
github.com/pkg/errors v0.9.1
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/shurcooL/githubv4 v0.0.0-20190601194912-068505affed7
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.7.0
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/vektah/gqlparser v1.3.1
github.com/xanzy/go-gitlab v0.40.1
github.com/xanzy/ssh-agent v0.3.0 // indirect
Expand Down
Loading