-
Notifications
You must be signed in to change notification settings - Fork 129
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
EVG-13846 EVG-13946 Mainline commits query and graphql resolver. #4663
Changes from 11 commits
8184c81
d3ea4b6
849a1ea
e1bca53
4a93c50
c92c6be
2ff813c
1f70772
1e529ea
cd1092c
aabba9c
af013eb
0d31ad5
0f8b9ab
534ea5b
6352a33
150573b
d1b6d15
16afea1
24ad77d
066f6bc
7eb1394
7bcc8b7
05fcbe7
37e0956
caa8948
347dbfa
836742a
b2acd6a
8fd5195
fcabe67
d021e83
78c2428
cf41c70
49381c7
eb04ee1
cf1249e
ffdb1d4
a0656b6
c52b11c
ae2d5ea
8170230
881222f
448334e
4a7303c
17501e2
d258563
6c75deb
77aa154
0da46d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -825,14 +825,7 @@ func (r *patchResolver) TaskStatuses(ctx context.Context, obj *restModel.APIPatc | |
{Key: task.DisplayNameKey, Order: 1}, | ||
} | ||
opts := data.TaskFilterOptions{ | ||
Statuses: []string{}, | ||
BaseStatuses: []string{}, | ||
Variants: []string{}, | ||
TaskNames: []string{}, | ||
Page: 0, | ||
Limit: 0, | ||
FieldsToProject: []string{}, | ||
Sorts: defaultSort, | ||
Sorts: defaultSort, | ||
} | ||
tasks, _, err := r.sc.FindTasksByVersion(*obj.Id, opts) | ||
if err != nil { | ||
|
@@ -955,13 +948,7 @@ func (r *queryResolver) Patch(ctx context.Context, id string) (*restModel.APIPat | |
failedAndAbortedStatuses := append(evergreen.TaskFailureStatuses, evergreen.TaskAborted) | ||
opts := data.TaskFilterOptions{ | ||
Statuses: failedAndAbortedStatuses, | ||
BaseStatuses: []string{}, | ||
Variants: []string{}, | ||
TaskNames: []string{}, | ||
Page: 0, | ||
Limit: 0, | ||
FieldsToProject: []string{task.DisplayStatusKey}, | ||
Sorts: []task.TasksSortOrder{}, | ||
} | ||
tasks, _, err := r.sc.FindTasksByVersion(id, opts) | ||
if err != nil { | ||
|
@@ -1172,14 +1159,13 @@ func (r *queryResolver) PatchTasks(ctx context.Context, patchID string, sorts [] | |
} | ||
} | ||
opts := data.TaskFilterOptions{ | ||
Statuses: statuses, | ||
BaseStatuses: baseStatuses, | ||
Variants: []string{variantParam}, | ||
TaskNames: []string{taskNameParam}, | ||
Page: pageParam, | ||
Limit: limitParam, | ||
FieldsToProject: []string{}, | ||
Sorts: taskSorts, | ||
Statuses: statuses, | ||
BaseStatuses: baseStatuses, | ||
Variants: []string{variantParam}, | ||
TaskNames: []string{taskNameParam}, | ||
Page: pageParam, | ||
Limit: limitParam, | ||
Sorts: taskSorts, | ||
} | ||
tasks, count, err := r.sc.FindTasksByVersion(patchID, opts) | ||
if err != nil { | ||
|
@@ -2526,47 +2512,42 @@ func (r *queryResolver) BbGetCreatedTickets(ctx context.Context, taskID string) | |
|
||
// Will return an array of activated and unactivated versions | ||
func (r *queryResolver) MainlineCommits(ctx context.Context, options MainlineCommitsOptions) (*MainlineCommits, error) { | ||
|
||
opts := model.MainlineCommitVersionOptions{ | ||
Activated: true, | ||
SkipOrderNumber: 0, | ||
Limit: 0, | ||
projectId, err := model.GetIdForProject(options.ProjectID) | ||
if err != nil { | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("Could not find project with id: %s", options.ProjectID)) | ||
} | ||
if options.Limit != nil { | ||
opts.Limit = *options.Limit | ||
limit := model.DefaultMainlineCommitVersionLimit | ||
if utility.FromIntPtr(options.Limit) != 0 { | ||
limit = utility.FromIntPtr(options.Limit) | ||
} | ||
if options.SkipOrderNumber != nil { | ||
opts.SkipOrderNumber = *options.SkipOrderNumber | ||
opts := model.MainlineCommitVersionOptions{ | ||
Activated: true, | ||
Limit: limit, | ||
SkipOrderNumber: utility.FromIntPtr(options.SkipOrderNumber), | ||
} | ||
|
||
activatedVersions, err := model.GetMainlineCommitVersionsWithOptions(options.ProjectID, opts) | ||
activatedVersions, err := model.GetMainlineCommitVersionsWithOptions(projectId, opts) | ||
if err != nil { | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("Error getting activated versions %s", err.Error())) | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("Error getting activated versions: %s", err.Error())) | ||
} | ||
|
||
opts = model.MainlineCommitVersionOptions{ | ||
Activated: false, | ||
SkipOrderNumber: 0, | ||
Limit: 0, | ||
} | ||
if options.Limit != nil { | ||
opts.Limit = *options.Limit | ||
} | ||
if options.SkipOrderNumber != nil { | ||
opts.SkipOrderNumber = *options.SkipOrderNumber | ||
SkipOrderNumber: utility.FromIntPtr(options.SkipOrderNumber), | ||
} | ||
|
||
unactivatedVersions, err := model.GetMainlineCommitVersionsWithOptions(options.ProjectID, opts) | ||
unactivatedVersions, err := model.GetMainlineCommitVersionsWithOptions(projectId, opts) | ||
if err != nil { | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("Error getting unactivated versions %s", err.Error())) | ||
return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("Error getting unactivated versions: %s", err.Error())) | ||
} | ||
|
||
versions := append(activatedVersions, unactivatedVersions...) | ||
sort.Slice(versions, func(i, j int) bool { | ||
return versions[i].RevisionOrderNumber > versions[j].RevisionOrderNumber | ||
}) | ||
var mainlineCommits MainlineCommits | ||
activatedVersionCount := 0 | ||
for _, v := range versions { | ||
if activatedVersionCount == *options.Limit { | ||
if activatedVersionCount == limit { | ||
break | ||
} | ||
apiVersion := restModel.APIVersion{} | ||
|
@@ -2582,14 +2563,7 @@ func (r *queryResolver) MainlineCommits(ctx context.Context, options MainlineCom | |
{Key: task.DisplayNameKey, Order: 1}, | ||
} | ||
opts := data.TaskFilterOptions{ | ||
Statuses: []string{}, | ||
BaseStatuses: []string{}, | ||
Variants: []string{}, | ||
TaskNames: []string{}, | ||
Page: 0, | ||
Limit: 0, | ||
FieldsToProject: []string{}, | ||
Sorts: defaultSort, | ||
Sorts: defaultSort, | ||
} | ||
tasks, _, err := r.sc.FindTasksByVersion(v.Id, opts) | ||
if err != nil { | ||
|
@@ -2609,24 +2583,37 @@ func (r *queryResolver) MainlineCommits(ctx context.Context, options MainlineCom | |
} | ||
mainlineCommitVersion := MainlineCommitVersion{} | ||
|
||
// If a version is activated we append it directly to our returned list of mainlineCommits | ||
// If a version is not activated we roll up all the unactivated versions that are sequentially near each other | ||
// into a single MainlineCommitVersion and then append it to our returned list | ||
if utility.FromBoolPtr(v.Activated) { | ||
activatedVersionCount++ | ||
mainlineCommits.NextPageOrderNumber = &v.RevisionOrderNumber | ||
mainlineCommitVersion.Version = &apiVersion | ||
mainlineCommits.Versions = append(mainlineCommits.Versions, &mainlineCommitVersion) | ||
|
||
} else { | ||
// If we have any versions already we should check the most recent one first otherwise create a new one | ||
if len(mainlineCommits.Versions) > 0 { | ||
lastMainlineCommit := mainlineCommits.Versions[len(mainlineCommits.Versions)-1] | ||
|
||
// If the previous mainlineCommit contains rolled up unactivated versions append the latest RolledUp unactivated version | ||
if lastMainlineCommit.RolledUpVersions != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can check this in the go playground, but I believe appending to a nil list does work. Otherwise if there aren't any rolled up versions yet, you're just omitting the version completely at this step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I added some comments and moved the logic a little bit to make it more clear what this is doing. I also updated the graphql tests to capture this scenario. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for these comments! |
||
lastMainlineCommit.RolledUpVersions = append(lastMainlineCommit.RolledUpVersions, &apiVersion) | ||
} else { | ||
mainlineCommitVersion.RolledUpVersions = []*restModel.APIVersion{&apiVersion} | ||
} | ||
|
||
} else { | ||
mainlineCommitVersion.RolledUpVersions = []*restModel.APIVersion{&apiVersion} | ||
mainlineCommits.Versions = append(mainlineCommits.Versions, &mainlineCommitVersion) | ||
|
||
} | ||
|
||
} | ||
|
||
// Only add a mainlineCommit if a new one was added and its not a modified existing RolledUpVersion | ||
if mainlineCommitVersion.Version != nil || mainlineCommitVersion.RolledUpVersions != nil { | ||
mainlineCommits.Versions = append(mainlineCommits.Versions, &mainlineCommitVersion) | ||
} | ||
} | ||
|
||
return &mainlineCommits, nil | ||
|
@@ -2639,19 +2626,7 @@ func (r *versionResolver) BuildVariants(ctx context.Context, v *restModel.APIVer | |
if !utility.FromBoolPtr(v.Activated) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to consider if v.Activated is nil, or would the MainlineCommits resolver have been guaranteed to hit first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case it is guaranteed to have been hit first. But if we want to use this for another field that returns a version it is not guaranteed. There will be a super low likely hood of it being nil unless someone decides to view a really old version that was introduced before this field (v.Activated) was introduced There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added handling for that edge case just in case. |
||
return nil, nil | ||
} | ||
variants := []string{} | ||
tasks := []string{} | ||
statuses := []string{} | ||
if options.Variants != nil { | ||
variants = options.Variants | ||
} | ||
if options.Tasks != nil { | ||
tasks = options.Tasks | ||
} | ||
if options.Statuses != nil { | ||
statuses = options.Statuses | ||
} | ||
return generateBuildVariants(ctx, r.sc, *v.Id, variants, tasks, statuses) | ||
return generateBuildVariants(ctx, r.sc, *v.Id, options.Variants, options.Tasks, options.Statuses) | ||
} | ||
|
||
func (r *Resolver) Version() VersionResolver { return &versionResolver{r} } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you don't need to specify any of the fields you don't want to use; the defaults are the same as what you're specifying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I meant here was that you should just say:
opts := data.TaskFilterOptions{Sorts: defaultSort}
rather than specifying the fields that you don't need (same below).