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-7219 Remove db access from cli commands #7912

Merged
merged 16 commits into from
May 29, 2024
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-23"
ClientVersion = "2024-05-24"

// Agent version to control agent rollover. The format is the calendar date
// (YYYY-MM-DD).
Expand Down
44 changes: 38 additions & 6 deletions graphql/generated.go

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

22 changes: 22 additions & 0 deletions graphql/patch_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ 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.
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 {
Expand Down
16 changes: 10 additions & 6 deletions graphql/query_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -398,11 +401,12 @@ 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

return apiPatch, nil
}

// GithubProjectConflicts is the resolver for the githubProjectConflicts field.
Expand Down
72 changes: 72 additions & 0 deletions graphql/tests/patch/canEnqueueToCommitQueue/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"patches": [
{
"_id": {
"$oid": "5e4ff3abe3c3317e352062e4"
},
"branch": "spruce",
"version": "5e4ff3abe3c3317e352062e4",
"activated": true,
"githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab",
"git_info": {
"username": "bob.smith",
"email": "[email protected]"
},
"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": "mci",
"version": "4e4ff3abe3c3317e352062e4",
"activated": true,
"githash": "5e823e1f28baeaa22ae00823d83e03082cd148ab",
"git_info": {
"username": "bob.smith",
"email": "[email protected]"
},
"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": ""
}
}
],
"project_ref": [
{
"_id": "spruce",
"identifier": "spruce",
"commit_queue": {
"enabled": true,
"merge_queue": "EVERGREEN"
}
},
{
"_id": "mci",
"identifier": "mci",
"commit_queue": {
"enabled": true,
"merge_queue": "GITHUB"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
patch(patchId: "5e4ff3abe3c3317e352062e4") {
canEnqueueToCommitQueue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
patch(patchId: "4e4ff3abe3c3317e352062e4") {
canEnqueueToCommitQueue
}
}
24 changes: 24 additions & 0 deletions graphql/tests/patch/canEnqueueToCommitQueue/results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"tests": [
{
"query_file": "can_enqueue_to_commit_queue.graphql",
"result": {
"data": {
"patch": {
"canEnqueueToCommitQueue": true
}
}
}
},
{
"query_file": "cannot_enqueue_to_commit_queue.graphql",
"result": {
"data": {
"patch": {
"canEnqueueToCommitQueue": false
}
}
}
}
]
}
32 changes: 11 additions & 21 deletions rest/model/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -155,16 +154,6 @@ 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)
}
// Projects that use the GitHub merge queue cannot enqueue to the commit queue.
apiPatch.CanEnqueueToCommitQueue = (p.HasValidGitInfo() || p.IsGithubPRPatch()) && proj.CommitQueue.MergeQueue != model.MergeQueueGitHub
Copy link
Contributor

@ablack12 ablack12 May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is only used by the UI, right? Instead of including this here, could we instead remove CanEnqueueToCommitQueue from the APIPatch struct and instead just add a resolver for it? (like

func (r *patchResolver) CommitQueuePosition(ctx context.Context, obj *restModel.APIPatch) (*int, error) {
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(@khelif96 is that reasonable?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this makes sense to me


if args != nil {
if args.IncludeProjectIdentifier && p.Project != "" {
apiPatch.GetIdentifier()
Expand All @@ -173,6 +162,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")
Expand Down
Loading