diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-02-14 16:03:51 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-02-21 14:15:50 +0100 |
commit | cb61245078a0e8f14e359ed20e0582a695645a08 (patch) | |
tree | aa0e8f4ea3d8a5eb2f7ac3746875b0854c1714bb /cache/filter.go | |
parent | 956f98b676ab44d19ed522061c9520a32aab1a3c (diff) | |
download | git-bug-cb61245078a0e8f14e359ed20e0582a695645a08.tar.gz |
Add ability to search by arbitrary metadata
Example:
~/git/git-bug/git-bug ls --metadata github-url=https://github.com/author/myproject/issues/42
or
~/git/git-bug/git-bug ls metadata:github-url:\"https://github.com/author/myproject/issues/42\"
Fixes the cmdline part of <https://github.com/MichaelMure/git-bug/issues/567>.
Diffstat (limited to 'cache/filter.go')
-rw-r--r-- | cache/filter.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cache/filter.go b/cache/filter.go index 2ac56ab5..c167fe71 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -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 { @@ -109,6 +119,7 @@ func NoLabelFilter() Filter { type Matcher struct { Status []Filter Author []Filter + Metadata []Filter Actor []Filter Participant []Filter Label []Filter @@ -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)) } @@ -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 } |