Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-10179: Add task name and status filtering #8800

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions graphql/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions graphql/query_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,21 +968,48 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions)

opts := model.WaterfallOptions{
Limit: limit,
Requesters: requesters,
MaxOrder: maxOrderOpt,
MinOrder: minOrderOpt,
Variants: options.Variants,
Requesters: requesters,
Statuses: utility.FilterSlice(options.Statuses, func(s string) bool { return s != "" }),
Tasks: utility.FilterSlice(options.Tasks, func(s string) bool { return s != "" }),
Variants: utility.FilterSlice(options.Variants, func(s string) bool { return s != "" }),
}

activeVersions, err := model.GetActiveWaterfallVersions(ctx, projectId, opts)
mostRecentWaterfallVersion, err := model.GetMostRecentWaterfallVersion(ctx, projectId)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting active waterfall versions: %s", err.Error()))
return nil, InternalServerError.Send(ctx, fmt.Sprintf("fetching most recent waterfall version: %s", err.Error()))
}
if mostRecentWaterfallVersion == nil {
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("no versions found for project '%s'", projectId))
}

var activeVersions []model.Version
if len(opts.Tasks) > 0 || len(opts.Statuses) > 0 {
var searchOffset int
if opts.MaxOrder != 0 {
searchOffset = opts.MaxOrder
} else if opts.MinOrder != 0 {
searchOffset = opts.MinOrder
} else {
// Add one because minOrder and maxOrder are exclusive
searchOffset = mostRecentWaterfallVersion.RevisionOrderNumber + 1
}
activeVersions, err = model.GetActiveVersionsByTaskFilters(ctx, projectId, opts, searchOffset)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting active waterfall versions: %s", err.Error()))
}
} else {
activeVersions, err = model.GetActiveWaterfallVersions(ctx, projectId, opts)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting active waterfall versions: %s", err.Error()))
}
}

// Since GetAllWaterfallVersions uses an inclusive order range ($gte instead of $gt), add 1 to our minimum range
minVersionOrder := minOrderOpt + 1
if len(activeVersions) == 0 {
minVersionOrder = 0
minVersionOrder = opts.MinOrder
} else if minOrderOpt == 0 {
// Find an older version that is activated. If it doesn't exist, that means there are trailing inactive
// versions on the waterfall and that we should not place a lower bound.
Expand All @@ -1002,7 +1029,7 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions)
// Same as above, but subtract for max order
maxVersionOrder := maxOrderOpt - 1
if len(activeVersions) == 0 {
maxVersionOrder = 0
maxVersionOrder = opts.MaxOrder
} else if maxOrderOpt == 0 && minOrderOpt == 0 {
// If no order options were specified, we're on the first page and should not put a limit on the first version returned so that we don't omit inactive versions
maxVersionOrder = 0
Expand Down Expand Up @@ -1033,10 +1060,6 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions)
}

waterfallVersions := groupInactiveVersions(allVersions)
mostRecentWaterfallVersion, err := model.GetMostRecentWaterfallVersion(ctx, projectId)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("fetching most recent waterfall version: %s", err.Error()))
}

prevPageOrder := 0
nextPageOrder := 0
Expand Down
2 changes: 2 additions & 0 deletions graphql/schema/types/waterfall.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ input WaterfallOptions {
@requireProjectAccess(permission: TASKS, access: VIEW)
requesters: [String!]
revision: String
statuses: [String!]
tasks: [String!]
variants: [String!]
}

