Skip to content

Commit

Permalink
feat: filters for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Aug 9, 2024
1 parent e4d0708 commit 84cbc6c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/repository/testworkflow/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ type FilterImpl struct {
FPageSize int
FTextSearch string
FSelector string
FRunnerIds []string
FTags map[string]string
}

func NewExecutionsFilter() *FilterImpl {
result := FilterImpl{FPage: 0, FPageSize: PageDefaultLimit}
result := FilterImpl{FPage: 0, FPageSize: PageDefaultLimit, FTags: make(map[string]string)}
return &result
}

Expand Down Expand Up @@ -130,3 +132,11 @@ func (f FilterImpl) TextSearch() string {
func (f FilterImpl) Selector() string {
return f.FSelector
}

func (f FilterImpl) RunnerIds() []string {
return f.FRunnerIds
}

func (f FilterImpl) Tags() map[string]string {
return f.FTags
}
2 changes: 2 additions & 0 deletions pkg/repository/testworkflow/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Filter interface {
TextSearchDefined() bool
TextSearch() string
Selector() string
RunnerIds() []string
Tags() map[string]string
}

//go:generate mockgen -destination=./mock_repository.go -package=testworkflow "github.com/kubeshop/testkube/pkg/repository/testworkflow" Repository
Expand Down
11 changes: 11 additions & 0 deletions pkg/repository/testworkflow/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ func composeQueryAndOpts(filter Filter) (bson.M, *options.FindOptions) {
}
}

if len(filter.RunnerIds()) > 0 {
query["runningcontext.runnerids"] = bson.M{"$in": filter.RunnerIds()}
}

// this one needs wildard index or changing the model to {k:X v:Y}
if len(filter.Tags()) > 0 {
for k, v := range filter.Tags() {
query["runningcontext.tags."+k] = v
}
}

opts.SetSkip(int64(filter.Page() * filter.PageSize()))
opts.SetLimit(int64(filter.PageSize()))
opts.SetSort(bson.D{{Key: "scheduledat", Value: -1}})
Expand Down

0 comments on commit 84cbc6c

Please sign in to comment.