diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-03-31 22:32:35 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-04-04 00:37:57 +0200 |
commit | 2a5fbc4dc988d2eea76fe5e844ccf6425f9386ee (patch) | |
tree | 8e5125a64ff3d54fa304ae758ddbbcc427b368af /cache | |
parent | 5b0a92dea43f467f31a65a6f02e937d285cb0a71 (diff) | |
download | git-bug-2a5fbc4dc988d2eea76fe5e844ccf6425f9386ee.tar.gz |
Expose actors and participants in snapshot and bug excerpt
Append operations authors to each list on Apply() call
Expose actors and participants in graphql
Add actor/participant query filter and documentation
Diffstat (limited to 'cache')
-rw-r--r-- | cache/bug_excerpt.go | 22 | ||||
-rw-r--r-- | cache/filter.go | 54 | ||||
-rw-r--r-- | cache/query.go | 10 | ||||
-rw-r--r-- | cache/query_test.go | 3 |
4 files changed, 79 insertions, 10 deletions
diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go index a50d8c66..d78def4e 100644 --- a/cache/bug_excerpt.go +++ b/cache/bug_excerpt.go @@ -23,10 +23,12 @@ type BugExcerpt struct { CreateUnixTime int64 EditUnixTime int64 - Status bug.Status - Labels []bug.Label - Title string - LenComments int + Status bug.Status + Labels []bug.Label + Title string + LenComments int + Actors []string + Participants []string // If author is identity.Bare, LegacyAuthor is set // If author is identity.Identity, AuthorId is set and data is deported @@ -44,6 +46,16 @@ type LegacyAuthorExcerpt struct { } func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { + participantsIds := make([]string, len(snap.Participants)) + for i, participant := range snap.Participants { + participantsIds[i] = participant.Id() + } + + actorsIds := make([]string, len(snap.Actors)) + for i, actor := range snap.Actors { + actorsIds[i] = actor.Id() + } + e := &BugExcerpt{ Id: b.Id(), CreateLamportTime: b.CreateLamportTime(), @@ -52,6 +64,8 @@ func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { EditUnixTime: snap.LastEditUnix(), Status: snap.Status, Labels: snap.Labels, + Actors: actorsIds, + Participants: participantsIds, Title: snap.Title, LenComments: len(snap.Comments), CreateMetadata: b.FirstOp().AllMetadata(), diff --git a/cache/filter.go b/cache/filter.go index 7f010608..48ee6678 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -55,6 +55,40 @@ func LabelFilter(label string) Filter { } } +// ActorFilter return a Filter that match a bug actor +func ActorFilter(actor string) Filter { + return func(repoCache *RepoCache, excerpt *BugExcerpt) bool { + for _, identityExcerpt := range repoCache.identitiesExcerpts { + if strings.Contains(strings.ToLower(identityExcerpt.Name), actor) || + actor == identityExcerpt.Id || actor == identityExcerpt.Login { + for _, actorId := range excerpt.Actors { + if identityExcerpt.Id == actorId { + return true + } + } + } + } + return false + } +} + +// ParticipantFilter return a Filter that match a bug participant +func ParticipantFilter(participant string) Filter { + return func(repoCache *RepoCache, excerpt *BugExcerpt) bool { + for _, identityExcerpt := range repoCache.identitiesExcerpts { + if strings.Contains(strings.ToLower(identityExcerpt.Name), participant) || + participant == identityExcerpt.Id || participant == identityExcerpt.Login { + for _, participantId := range excerpt.Participants { + if identityExcerpt.Id == participantId { + return true + } + } + } + } + return false + } +} + // 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 { @@ -74,11 +108,13 @@ func NoLabelFilter() Filter { // Filters is a collection of Filter that implement a complex filter type Filters struct { - Status []Filter - Author []Filter - Label []Filter - Title []Filter - NoFilters []Filter + Status []Filter + Author []Filter + Actor []Filter + Participant []Filter + Label []Filter + Title []Filter + NoFilters []Filter } // Match check if a bug match the set of filters @@ -91,6 +127,14 @@ func (f *Filters) Match(repoCache *RepoCache, excerpt *BugExcerpt) bool { return false } + if match := f.orMatch(f.Participant, repoCache, excerpt); !match { + return false + } + + if match := f.orMatch(f.Actor, repoCache, excerpt); !match { + return false + } + if match := f.andMatch(f.Label, repoCache, excerpt); !match { return false } diff --git a/cache/query.go b/cache/query.go index 39815d32..633ef1c2 100644 --- a/cache/query.go +++ b/cache/query.go @@ -56,13 +56,21 @@ func ParseQuery(query string) (*Query, error) { f := AuthorFilter(qualifierQuery) result.Author = append(result.Author, f) + case "actor": + f := ActorFilter(qualifierQuery) + result.Actor = append(result.Actor, f) + + case "participant": + f := ParticipantFilter(qualifierQuery) + result.Participant = append(result.Participant, f) + case "label": f := LabelFilter(qualifierQuery) result.Label = append(result.Label, f) case "title": f := TitleFilter(qualifierQuery) - result.Label = append(result.Title, f) + result.Title = append(result.Title, f) case "no": err := result.parseNoFilter(qualifierQuery) diff --git a/cache/query_test.go b/cache/query_test.go index f34b3e6a..9ae62ac4 100644 --- a/cache/query_test.go +++ b/cache/query_test.go @@ -19,6 +19,9 @@ func TestQueryParse(t *testing.T) { {"author:rene", true}, {`author:"René Descartes"`, true}, + {"actor:bernhard", true}, + {"participant:leonhard", true}, + {"label:hello", true}, {`label:"Good first issue"`, true}, |