From 0aa4db6cd9060205ef1b40c4495e69d1ac4f403e Mon Sep 17 00:00:00 2001 From: bynn Date: Wed, 22 May 2024 14:58:19 -0400 Subject: [PATCH 01/15] DEVPROD-7219 Remove db access from cli commands --- config.go | 2 +- operations/patch_util.go | 2 +- rest/model/patch.go | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 4ab32c47708..eb70d83474a 100644 --- a/config.go +++ b/config.go @@ -34,7 +34,7 @@ var ( // ClientVersion is the commandline version string used to control updating // the CLI. The format is the calendar date (YYYY-MM-DD). - ClientVersion = "2024-05-17" + ClientVersion = "2024-05-22" // Agent version to control agent rollover. The format is the calendar date // (YYYY-MM-DD). diff --git a/operations/patch_util.go b/operations/patch_util.go index a4d9b83893e..3c847a0b542 100644 --- a/operations/patch_util.go +++ b/operations/patch_util.go @@ -595,7 +595,7 @@ func getJSONPatchDisplay(ac *legacyClient, params outputPatchParams) (string, er display := []restModel.APIPatch{} for _, p := range params.patches { api := restModel.APIPatch{} - err := api.BuildFromService(p, nil) + err := api.BuildFromService(p, &restModel.APIPatchArgs{FromCLI: true}) if err != nil { return "", errors.Wrap(err, "converting patch to API model") } diff --git a/rest/model/patch.go b/rest/model/patch.go index 8f0c1570a6f..e1f9f83a072 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -147,6 +147,7 @@ type APIPatchArgs struct { IncludeProjectIdentifier bool IncludeCommitQueuePosition bool IncludeChildPatches bool + FromCLI bool } // BuildFromService converts from service level structs to an APIPatch. @@ -155,15 +156,19 @@ func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) er apiPatch.buildBasePatch(p) projectIdentifier := p.Project - proj, err := model.FindMergedProjectRef(projectIdentifier, p.Version, false) - if err != nil { - return errors.Wrapf(err, "finding project ref '%s'", projectIdentifier) - } - if proj == nil { - return errors.Errorf("project ref '%s' not found", projectIdentifier) + + // CLI cannot access DB information. + if !args.FromCLI { + proj, err := model.FindMergedProjectRef(projectIdentifier, p.Version, false) + if err != nil { + return errors.Wrapf(err, "finding project ref '%s'", projectIdentifier) + } + if proj == nil { + return errors.Errorf("project ref '%s' not found", projectIdentifier) + } + // Projects that use the GitHub merge queue cannot enqueue to the commit queue. + apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub } - // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub if args != nil { if args.IncludeProjectIdentifier && p.Project != "" { From d30c706739dfcdff62c1f80255f5c489296d4a34 Mon Sep 17 00:00:00 2001 From: bynn Date: Wed, 22 May 2024 15:02:59 -0400 Subject: [PATCH 02/15] use previous value --- rest/model/patch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest/model/patch.go b/rest/model/patch.go index e1f9f83a072..6edfcf015eb 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -168,6 +168,8 @@ func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) er } // Projects that use the GitHub merge queue cannot enqueue to the commit queue. apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub + } else { + apiPatch.CanEnqueueToCommitQueue = p.HasValidGitInfo() || p.IsGithubPRPatch() } if args != nil { From 27b845590e4ee51b25eecf7c25050d677a2f3b31 Mon Sep 17 00:00:00 2001 From: bynn Date: Wed, 22 May 2024 16:10:45 -0400 Subject: [PATCH 03/15] nil fix --- rest/model/patch.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/rest/model/patch.go b/rest/model/patch.go index 6edfcf015eb..5023df8f2d4 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -156,23 +156,21 @@ func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) er apiPatch.buildBasePatch(p) projectIdentifier := p.Project - - // CLI cannot access DB information. - if !args.FromCLI { - proj, err := model.FindMergedProjectRef(projectIdentifier, p.Version, false) - if err != nil { - return errors.Wrapf(err, "finding project ref '%s'", projectIdentifier) - } - if proj == nil { - return errors.Errorf("project ref '%s' not found", projectIdentifier) + apiPatch.CanEnqueueToCommitQueue = p.HasValidGitInfo() || p.IsGithubPRPatch() + if args != nil { + // CLI cannot access DB information. + if !args.FromCLI { + proj, err := model.FindMergedProjectRef(projectIdentifier, p.Version, false) + if err != nil { + return errors.Wrapf(err, "finding project ref '%s'", projectIdentifier) + } + if proj == nil { + return errors.Errorf("project ref '%s' not found", projectIdentifier) + } + // Projects that use the GitHub merge queue cannot enqueue to the commit queue. + apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub } - // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub - } else { - apiPatch.CanEnqueueToCommitQueue = p.HasValidGitInfo() || p.IsGithubPRPatch() - } - if args != nil { if args.IncludeProjectIdentifier && p.Project != "" { apiPatch.GetIdentifier() if apiPatch.ProjectIdentifier != nil { @@ -180,6 +178,7 @@ func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) er } } + if args.IncludeCommitQueuePosition { if err := apiPatch.GetCommitQueuePosition(); err != nil { return errors.Wrap(err, "getting commit queue position") From bcb5ebcec4eeca0590da43de77c3643ef289f63c Mon Sep 17 00:00:00 2001 From: bynn Date: Thu, 23 May 2024 13:56:58 -0400 Subject: [PATCH 04/15] add field to graphql' --- graphql/query_resolver.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/graphql/query_resolver.go b/graphql/query_resolver.go index 7192838533d..9eadea9e358 100644 --- a/graphql/query_resolver.go +++ b/graphql/query_resolver.go @@ -374,19 +374,22 @@ func (r *queryResolver) Pod(ctx context.Context, podID string) (*restModel.APIPo // Patch is the resolver for the patch field. func (r *queryResolver) Patch(ctx context.Context, patchID string) (*restModel.APIPatch, error) { - patch, err := data.FindPatchById(patchID) + apiPatch, err := data.FindPatchById(patchID) if err != nil { return nil, InternalServerError.Send(ctx, err.Error()) } + if apiPatch == nil { + return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) + } - if evergreen.IsFinishedVersionStatus(*patch.Status) { + if evergreen.IsFinishedVersionStatus(*apiPatch.Status) { statuses, err := task.GetTaskStatusesByVersion(ctx, patchID) if err != nil { return nil, InternalServerError.Send(ctx, fmt.Sprintf("fetching task statuses for patch: %s", err.Error())) } - if len(patch.ChildPatches) > 0 { - for _, cp := range patch.ChildPatches { + if len(apiPatch.ChildPatches) > 0 { + for _, cp := range apiPatch.ChildPatches { childPatchStatuses, err := task.GetTaskStatusesByVersion(ctx, *cp.Id) if err != nil { return nil, InternalServerError.Send(ctx, fmt.Sprintf("fetching task statuses for child patch: %s", err.Error())) @@ -398,11 +401,30 @@ func (r *queryResolver) Patch(ctx context.Context, patchID string) (*restModel.A // If theres an aborted task we should set the patch status to aborted if there are no other failures if utility.StringSliceContains(statuses, evergreen.TaskAborted) { if len(utility.StringSliceIntersection(statuses, evergreen.TaskFailureStatuses)) == 0 { - patch.Status = utility.ToStringPtr(evergreen.VersionAborted) + apiPatch.Status = utility.ToStringPtr(evergreen.VersionAborted) } } } - return patch, nil + + p, err := patch.FindOneId(patchID) + if err != nil { + return nil, InternalServerError.Send(ctx, fmt.Sprintf("error finding patch '%s': %s", patchID, err.Error())) + } + if p == nil { + return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) + } + + proj, err := model.FindMergedProjectRef(p.Project, p.Version, false) + if err != nil { + return nil, InternalServerError.Send(ctx, fmt.Sprintf("error getting project '%s': %s", p.Project, err.Error())) + } + if proj == nil { + return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) + } + // Projects that use the GitHub merge queue cannot enqueue to the commit queue. + apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub + + return apiPatch, nil } // GithubProjectConflicts is the resolver for the githubProjectConflicts field. From 7798b4c8ba4becb519dadd8783afb85c52e9792c Mon Sep 17 00:00:00 2001 From: bynn Date: Thu, 23 May 2024 15:42:41 -0400 Subject: [PATCH 05/15] remove unneeded --- operations/patch_util.go | 2 +- rest/model/patch.go | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/operations/patch_util.go b/operations/patch_util.go index 3c847a0b542..a4d9b83893e 100644 --- a/operations/patch_util.go +++ b/operations/patch_util.go @@ -595,7 +595,7 @@ func getJSONPatchDisplay(ac *legacyClient, params outputPatchParams) (string, er display := []restModel.APIPatch{} for _, p := range params.patches { api := restModel.APIPatch{} - err := api.BuildFromService(p, &restModel.APIPatchArgs{FromCLI: true}) + err := api.BuildFromService(p, nil) if err != nil { return "", errors.Wrap(err, "converting patch to API model") } diff --git a/rest/model/patch.go b/rest/model/patch.go index 5023df8f2d4..1edcec14c9f 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -147,7 +147,6 @@ type APIPatchArgs struct { IncludeProjectIdentifier bool IncludeCommitQueuePosition bool IncludeChildPatches bool - FromCLI bool } // BuildFromService converts from service level structs to an APIPatch. @@ -156,21 +155,7 @@ func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) er apiPatch.buildBasePatch(p) projectIdentifier := p.Project - apiPatch.CanEnqueueToCommitQueue = p.HasValidGitInfo() || p.IsGithubPRPatch() if args != nil { - // CLI cannot access DB information. - if !args.FromCLI { - proj, err := model.FindMergedProjectRef(projectIdentifier, p.Version, false) - if err != nil { - return errors.Wrapf(err, "finding project ref '%s'", projectIdentifier) - } - if proj == nil { - return errors.Errorf("project ref '%s' not found", projectIdentifier) - } - // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub - } - if args.IncludeProjectIdentifier && p.Project != "" { apiPatch.GetIdentifier() if apiPatch.ProjectIdentifier != nil { From d7f0542661af548c7fdf9db5111fa18fa51d2737 Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 13:37:13 -0400 Subject: [PATCH 06/15] graphql test --- graphql/patch_resolver.go | 21 +++++++++ .../patch/canEnqueueToCommitQueue/data.json | 44 +++++++++++++++++++ .../can_enqueue_to_commit_queue.graphql | 5 +++ .../canEnqueueToCommitQueue/results.json | 19 ++++++++ 4 files changed, 89 insertions(+) create mode 100644 graphql/tests/patch/canEnqueueToCommitQueue/data.json create mode 100644 graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql create mode 100644 graphql/tests/patch/canEnqueueToCommitQueue/results.json diff --git a/graphql/patch_resolver.go b/graphql/patch_resolver.go index 39a42f516b3..58edc6296f5 100644 --- a/graphql/patch_resolver.go +++ b/graphql/patch_resolver.go @@ -27,6 +27,27 @@ func (r *patchResolver) AuthorDisplayName(ctx context.Context, obj *restModel.AP return usr.DisplayName(), nil } +func (r *patchResolver) CanEnqueueToCommitQueue(ctx context.Context, obj *restModel.APIPatch) (bool, error) { + patchID := utility.FromStringPtr(obj.Id) + p, err := patch.FindOneId(patchID) + if err != nil { + return false, InternalServerError.Send(ctx, fmt.Sprintf("error finding patch '%s': %s", patchID, err.Error())) + } + if p == nil { + return false, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) + } + + proj, err := model.FindMergedProjectRef(p.Project, p.Version, false) + if err != nil { + return false, InternalServerError.Send(ctx, fmt.Sprintf("error getting project '%s': %s", p.Project, err.Error())) + } + if proj == nil { + return false, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) + } + // Projects that use the GitHub merge queue cannot enqueue to the commit queue. + return (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub, nil +} + // BaseTaskStatuses is the resolver for the baseTaskStatuses field. func (r *patchResolver) BaseTaskStatuses(ctx context.Context, obj *restModel.APIPatch) ([]string, error) { baseVersion, err := model.FindBaseVersionForVersion(*obj.Id) diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/data.json b/graphql/tests/patch/canEnqueueToCommitQueue/data.json new file mode 100644 index 00000000000..92c30d6bee0 --- /dev/null +++ b/graphql/tests/patch/canEnqueueToCommitQueue/data.json @@ -0,0 +1,44 @@ +{ + "patches": [ + { + "_id": { + "$oid": "5e4ff3abe3c3317e352062e4" + }, + "branch": "spruce", + "version": "5e4ff3abe3c3317e352062e4", + "activated": true, + "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab" + }, + { + "_id": { + "$oid": "5e4ff3abe3c3317e352062e1" + }, + "branch": "spruce", + "version": "5e4ff3abe3c3317e352062e1", + "activated": true, + "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab", + "triggers": { + "aliases": ["evergreen_alias"], + "child_patches": ["5e4ff3abe3c3317e352062e4"] + } + } + ], + "project_ref": [ + { + "_id": "spruce", + "identifier": "spruce", + "patch_trigger_aliases": [ + { + "alias": "test-alias", + "child_project": "spruce", + "task_specifiers": [ + { + "task_regex": ".*", + "variant_regex": ".*" + } + ] + } + ] + } + ] +} diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql b/graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql new file mode 100644 index 00000000000..f5751c7e126 --- /dev/null +++ b/graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql @@ -0,0 +1,5 @@ +{ + patch(patchId: "5e4ff3abe3c3317e352062e4") { + canEnqueueToCommitQueue + } +} diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/results.json b/graphql/tests/patch/canEnqueueToCommitQueue/results.json new file mode 100644 index 00000000000..2e423fc582c --- /dev/null +++ b/graphql/tests/patch/canEnqueueToCommitQueue/results.json @@ -0,0 +1,19 @@ +{ + "tests": [ + { + "query_file": "can_enqueue_to_commit_queue.graphql", + "result": { + "data": { + "patch": { + "canEnqueueToCommitQueue": [ + { + "canEnqueueToCommitQueue": true, + "patchId": "5e4ff3abe3c3317e352062e4" + } + ] + } + } + } + } + ] +} From 8a8ff09c000c49466435563276fa7570c2be7557 Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 13:38:33 -0400 Subject: [PATCH 07/15] rm old --- graphql/query_resolver.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/graphql/query_resolver.go b/graphql/query_resolver.go index 9eadea9e358..c234df397b4 100644 --- a/graphql/query_resolver.go +++ b/graphql/query_resolver.go @@ -406,24 +406,6 @@ func (r *queryResolver) Patch(ctx context.Context, patchID string) (*restModel.A } } - p, err := patch.FindOneId(patchID) - if err != nil { - return nil, InternalServerError.Send(ctx, fmt.Sprintf("error finding patch '%s': %s", patchID, err.Error())) - } - if p == nil { - return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) - } - - proj, err := model.FindMergedProjectRef(p.Project, p.Version, false) - if err != nil { - return nil, InternalServerError.Send(ctx, fmt.Sprintf("error getting project '%s': %s", p.Project, err.Error())) - } - if proj == nil { - return nil, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) - } - // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub - return apiPatch, nil } From d34d61b145d9f3cb9184b6364c060931faa3eeec Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 14:42:16 -0400 Subject: [PATCH 08/15] 2 tests --- .../patch/canEnqueueToCommitQueue/data.json | 43 +++++++++++-------- .../canEnqueueToCommitQueue/results.json | 17 +++++++- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/data.json b/graphql/tests/patch/canEnqueueToCommitQueue/data.json index 92c30d6bee0..0483e22b3b1 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/data.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/data.json @@ -7,38 +7,43 @@ "branch": "spruce", "version": "5e4ff3abe3c3317e352062e4", "activated": true, - "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab" + "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab", + "git_info": { + "username": "bob.smith", + "email": "bob.smith@gmail.com" + } }, { "_id": { - "$oid": "5e4ff3abe3c3317e352062e1" + "$oid": "4e4ff3abe3c3317e352062e4" }, - "branch": "spruce", - "version": "5e4ff3abe3c3317e352062e1", + "branch": "spruce2", + "version": "4e4ff3abe3c3317e352062e4", "activated": true, "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab", - "triggers": { - "aliases": ["evergreen_alias"], - "child_patches": ["5e4ff3abe3c3317e352062e4"] + "git_info": { + "username": "bob.smith", + "email": "bob.smith@gmail.com" } } + ], "project_ref": [ { "_id": "spruce", "identifier": "spruce", - "patch_trigger_aliases": [ - { - "alias": "test-alias", - "child_project": "spruce", - "task_specifiers": [ - { - "task_regex": ".*", - "variant_regex": ".*" - } - ] - } - ] + "commitqueue": { + "enabled": true, + "mergeQueue": "EVERGREEN" + } + }, + { + "_id": "spruce2", + "identifier": "spruce2", + "commitqueue": { + "enabled": true, + "mergeQueue": "GITHUB" + } } ] } diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/results.json b/graphql/tests/patch/canEnqueueToCommitQueue/results.json index 2e423fc582c..a075d48bd7f 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/results.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/results.json @@ -7,8 +7,21 @@ "patch": { "canEnqueueToCommitQueue": [ { - "canEnqueueToCommitQueue": true, - "patchId": "5e4ff3abe3c3317e352062e4" + "canEnqueueToCommitQueue": true + } + ] + } + } + } + }, + { + "query_file": "cannot_enqueue_to_commit_queue.graphql", + "result": { + "data": { + "patch": { + "canEnqueueToCommitQueue": [ + { + "canEnqueueToCommitQueue": false } ] } From 6bdec703aff31213cf110ab6b4f7128ec8ff87d3 Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 14:44:31 -0400 Subject: [PATCH 09/15] new file' --- .../queries/cannot_enqueue_to_commit_queue.graphql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql b/graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql new file mode 100644 index 00000000000..7b8e442fa97 --- /dev/null +++ b/graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql @@ -0,0 +1,5 @@ +{ + patch(patchId: "4e4ff3abe3c3317e352062e4") { + canEnqueueToCommitQueue + } +} From c201387612cfea0414d90fd19cb77e5d5dd5cb33 Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 14:55:05 -0400 Subject: [PATCH 10/15] tets fix --- .../patch/canEnqueueToCommitQueue/data.json | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/data.json b/graphql/tests/patch/canEnqueueToCommitQueue/data.json index 0483e22b3b1..808e82c7b80 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/data.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/data.json @@ -11,19 +11,43 @@ "git_info": { "username": "bob.smith", "email": "bob.smith@gmail.com" + }, + "github_patch_data": { + "pr_number": 27, + "base_owner": "evergreen-ci", + "base_repo": "spruce", + "base_branch": "main", + "head_owner": "evergreen-ci", + "head_repo": "spruce", + "head_hash": "2b37dacf86f9d4d1545faaba37c7c5693202e645", + "author": "tgrander", + "author_uid": 15262143, + "merge_commit_sha": "" } }, { "_id": { "$oid": "4e4ff3abe3c3317e352062e4" }, - "branch": "spruce2", + "branch": "mci", "version": "4e4ff3abe3c3317e352062e4", "activated": true, "githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab", "git_info": { "username": "bob.smith", "email": "bob.smith@gmail.com" + }, + "github_patch_data": { + "pr_number": 27, + "base_owner": "evergreen-ci", + "base_repo": "spruce", + "base_branch": "main", + "head_owner": "evergreen-ci", + "head_repo": "spruce", + "head_hash": "2b37dacf86f9d4d1545faaba37c7c5693202e645", + "author": "tgrander", + "author_uid": 15262143, + "merge_commit_sha": "" } } @@ -38,8 +62,8 @@ } }, { - "_id": "spruce2", - "identifier": "spruce2", + "_id": "mci", + "identifier": "mci", "commitqueue": { "enabled": true, "mergeQueue": "GITHUB" From 2d2b55dca4e163a92d432530f11caef7e10e85fb Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 14:55:36 -0400 Subject: [PATCH 11/15] client version --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index eb70d83474a..650ca2143a6 100644 --- a/config.go +++ b/config.go @@ -34,7 +34,7 @@ var ( // ClientVersion is the commandline version string used to control updating // the CLI. The format is the calendar date (YYYY-MM-DD). - ClientVersion = "2024-05-22" + ClientVersion = "2024-05-24" // Agent version to control agent rollover. The format is the calendar date // (YYYY-MM-DD). From a729a6078dcbe8907ac7dbd7cb3902709afe8f62 Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 17:42:13 -0400 Subject: [PATCH 12/15] rename --- graphql/generated.go | 44 +++++++++++++--- graphql/patch_resolver.go | 51 +++++++++++-------- .../patch/canEnqueueToCommitQueue/data.json | 11 ++-- ...e.graphql => can_enqueue_pr_patch.graphql} | 0 ...cannot_enqueue_using_github_queue.graphql} | 0 .../canEnqueueToCommitQueue/results.json | 12 +---- rest/model/patch.go | 21 ++++---- 7 files changed, 85 insertions(+), 54 deletions(-) rename graphql/tests/patch/canEnqueueToCommitQueue/queries/{can_enqueue_to_commit_queue.graphql => can_enqueue_pr_patch.graphql} (100%) rename graphql/tests/patch/canEnqueueToCommitQueue/queries/{cannot_enqueue_to_commit_queue.graphql => cannot_enqueue_using_github_queue.graphql} (100%) diff --git a/graphql/generated.go b/graphql/generated.go index 403bf6a2071..4347d3c71dc 100644 --- a/graphql/generated.go +++ b/graphql/generated.go @@ -1716,6 +1716,7 @@ type PatchResolver interface { AuthorDisplayName(ctx context.Context, obj *model.APIPatch) (string, error) BaseTaskStatuses(ctx context.Context, obj *model.APIPatch) ([]string, error) Builds(ctx context.Context, obj *model.APIPatch) ([]*model.APIBuild, error) + CanEnqueueToCommitQueue(ctx context.Context, obj *model.APIPatch) (bool, error) CommitQueuePosition(ctx context.Context, obj *model.APIPatch) (*int, error) @@ -34368,7 +34369,7 @@ func (ec *executionContext) _Patch_canEnqueueToCommitQueue(ctx context.Context, }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.CanEnqueueToCommitQueue, nil + return ec.resolvers.Patch().CanEnqueueToCommitQueue(rctx, obj) }) if err != nil { ec.Error(ctx, err) @@ -34389,8 +34390,8 @@ func (ec *executionContext) fieldContext_Patch_canEnqueueToCommitQueue(ctx conte fc = &graphql.FieldContext{ Object: "Patch", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { return nil, errors.New("field of type Boolean does not have child fields") }, @@ -78199,10 +78200,41 @@ func (ec *executionContext) _Patch(ctx context.Context, sel ast.SelectionSet, ob out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "canEnqueueToCommitQueue": - out.Values[i] = ec._Patch_canEnqueueToCommitQueue(ctx, field, obj) - if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Patch_canEnqueueToCommitQueue(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "childPatchAliases": out.Values[i] = ec._Patch_childPatchAliases(ctx, field, obj) case "childPatches": diff --git a/graphql/patch_resolver.go b/graphql/patch_resolver.go index 58edc6296f5..f069421a5f0 100644 --- a/graphql/patch_resolver.go +++ b/graphql/patch_resolver.go @@ -13,6 +13,8 @@ import ( "github.com/evergreen-ci/evergreen/rest/data" restModel "github.com/evergreen-ci/evergreen/rest/model" "github.com/evergreen-ci/utility" + "github.com/mongodb/grip" + "github.com/mongodb/grip/message" ) // AuthorDisplayName is the resolver for the authorDisplayName field. @@ -27,27 +29,6 @@ func (r *patchResolver) AuthorDisplayName(ctx context.Context, obj *restModel.AP return usr.DisplayName(), nil } -func (r *patchResolver) CanEnqueueToCommitQueue(ctx context.Context, obj *restModel.APIPatch) (bool, error) { - patchID := utility.FromStringPtr(obj.Id) - p, err := patch.FindOneId(patchID) - if err != nil { - return false, InternalServerError.Send(ctx, fmt.Sprintf("error finding patch '%s': %s", patchID, err.Error())) - } - if p == nil { - return false, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) - } - - proj, err := model.FindMergedProjectRef(p.Project, p.Version, false) - if err != nil { - return false, InternalServerError.Send(ctx, fmt.Sprintf("error getting project '%s': %s", p.Project, err.Error())) - } - if proj == nil { - return false, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) - } - // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - return (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub, nil -} - // BaseTaskStatuses is the resolver for the baseTaskStatuses field. func (r *patchResolver) BaseTaskStatuses(ctx context.Context, obj *restModel.APIPatch) ([]string, error) { baseVersion, err := model.FindBaseVersionForVersion(*obj.Id) @@ -79,6 +60,34 @@ func (r *patchResolver) Builds(ctx context.Context, obj *restModel.APIPatch) ([] return apiBuilds, nil } +// CanEnqueueToCommitQueue is the resolver for the canEnqueueToCommitQueue field. +func (r *patchResolver) CanEnqueueToCommitQueue(ctx context.Context, obj *restModel.APIPatch) (bool, error) { + patchID := utility.FromStringPtr(obj.Id) + p, err := patch.FindOneId(patchID) + if err != nil { + return false, InternalServerError.Send(ctx, fmt.Sprintf("error finding patch '%s': %s", patchID, err.Error())) + } + if p == nil { + return false, ResourceNotFound.Send(ctx, fmt.Sprintf("patch '%s' not found", patchID)) + } + + proj, err := model.FindMergedProjectRef(p.Project, p.Version, false) + if err != nil { + return false, InternalServerError.Send(ctx, fmt.Sprintf("error getting project '%s': %s", p.Project, err.Error())) + } + if proj == nil { + return false, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) + } + // Projects that use the GitHub merge queue cannot enqueue to the commit queue. + grip.Info(message.Fields{ + "bynnbynn": "checking if patch can be enqueued to the commit queue", + "patch": p.Id, + "project": proj.Identifier, + "queue": proj.CommitQueue.MergeQueue, + }) + return (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub, nil +} + // CommitQueuePosition is the resolver for the commitQueuePosition field. func (r *patchResolver) CommitQueuePosition(ctx context.Context, obj *restModel.APIPatch) (*int, error) { if err := obj.GetCommitQueuePosition(); err != nil { diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/data.json b/graphql/tests/patch/canEnqueueToCommitQueue/data.json index 808e82c7b80..a00d73d6877 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/data.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/data.json @@ -37,7 +37,7 @@ "username": "bob.smith", "email": "bob.smith@gmail.com" }, - "github_patch_data": { + "github_patch_data": { "pr_number": 27, "base_owner": "evergreen-ci", "base_repo": "spruce", @@ -50,23 +50,22 @@ "merge_commit_sha": "" } } - ], "project_ref": [ { "_id": "spruce", "identifier": "spruce", - "commitqueue": { + "commit_queue": { "enabled": true, - "mergeQueue": "EVERGREEN" + "merge_queue": "EVERGREEN" } }, { "_id": "mci", "identifier": "mci", - "commitqueue": { + "commit_queue": { "enabled": true, - "mergeQueue": "GITHUB" + "merge_queue": "GITHUB" } } ] diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql b/graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_pr_patch.graphql similarity index 100% rename from graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_to_commit_queue.graphql rename to graphql/tests/patch/canEnqueueToCommitQueue/queries/can_enqueue_pr_patch.graphql diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql b/graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_using_github_queue.graphql similarity index 100% rename from graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_to_commit_queue.graphql rename to graphql/tests/patch/canEnqueueToCommitQueue/queries/cannot_enqueue_using_github_queue.graphql diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/results.json b/graphql/tests/patch/canEnqueueToCommitQueue/results.json index a075d48bd7f..ed895ed675e 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/results.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/results.json @@ -5,11 +5,7 @@ "result": { "data": { "patch": { - "canEnqueueToCommitQueue": [ - { - "canEnqueueToCommitQueue": true - } - ] + "canEnqueueToCommitQueue": true } } } @@ -19,11 +15,7 @@ "result": { "data": { "patch": { - "canEnqueueToCommitQueue": [ - { - "canEnqueueToCommitQueue": false - } - ] + "canEnqueueToCommitQueue": false } } } diff --git a/rest/model/patch.go b/rest/model/patch.go index 1edcec14c9f..21b35e5b0bd 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -52,17 +52,16 @@ type APIPatch struct { // List of documents of available tasks and associated build variant VariantsTasks []VariantTask `json:"variants_tasks"` // Whether the patch has been finalized and activated - Activated bool `json:"activated"` - Alias *string `json:"alias,omitempty"` - GithubPatchData githubPatch `json:"github_patch_data,omitempty"` - ModuleCodeChanges []APIModulePatch `json:"module_code_changes"` - Parameters []APIParameter `json:"parameters"` - ProjectStorageMethod *string `json:"project_storage_method,omitempty"` - CanEnqueueToCommitQueue bool `json:"can_enqueue_to_commit_queue"` - ChildPatches []APIPatch `json:"child_patches"` - ChildPatchAliases []APIChildPatchAlias `json:"child_patch_aliases,omitempty"` - Requester *string `json:"requester"` - MergedFrom *string `json:"merged_from"` + Activated bool `json:"activated"` + Alias *string `json:"alias,omitempty"` + GithubPatchData githubPatch `json:"github_patch_data,omitempty"` + ModuleCodeChanges []APIModulePatch `json:"module_code_changes"` + Parameters []APIParameter `json:"parameters"` + ProjectStorageMethod *string `json:"project_storage_method,omitempty"` + ChildPatches []APIPatch `json:"child_patches"` + ChildPatchAliases []APIChildPatchAlias `json:"child_patch_aliases,omitempty"` + Requester *string `json:"requester"` + MergedFrom *string `json:"merged_from"` // Only populated for commit queue patches: returns the 0-indexed position of the patch on the queue, or -1 if not on the queue anymore CommitQueuePosition *int `json:"commit_queue_position,omitempty"` } From b7485bc95fe89a3ba7508bb980e409ac83a732fd Mon Sep 17 00:00:00 2001 From: bynn Date: Fri, 24 May 2024 17:43:04 -0400 Subject: [PATCH 13/15] log --- graphql/patch_resolver.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/graphql/patch_resolver.go b/graphql/patch_resolver.go index f069421a5f0..54692ac7a01 100644 --- a/graphql/patch_resolver.go +++ b/graphql/patch_resolver.go @@ -13,8 +13,6 @@ import ( "github.com/evergreen-ci/evergreen/rest/data" restModel "github.com/evergreen-ci/evergreen/rest/model" "github.com/evergreen-ci/utility" - "github.com/mongodb/grip" - "github.com/mongodb/grip/message" ) // AuthorDisplayName is the resolver for the authorDisplayName field. @@ -79,12 +77,6 @@ func (r *patchResolver) CanEnqueueToCommitQueue(ctx context.Context, obj *restMo return false, ResourceNotFound.Send(ctx, fmt.Sprintf("project '%s' not found", p.Project)) } // Projects that use the GitHub merge queue cannot enqueue to the commit queue. - grip.Info(message.Fields{ - "bynnbynn": "checking if patch can be enqueued to the commit queue", - "patch": p.Id, - "project": proj.Identifier, - "queue": proj.CommitQueue.MergeQueue, - }) return (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub, nil } From 3bd1c24bbfd7263c439e72211acbb5e30b99cce0 Mon Sep 17 00:00:00 2001 From: bynn Date: Tue, 28 May 2024 11:27:05 -0400 Subject: [PATCH 14/15] graphql file --- graphql/tests/patch/canEnqueueToCommitQueue/results.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/tests/patch/canEnqueueToCommitQueue/results.json b/graphql/tests/patch/canEnqueueToCommitQueue/results.json index ed895ed675e..b9dcfa68014 100644 --- a/graphql/tests/patch/canEnqueueToCommitQueue/results.json +++ b/graphql/tests/patch/canEnqueueToCommitQueue/results.json @@ -1,7 +1,7 @@ { "tests": [ { - "query_file": "can_enqueue_to_commit_queue.graphql", + "query_file": "can_enqueue_pr_patch.graphql", "result": { "data": { "patch": { @@ -11,7 +11,7 @@ } }, { - "query_file": "cannot_enqueue_to_commit_queue.graphql", + "query_file": "cannot_enqueue_using_github_queue.graphql", "result": { "data": { "patch": { From b15eb008c7b365a8a1fc63e6abf71985f45d9c5a Mon Sep 17 00:00:00 2001 From: bynn Date: Tue, 28 May 2024 17:48:12 -0400 Subject: [PATCH 15/15] api patch smaller --- trigger/payloads_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trigger/payloads_test.go b/trigger/payloads_test.go index 8a412f60de8..e0a1ab7d2a6 100644 --- a/trigger/payloads_test.go +++ b/trigger/payloads_test.go @@ -132,7 +132,7 @@ func (s *payloadSuite) TestEvergreenWebhook() { s.NoError(err) s.Require().NotNil(m) - s.Len(m.Body, 613) + s.Len(m.Body, 577) s.Len(m.Headers, 1) }