Expand Down
22 changes: 16 additions & 6 deletions graphql/tests/query/waterfall/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"activated": true,
"author": "mohamed.khelif",
"status": "failed",
"order": 39,
"order": 1,
"create_time": {
"$date": "2019-12-30T00:00:03Z"
}
Expand All @@ -28,7 +28,7 @@
},
{
"_id": "evergreen_version1",
"gitspec": "revision1",
"gitspec": "d7b7a086cc4f4edeb9a5eb59f3dd4f2f7c3f7ddb",
"identifier": "spruce",
"r": "git_tag_request",
"activated": true,
Expand Down Expand Up @@ -103,7 +103,7 @@
"activated": false,
"author": "mohamed.khelif",
"status": "created",
"order": 645,
"order": 44,
"create_time": {
"$date": "2020-01-04T08:15:00Z"
}
Expand All @@ -116,7 +116,7 @@
"activated": true,
"author": "mohamed.khelif",
"status": "created",
"order": 945,
"order": 45,
"create_time": {
"$date": "2020-01-05T12:00:00Z"
},
Expand Down Expand Up @@ -194,6 +194,7 @@
"display_status_cache": "success",
"display_name": "Task A",
"activated": true,
"branch": "spruce",
"build_variant": "enterprise-ubuntu1604-64",
"build_variant_display_name": "Ubuntu 16.04",
"build_id": "evergreen_version1_build",
Expand All @@ -202,6 +203,7 @@
},
"execution": 0,
"display_task_id": "",
"order": 41,
"r": "gitter_request"
},
{
Expand All @@ -211,6 +213,7 @@
"display_status_cache": "success",
"display_name": "Task B",
"activated": true,
"branch": "spruce",
"build_variant": "enterprise-ubuntu1604-64",
"build_variant_display_name": "Ubuntu 16.04",
"build_id": "evergreen_version1_build",
Expand All @@ -219,6 +222,7 @@
},
"execution": 1,
"display_task_id": "",
"order": 41,
"r": "gitter_request"
},
{
Expand All @@ -231,6 +235,7 @@
},
"display_name": "Task A",
"activated": true,
"branch": "spruce",
"build_variant": "enterprise-ubuntu1604-64",
"build_variant_display_name": "Ubuntu 16.04",
"build_id": "evergreen_version2_build",
Expand All @@ -239,6 +244,7 @@
},
"execution": 0,
"display_task_id": "",
"order": 42,
"r": "gitter_request"
},
{
Expand All @@ -248,6 +254,7 @@
"display_status_cache": "success",
"display_name": "Task B",
"activated": true,
"branch": "spruce",
"build_variant": "enterprise-ubuntu1604-64",
"build_variant_display_name": "Ubuntu 16.04",
"build_id": "evergreen_version2_build",
Expand All @@ -256,15 +263,17 @@
},
"execution": 0,
"display_task_id": "",
"order": 42,
"r": "gitter_request"
},
{
"_id": "task_5",
"version": "evergreen_version5",
"status": "success",
"display_status_cache": "success",
"status": "failed",
"display_status_cache": "system-failed",
"display_name": "Task C",
"activated": true,
"branch": "spruce",
"build_variant": "lint",
"build_variant_display_name": "Linter",
"build_id": "evergreen_version3_build",
Expand All @@ -273,6 +282,7 @@
},
"execution": 0,
"display_task_id": "",
"order": 45,
"r": "gitter_request"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
waterfall(options: { projectIdentifier: "spruce-identifier", maxOrder: 945 }) {
waterfall(options: { projectIdentifier: "spruce-identifier", maxOrder: 45 }) {
versions {
version {
activated
Expand Down
2 changes: 1 addition & 1 deletion graphql/tests/query/waterfall/queries/revision.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
waterfall(options: { projectIdentifier: "spruce", revision: "da39a3e" }) {
waterfall(options: { projectIdentifier: "spruce", revision: "d7b7a08" }) {
versions {
version {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
waterfall(options: { projectIdentifier: "spruce-identifier", minOrder: 41, statuses: ["success"] }) {
flattenedVersions {
id
activated
status
order
}
pagination {
activeVersionIds
}
}
}
12 changes: 12 additions & 0 deletions graphql/tests/query/waterfall/queries/task-status.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
waterfall(options: { projectIdentifier: "spruce-identifier", statuses: ["system-failed"] }) {
flattenedVersions {
id
activated
requester
}
pagination {
activeVersionIds
}
}
}
12 changes: 12 additions & 0 deletions graphql/tests/query/waterfall/queries/tasks.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
waterfall(options: { projectIdentifier: "spruce-identifier", tasks: ["Task C"] }) {
flattenedVersions {
id
activated
requester
}
pagination {
activeVersionIds
}
}
}
Loading
Loading