From 6ba73035754b814b8939d46852a065c92a4a46c2 Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:10:36 -0400 Subject: [PATCH 1/6] feat: add display tasks to models --- graphql/generated.go | 333 +++++++++++++++++++++++++++-- graphql/models_gen.go | 11 +- graphql/patch_resolver.go | 21 +- graphql/schema/types/patch.graphql | 10 +- rest/model/patch.go | 46 +++- 5 files changed, 395 insertions(+), 26 deletions(-) diff --git a/graphql/generated.go b/graphql/generated.go index 8cf8ea45db2..8e16305f03a 100644 --- a/graphql/generated.go +++ b/graphql/generated.go @@ -80,6 +80,7 @@ type ResolverRoot interface { TaskQueueItem() TaskQueueItemResolver TicketFields() TicketFieldsResolver User() UserResolver + VariantTask() VariantTaskResolver Version() VersionResolver Volume() VolumeResolver BootstrapSettingsInput() BootstrapSettingsInputResolver @@ -247,6 +248,11 @@ type ComplexityRoot struct { Version func(childComplexity int) int } + DisplayTask struct { + ExecTasks func(childComplexity int) int + Name func(childComplexity int) int + } + Distro struct { AdminOnly func(childComplexity int) int Aliases func(childComplexity int) int @@ -1598,8 +1604,9 @@ type ComplexityRoot struct { } VariantTask struct { - Name func(childComplexity int) int - Tasks func(childComplexity int) int + DisplayTasks func(childComplexity int) int + Name func(childComplexity int) int + Tasks func(childComplexity int) int } Version struct { @@ -2075,6 +2082,9 @@ type UserResolver interface { Subscriptions(ctx context.Context, obj *model.APIDBUser) ([]*model.APISubscription, error) } +type VariantTaskResolver interface { + DisplayTasks(ctx context.Context, obj *model.VariantTask) ([]*DisplayTask, error) +} type VersionResolver interface { BaseTaskStatuses(ctx context.Context, obj *model.APIVersion) ([]string, error) BaseVersion(ctx context.Context, obj *model.APIVersion) (*model.APIVersion, error) @@ -2709,6 +2719,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.DispatcherSettings.Version(childComplexity), true + case "DisplayTask.execTasks": + if e.complexity.DisplayTask.ExecTasks == nil { + break + } + + return e.complexity.DisplayTask.ExecTasks(childComplexity), true + + case "DisplayTask.name": + if e.complexity.DisplayTask.Name == nil { + break + } + + return e.complexity.DisplayTask.Name(childComplexity), true + case "Distro.adminOnly": if e.complexity.Distro.AdminOnly == nil { break @@ -9677,6 +9701,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.UserSettings.UseSpruceOptions(childComplexity), true + case "VariantTask.displayTasks": + if e.complexity.VariantTask.DisplayTasks == nil { + break + } + + return e.complexity.VariantTask.DisplayTasks(childComplexity), true + case "VariantTask.name": if e.complexity.VariantTask.Name == nil { break @@ -10400,7 +10431,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputDeleteDistroInput, ec.unmarshalInputDeleteGithubAppCredentialsInput, ec.unmarshalInputDispatcherSettingsInput, - ec.unmarshalInputDisplayTask, + ec.unmarshalInputDisplayTaskInput, ec.unmarshalInputDistroEventsInput, ec.unmarshalInputDistroInput, ec.unmarshalInputDistroPermissionsOptions, @@ -17049,6 +17080,94 @@ func (ec *executionContext) fieldContext_DispatcherSettings_version(_ context.Co return fc, nil } +func (ec *executionContext) _DisplayTask_execTasks(ctx context.Context, field graphql.CollectedField, obj *DisplayTask) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DisplayTask_execTasks(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ExecTasks, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DisplayTask_execTasks(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DisplayTask", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _DisplayTask_name(ctx context.Context, field graphql.CollectedField, obj *DisplayTask) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_DisplayTask_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_DisplayTask_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "DisplayTask", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Distro_adminOnly(ctx context.Context, field graphql.CollectedField, obj *model.APIDistro) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Distro_adminOnly(ctx, field) if err != nil { @@ -38007,6 +38126,8 @@ func (ec *executionContext) fieldContext_Patch_variantsTasks(_ context.Context, return ec.fieldContext_VariantTask_name(ctx, field) case "tasks": return ec.fieldContext_VariantTask_tasks(ctx, field) + case "displayTasks": + return ec.fieldContext_VariantTask_displayTasks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type VariantTask", field.Name) }, @@ -38791,6 +38912,8 @@ func (ec *executionContext) fieldContext_PatchTriggerAlias_variantsTasks(_ conte return ec.fieldContext_VariantTask_name(ctx, field) case "tasks": return ec.fieldContext_VariantTask_tasks(ctx, field) + case "displayTasks": + return ec.fieldContext_VariantTask_displayTasks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type VariantTask", field.Name) }, @@ -65972,6 +66095,56 @@ func (ec *executionContext) fieldContext_VariantTask_tasks(_ context.Context, fi return fc, nil } +func (ec *executionContext) _VariantTask_displayTasks(ctx context.Context, field graphql.CollectedField, obj *model.VariantTask) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_VariantTask_displayTasks(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.VariantTask().DisplayTasks(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*DisplayTask) + fc.Result = res + return ec.marshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_VariantTask_displayTasks(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "VariantTask", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "execTasks": + return ec.fieldContext_DisplayTask_execTasks(ctx, field) + case "name": + return ec.fieldContext_DisplayTask_name(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type DisplayTask", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _Version_id(ctx context.Context, field graphql.CollectedField, obj *model.APIVersion) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Version_id(ctx, field) if err != nil { @@ -73669,8 +73842,8 @@ func (ec *executionContext) unmarshalInputDispatcherSettingsInput(ctx context.Co return it, nil } -func (ec *executionContext) unmarshalInputDisplayTask(ctx context.Context, obj interface{}) (DisplayTask, error) { - var it DisplayTask +func (ec *executionContext) unmarshalInputDisplayTaskInput(ctx context.Context, obj interface{}) (DisplayTaskInput, error) { + var it DisplayTaskInput asMap := map[string]interface{}{} for k, v := range obj.(map[string]interface{}) { asMap[k] = v @@ -78181,7 +78354,7 @@ func (ec *executionContext) unmarshalInputVariantTasks(ctx context.Context, obj switch k { case "displayTasks": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("displayTasks")) - data, err := ec.unmarshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx, v) + data, err := ec.unmarshalNDisplayTaskInput2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInputᚄ(ctx, v) if err != nil { return it, err } @@ -79833,6 +80006,50 @@ func (ec *executionContext) _DispatcherSettings(ctx context.Context, sel ast.Sel return out } +var displayTaskImplementors = []string{"DisplayTask"} + +func (ec *executionContext) _DisplayTask(ctx context.Context, sel ast.SelectionSet, obj *DisplayTask) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, displayTaskImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("DisplayTask") + case "execTasks": + out.Values[i] = ec._DisplayTask_execTasks(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "name": + out.Values[i] = ec._DisplayTask_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var distroImplementors = []string{"Distro"} func (ec *executionContext) _Distro(ctx context.Context, sel ast.SelectionSet, obj *model.APIDistro) graphql.Marshaler { @@ -92858,13 +93075,49 @@ func (ec *executionContext) _VariantTask(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec._VariantTask_name(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) } case "tasks": out.Values[i] = ec._VariantTask_tasks(ctx, field, obj) if out.Values[i] == graphql.Null { - out.Invalids++ + atomic.AddUint32(&out.Invalids, 1) + } + case "displayTasks": + 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._VariantTask_displayTasks(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) }) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -95123,16 +95376,70 @@ func (ec *executionContext) marshalNDispatcherVersion2githubᚗcomᚋevergreen return v } -func (ec *executionContext) unmarshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx context.Context, v interface{}) ([]*DisplayTask, error) { +func (ec *executionContext) marshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx context.Context, sel ast.SelectionSet, v []*DisplayTask) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx context.Context, sel ast.SelectionSet, v *DisplayTask) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._DisplayTask(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNDisplayTaskInput2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInputᚄ(ctx context.Context, v interface{}) ([]*DisplayTaskInput, error) { var vSlice []interface{} if v != nil { vSlice = graphql.CoerceList(v) } var err error - res := make([]*DisplayTask, len(vSlice)) + res := make([]*DisplayTaskInput, len(vSlice)) for i := range vSlice { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx, vSlice[i]) + res[i], err = ec.unmarshalNDisplayTaskInput2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInput(ctx, vSlice[i]) if err != nil { return nil, err } @@ -95140,8 +95447,8 @@ func (ec *executionContext) unmarshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreen return res, nil } -func (ec *executionContext) unmarshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx context.Context, v interface{}) (*DisplayTask, error) { - res, err := ec.unmarshalInputDisplayTask(ctx, v) +func (ec *executionContext) unmarshalNDisplayTaskInput2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInput(ctx context.Context, v interface{}) (*DisplayTaskInput, error) { + res, err := ec.unmarshalInputDisplayTaskInput(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) } diff --git a/graphql/models_gen.go b/graphql/models_gen.go index e1272d77e17..bd577975bd8 100644 --- a/graphql/models_gen.go +++ b/graphql/models_gen.go @@ -93,6 +93,11 @@ type Dependency struct { } type DisplayTask struct { + ExecTasks []string `json:"execTasks"` + Name string `json:"name"` +} + +type DisplayTaskInput struct { ExecTasks []string `json:"ExecTasks"` Name string `json:"Name"` } @@ -596,9 +601,9 @@ type UserConfig struct { } type VariantTasks struct { - DisplayTasks []*DisplayTask `json:"displayTasks"` - Tasks []string `json:"tasks"` - Variant string `json:"variant"` + DisplayTasks []*DisplayTaskInput `json:"displayTasks"` + Tasks []string `json:"tasks"` + Variant string `json:"variant"` } type VersionTasks struct { diff --git a/graphql/patch_resolver.go b/graphql/patch_resolver.go index 29b52f10215..dbdf06478cd 100644 --- a/graphql/patch_resolver.go +++ b/graphql/patch_resolver.go @@ -152,9 +152,17 @@ func (r *patchResolver) PatchTriggerAliases(ctx context.Context, obj *restModel. variantsTasks := []restModel.VariantTask{} for _, vt := range matchingTasks { + displayTasks := []*restModel.DisplayTask{} + for _, dt := range vt.DisplayTasks { + displayTasks = append(displayTasks, &restModel.DisplayTask{ + Name: dt.Name, + ExecTasks: dt.ExecTasks, + }) + } variantsTasks = append(variantsTasks, restModel.VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: utility.ToStringPtrSlice(vt.Tasks), + Name: utility.ToStringPtr(vt.Variant), + Tasks: utility.ToStringPtrSlice(vt.Tasks), + DisplayTasks: displayTasks, }) } @@ -254,7 +262,16 @@ func (r *patchResolver) VersionFull(ctx context.Context, obj *restModel.APIPatch return &apiVersion, nil } +// DisplayTasks is the resolver for the displayTasks field. +func (r *variantTaskResolver) DisplayTasks(ctx context.Context, obj *restModel.VariantTask) ([]*DisplayTask, error) { + panic(fmt.Errorf("not implemented: DisplayTasks - displayTasks")) +} + // Patch returns PatchResolver implementation. func (r *Resolver) Patch() PatchResolver { return &patchResolver{r} } +// VariantTask returns VariantTaskResolver implementation. +func (r *Resolver) VariantTask() VariantTaskResolver { return &variantTaskResolver{r} } + type patchResolver struct{ *Resolver } +type variantTaskResolver struct{ *Resolver } diff --git a/graphql/schema/types/patch.graphql b/graphql/schema/types/patch.graphql index 3669e297234..1634c285ddc 100644 --- a/graphql/schema/types/patch.graphql +++ b/graphql/schema/types/patch.graphql @@ -34,12 +34,12 @@ input PatchConfigure { } input VariantTasks { - displayTasks: [DisplayTask!]! + displayTasks: [DisplayTaskInput!]! tasks: [String!]! variant: String! } -input DisplayTask { +input DisplayTaskInput { ExecTasks: [String!]! Name: String! } @@ -108,6 +108,12 @@ type PatchTriggerAlias { type VariantTask { name: String! tasks: [String!]! + displayTasks: [DisplayTask!]! +} + +type DisplayTask { + execTasks: [String!]! + name: String! } # This is also used by the Project type diff --git a/rest/model/patch.go b/rest/model/patch.go index a09560c5882..1c924fb10c6 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -77,11 +77,21 @@ type ChildPatch struct { PatchID *string `json:"patch_id"` Status *string `json:"status"` } + type VariantTask struct { // Name of build variant Name *string `json:"name"` // All tasks available to run on this build variant Tasks []*string `json:"tasks"` + // Display tasks associated with the tasks + DisplayTasks []*DisplayTask `json:"display_tasks"` +} + +type DisplayTask struct { + // Name of the display task + Name string `json:"name"` + // Execution tasks of the display task + ExecTasks []string `json:"execution_tasks"` } type FileDiff struct { @@ -247,9 +257,17 @@ func (apiPatch *APIPatch) buildBasePatch(p patch.Patch) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.ToStringPtr(task)) } + displayTasks := make([]*DisplayTask, 0) + for _, task := range vt.DisplayTasks { + displayTasks = append(displayTasks, &DisplayTask{ + Name: task.Name, + ExecTasks: task.ExecTasks, + }) + } variantTasks = append(variantTasks, VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: vtasks, + Name: utility.ToStringPtr(vt.Variant), + Tasks: vtasks, + DisplayTasks: displayTasks, }) } apiPatch.VariantsTasks = variantTasks @@ -289,9 +307,17 @@ func getChildPatchesData(p patch.Patch) ([]DownstreamTasks, []APIPatch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.ToStringPtr(task)) } + displayTasks := make([]*DisplayTask, 0) + for _, task := range vt.DisplayTasks { + displayTasks = append(displayTasks, &DisplayTask{ + Name: task.Name, + ExecTasks: task.ExecTasks, + }) + } variantTasks = append(variantTasks, VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: vtasks, + Name: utility.ToStringPtr(vt.Variant), + Tasks: vtasks, + DisplayTasks: displayTasks, }) } @@ -432,9 +458,17 @@ func (apiPatch *APIPatch) ToService() (patch.Patch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.FromStringPtr(task)) } + displayTasks := make([]patch.DisplayTask, 0) + for _, task := range vt.DisplayTasks { + displayTasks = append(displayTasks, patch.DisplayTask{ + Name: task.Name, + ExecTasks: task.ExecTasks, + }) + } variantTasks = append(variantTasks, patch.VariantTasks{ - Variant: utility.FromStringPtr(vt.Name), - Tasks: vtasks, + Variant: utility.FromStringPtr(vt.Name), + Tasks: vtasks, + DisplayTasks: displayTasks, }) } res.VariantsTasks = variantTasks From 7c16a2e1051a9b90d4204bc48ffa828ea39e432c Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:51:09 -0500 Subject: [PATCH 2/6] fix: remove graphql changes and remove exec and only send display tasks --- graphql/generated.go | 333 ++--------------------------- graphql/models_gen.go | 11 +- graphql/patch_resolver.go | 21 +- graphql/schema/types/patch.graphql | 10 +- rest/model/patch.go | 57 ++--- 5 files changed, 40 insertions(+), 392 deletions(-) diff --git a/graphql/generated.go b/graphql/generated.go index 8e16305f03a..8cf8ea45db2 100644 --- a/graphql/generated.go +++ b/graphql/generated.go @@ -80,7 +80,6 @@ type ResolverRoot interface { TaskQueueItem() TaskQueueItemResolver TicketFields() TicketFieldsResolver User() UserResolver - VariantTask() VariantTaskResolver Version() VersionResolver Volume() VolumeResolver BootstrapSettingsInput() BootstrapSettingsInputResolver @@ -248,11 +247,6 @@ type ComplexityRoot struct { Version func(childComplexity int) int } - DisplayTask struct { - ExecTasks func(childComplexity int) int - Name func(childComplexity int) int - } - Distro struct { AdminOnly func(childComplexity int) int Aliases func(childComplexity int) int @@ -1604,9 +1598,8 @@ type ComplexityRoot struct { } VariantTask struct { - DisplayTasks func(childComplexity int) int - Name func(childComplexity int) int - Tasks func(childComplexity int) int + Name func(childComplexity int) int + Tasks func(childComplexity int) int } Version struct { @@ -2082,9 +2075,6 @@ type UserResolver interface { Subscriptions(ctx context.Context, obj *model.APIDBUser) ([]*model.APISubscription, error) } -type VariantTaskResolver interface { - DisplayTasks(ctx context.Context, obj *model.VariantTask) ([]*DisplayTask, error) -} type VersionResolver interface { BaseTaskStatuses(ctx context.Context, obj *model.APIVersion) ([]string, error) BaseVersion(ctx context.Context, obj *model.APIVersion) (*model.APIVersion, error) @@ -2719,20 +2709,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.DispatcherSettings.Version(childComplexity), true - case "DisplayTask.execTasks": - if e.complexity.DisplayTask.ExecTasks == nil { - break - } - - return e.complexity.DisplayTask.ExecTasks(childComplexity), true - - case "DisplayTask.name": - if e.complexity.DisplayTask.Name == nil { - break - } - - return e.complexity.DisplayTask.Name(childComplexity), true - case "Distro.adminOnly": if e.complexity.Distro.AdminOnly == nil { break @@ -9701,13 +9677,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.UserSettings.UseSpruceOptions(childComplexity), true - case "VariantTask.displayTasks": - if e.complexity.VariantTask.DisplayTasks == nil { - break - } - - return e.complexity.VariantTask.DisplayTasks(childComplexity), true - case "VariantTask.name": if e.complexity.VariantTask.Name == nil { break @@ -10431,7 +10400,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputDeleteDistroInput, ec.unmarshalInputDeleteGithubAppCredentialsInput, ec.unmarshalInputDispatcherSettingsInput, - ec.unmarshalInputDisplayTaskInput, + ec.unmarshalInputDisplayTask, ec.unmarshalInputDistroEventsInput, ec.unmarshalInputDistroInput, ec.unmarshalInputDistroPermissionsOptions, @@ -17080,94 +17049,6 @@ func (ec *executionContext) fieldContext_DispatcherSettings_version(_ context.Co return fc, nil } -func (ec *executionContext) _DisplayTask_execTasks(ctx context.Context, field graphql.CollectedField, obj *DisplayTask) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DisplayTask_execTasks(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.ExecTasks, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]string) - fc.Result = res - return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_DisplayTask_execTasks(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "DisplayTask", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _DisplayTask_name(ctx context.Context, field graphql.CollectedField, obj *DisplayTask) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_DisplayTask_name(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Name, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_DisplayTask_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "DisplayTask", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") - }, - } - return fc, nil -} - func (ec *executionContext) _Distro_adminOnly(ctx context.Context, field graphql.CollectedField, obj *model.APIDistro) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Distro_adminOnly(ctx, field) if err != nil { @@ -38126,8 +38007,6 @@ func (ec *executionContext) fieldContext_Patch_variantsTasks(_ context.Context, return ec.fieldContext_VariantTask_name(ctx, field) case "tasks": return ec.fieldContext_VariantTask_tasks(ctx, field) - case "displayTasks": - return ec.fieldContext_VariantTask_displayTasks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type VariantTask", field.Name) }, @@ -38912,8 +38791,6 @@ func (ec *executionContext) fieldContext_PatchTriggerAlias_variantsTasks(_ conte return ec.fieldContext_VariantTask_name(ctx, field) case "tasks": return ec.fieldContext_VariantTask_tasks(ctx, field) - case "displayTasks": - return ec.fieldContext_VariantTask_displayTasks(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type VariantTask", field.Name) }, @@ -66095,56 +65972,6 @@ func (ec *executionContext) fieldContext_VariantTask_tasks(_ context.Context, fi return fc, nil } -func (ec *executionContext) _VariantTask_displayTasks(ctx context.Context, field graphql.CollectedField, obj *model.VariantTask) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_VariantTask_displayTasks(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.VariantTask().DisplayTasks(rctx, obj) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.([]*DisplayTask) - fc.Result = res - return ec.marshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_VariantTask_displayTasks(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "VariantTask", - Field: field, - IsMethod: true, - IsResolver: true, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "execTasks": - return ec.fieldContext_DisplayTask_execTasks(ctx, field) - case "name": - return ec.fieldContext_DisplayTask_name(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type DisplayTask", field.Name) - }, - } - return fc, nil -} - func (ec *executionContext) _Version_id(ctx context.Context, field graphql.CollectedField, obj *model.APIVersion) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Version_id(ctx, field) if err != nil { @@ -73842,8 +73669,8 @@ func (ec *executionContext) unmarshalInputDispatcherSettingsInput(ctx context.Co return it, nil } -func (ec *executionContext) unmarshalInputDisplayTaskInput(ctx context.Context, obj interface{}) (DisplayTaskInput, error) { - var it DisplayTaskInput +func (ec *executionContext) unmarshalInputDisplayTask(ctx context.Context, obj interface{}) (DisplayTask, error) { + var it DisplayTask asMap := map[string]interface{}{} for k, v := range obj.(map[string]interface{}) { asMap[k] = v @@ -78354,7 +78181,7 @@ func (ec *executionContext) unmarshalInputVariantTasks(ctx context.Context, obj switch k { case "displayTasks": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("displayTasks")) - data, err := ec.unmarshalNDisplayTaskInput2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInputᚄ(ctx, v) + data, err := ec.unmarshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx, v) if err != nil { return it, err } @@ -80006,50 +79833,6 @@ func (ec *executionContext) _DispatcherSettings(ctx context.Context, sel ast.Sel return out } -var displayTaskImplementors = []string{"DisplayTask"} - -func (ec *executionContext) _DisplayTask(ctx context.Context, sel ast.SelectionSet, obj *DisplayTask) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, displayTaskImplementors) - - out := graphql.NewFieldSet(fields) - deferred := make(map[string]*graphql.FieldSet) - for i, field := range fields { - switch field.Name { - case "__typename": - out.Values[i] = graphql.MarshalString("DisplayTask") - case "execTasks": - out.Values[i] = ec._DisplayTask_execTasks(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - case "name": - out.Values[i] = ec._DisplayTask_name(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ - } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } - } - out.Dispatch(ctx) - if out.Invalids > 0 { - return graphql.Null - } - - atomic.AddInt32(&ec.deferred, int32(len(deferred))) - - for label, dfs := range deferred { - ec.processDeferredGroup(graphql.DeferredGroup{ - Label: label, - Path: graphql.GetPath(ctx), - FieldSet: dfs, - Context: ctx, - }) - } - - return out -} - var distroImplementors = []string{"Distro"} func (ec *executionContext) _Distro(ctx context.Context, sel ast.SelectionSet, obj *model.APIDistro) graphql.Marshaler { @@ -93075,49 +92858,13 @@ func (ec *executionContext) _VariantTask(ctx context.Context, sel ast.SelectionS case "name": out.Values[i] = ec._VariantTask_name(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) + out.Invalids++ } case "tasks": out.Values[i] = ec._VariantTask_tasks(ctx, field, obj) if out.Values[i] == graphql.Null { - atomic.AddUint32(&out.Invalids, 1) - } - case "displayTasks": - 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._VariantTask_displayTasks(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.Invalids++ } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -95376,70 +95123,16 @@ func (ec *executionContext) marshalNDispatcherVersion2githubᚗcomᚋevergreen return v } -func (ec *executionContext) marshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx context.Context, sel ast.SelectionSet, v []*DisplayTask) graphql.Marshaler { - ret := make(graphql.Array, len(v)) - var wg sync.WaitGroup - isLen1 := len(v) == 1 - if !isLen1 { - wg.Add(len(v)) - } - for i := range v { - i := i - fc := &graphql.FieldContext{ - Index: &i, - Result: &v[i], - } - ctx := graphql.WithFieldContext(ctx, fc) - f := func(i int) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - if !isLen1 { - defer wg.Done() - } - ret[i] = ec.marshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx, sel, v[i]) - } - if isLen1 { - f(i) - } else { - go f(i) - } - - } - wg.Wait() - - for _, e := range ret { - if e == graphql.Null { - return graphql.Null - } - } - - return ret -} - -func (ec *executionContext) marshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx context.Context, sel ast.SelectionSet, v *DisplayTask) graphql.Marshaler { - if v == nil { - if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { - ec.Errorf(ctx, "the requested element is null which the schema does not allow") - } - return graphql.Null - } - return ec._DisplayTask(ctx, sel, v) -} - -func (ec *executionContext) unmarshalNDisplayTaskInput2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInputᚄ(ctx context.Context, v interface{}) ([]*DisplayTaskInput, error) { +func (ec *executionContext) unmarshalNDisplayTask2ᚕᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskᚄ(ctx context.Context, v interface{}) ([]*DisplayTask, error) { var vSlice []interface{} if v != nil { vSlice = graphql.CoerceList(v) } var err error - res := make([]*DisplayTaskInput, len(vSlice)) + res := make([]*DisplayTask, len(vSlice)) for i := range vSlice { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNDisplayTaskInput2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInput(ctx, vSlice[i]) + res[i], err = ec.unmarshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx, vSlice[i]) if err != nil { return nil, err } @@ -95447,8 +95140,8 @@ func (ec *executionContext) unmarshalNDisplayTaskInput2ᚕᚖgithubᚗcomᚋever return res, nil } -func (ec *executionContext) unmarshalNDisplayTaskInput2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTaskInput(ctx context.Context, v interface{}) (*DisplayTaskInput, error) { - res, err := ec.unmarshalInputDisplayTaskInput(ctx, v) +func (ec *executionContext) unmarshalNDisplayTask2ᚖgithubᚗcomᚋevergreenᚑciᚋevergreenᚋgraphqlᚐDisplayTask(ctx context.Context, v interface{}) (*DisplayTask, error) { + res, err := ec.unmarshalInputDisplayTask(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) } diff --git a/graphql/models_gen.go b/graphql/models_gen.go index bd577975bd8..e1272d77e17 100644 --- a/graphql/models_gen.go +++ b/graphql/models_gen.go @@ -93,11 +93,6 @@ type Dependency struct { } type DisplayTask struct { - ExecTasks []string `json:"execTasks"` - Name string `json:"name"` -} - -type DisplayTaskInput struct { ExecTasks []string `json:"ExecTasks"` Name string `json:"Name"` } @@ -601,9 +596,9 @@ type UserConfig struct { } type VariantTasks struct { - DisplayTasks []*DisplayTaskInput `json:"displayTasks"` - Tasks []string `json:"tasks"` - Variant string `json:"variant"` + DisplayTasks []*DisplayTask `json:"displayTasks"` + Tasks []string `json:"tasks"` + Variant string `json:"variant"` } type VersionTasks struct { diff --git a/graphql/patch_resolver.go b/graphql/patch_resolver.go index dbdf06478cd..29b52f10215 100644 --- a/graphql/patch_resolver.go +++ b/graphql/patch_resolver.go @@ -152,17 +152,9 @@ func (r *patchResolver) PatchTriggerAliases(ctx context.Context, obj *restModel. variantsTasks := []restModel.VariantTask{} for _, vt := range matchingTasks { - displayTasks := []*restModel.DisplayTask{} - for _, dt := range vt.DisplayTasks { - displayTasks = append(displayTasks, &restModel.DisplayTask{ - Name: dt.Name, - ExecTasks: dt.ExecTasks, - }) - } variantsTasks = append(variantsTasks, restModel.VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: utility.ToStringPtrSlice(vt.Tasks), - DisplayTasks: displayTasks, + Name: utility.ToStringPtr(vt.Variant), + Tasks: utility.ToStringPtrSlice(vt.Tasks), }) } @@ -262,16 +254,7 @@ func (r *patchResolver) VersionFull(ctx context.Context, obj *restModel.APIPatch return &apiVersion, nil } -// DisplayTasks is the resolver for the displayTasks field. -func (r *variantTaskResolver) DisplayTasks(ctx context.Context, obj *restModel.VariantTask) ([]*DisplayTask, error) { - panic(fmt.Errorf("not implemented: DisplayTasks - displayTasks")) -} - // Patch returns PatchResolver implementation. func (r *Resolver) Patch() PatchResolver { return &patchResolver{r} } -// VariantTask returns VariantTaskResolver implementation. -func (r *Resolver) VariantTask() VariantTaskResolver { return &variantTaskResolver{r} } - type patchResolver struct{ *Resolver } -type variantTaskResolver struct{ *Resolver } diff --git a/graphql/schema/types/patch.graphql b/graphql/schema/types/patch.graphql index 1634c285ddc..3669e297234 100644 --- a/graphql/schema/types/patch.graphql +++ b/graphql/schema/types/patch.graphql @@ -34,12 +34,12 @@ input PatchConfigure { } input VariantTasks { - displayTasks: [DisplayTaskInput!]! + displayTasks: [DisplayTask!]! tasks: [String!]! variant: String! } -input DisplayTaskInput { +input DisplayTask { ExecTasks: [String!]! Name: String! } @@ -108,12 +108,6 @@ type PatchTriggerAlias { type VariantTask { name: String! tasks: [String!]! - displayTasks: [DisplayTask!]! -} - -type DisplayTask { - execTasks: [String!]! - name: String! } # This is also used by the Project type diff --git a/rest/model/patch.go b/rest/model/patch.go index 1c924fb10c6..9cd7aedcf58 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -83,15 +83,6 @@ type VariantTask struct { Name *string `json:"name"` // All tasks available to run on this build variant Tasks []*string `json:"tasks"` - // Display tasks associated with the tasks - DisplayTasks []*DisplayTask `json:"display_tasks"` -} - -type DisplayTask struct { - // Name of the display task - Name string `json:"name"` - // Execution tasks of the display task - ExecTasks []string `json:"execution_tasks"` } type FileDiff struct { @@ -252,24 +243,30 @@ func (apiPatch *APIPatch) buildBasePatch(p patch.Patch) { } apiPatch.Tasks = tasks variantTasks := []VariantTask{} + execTasksToRemove := []string{} for _, vt := range p.VariantsTasks { vtasks := make([]*string, 0) for _, task := range vt.Tasks { vtasks = append(vtasks, utility.ToStringPtr(task)) } - displayTasks := make([]*DisplayTask, 0) for _, task := range vt.DisplayTasks { - displayTasks = append(displayTasks, &DisplayTask{ - Name: task.Name, - ExecTasks: task.ExecTasks, - }) + vtasks = append(vtasks, utility.ToStringPtr(task.Name)) + execTasksToRemove = append(execTasksToRemove, task.ExecTasks...) } variantTasks = append(variantTasks, VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: vtasks, - DisplayTasks: displayTasks, + Name: utility.ToStringPtr(vt.Variant), + Tasks: vtasks, }) } + for _, task := range execTasksToRemove { + for i, vt := range variantTasks { + for j, t := range vt.Tasks { + if t == utility.ToStringPtr(task) { + variantTasks[i].Tasks = append(vt.Tasks[:j], vt.Tasks[j+1:]...) + } + } + } + } apiPatch.VariantsTasks = variantTasks apiPatch.Activated = p.Activated apiPatch.Alias = utility.ToStringPtr(p.Alias) @@ -307,17 +304,10 @@ func getChildPatchesData(p patch.Patch) ([]DownstreamTasks, []APIPatch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.ToStringPtr(task)) } - displayTasks := make([]*DisplayTask, 0) - for _, task := range vt.DisplayTasks { - displayTasks = append(displayTasks, &DisplayTask{ - Name: task.Name, - ExecTasks: task.ExecTasks, - }) - } + // TODO FIX variantTasks = append(variantTasks, VariantTask{ - Name: utility.ToStringPtr(vt.Variant), - Tasks: vtasks, - DisplayTasks: displayTasks, + Name: utility.ToStringPtr(vt.Variant), + Tasks: vtasks, }) } @@ -458,17 +448,10 @@ func (apiPatch *APIPatch) ToService() (patch.Patch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.FromStringPtr(task)) } - displayTasks := make([]patch.DisplayTask, 0) - for _, task := range vt.DisplayTasks { - displayTasks = append(displayTasks, patch.DisplayTask{ - Name: task.Name, - ExecTasks: task.ExecTasks, - }) - } + // TODO FIX variantTasks = append(variantTasks, patch.VariantTasks{ - Variant: utility.FromStringPtr(vt.Name), - Tasks: vtasks, - DisplayTasks: displayTasks, + Variant: utility.FromStringPtr(vt.Name), + Tasks: vtasks, }) } res.VariantsTasks = variantTasks From 0ea1c62cf247b9c43f8055016c2cdd4700592cae Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:48:01 -0500 Subject: [PATCH 3/6] feat: fix loop to work correctly --- rest/model/patch.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rest/model/patch.go b/rest/model/patch.go index 9cd7aedcf58..1d5e9f3a3cd 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -258,14 +258,24 @@ func (apiPatch *APIPatch) buildBasePatch(p patch.Patch) { Tasks: vtasks, }) } - for _, task := range execTasksToRemove { - for i, vt := range variantTasks { - for j, t := range vt.Tasks { + // Go through all the variant tasks and remove the tasks that are in the execTasksToRemove list. + for i, vt := range variantTasks { + tasks := []*string{} + for j, t := range vt.Tasks { + keepTask := true + // If the task is in the execTasksToRemove, we + // do not keep it in the list of tasks. + for _, task := range execTasksToRemove { if t == utility.ToStringPtr(task) { - variantTasks[i].Tasks = append(vt.Tasks[:j], vt.Tasks[j+1:]...) + keepTask = false + break } } + if keepTask { + tasks = append(tasks, vt.Tasks[j]) + } } + variantTasks[i].Tasks = tasks } apiPatch.VariantsTasks = variantTasks apiPatch.Activated = p.Activated From a6c103d3d80cc8afc5c4abbf89934d6d7708e6a6 Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:37:07 -0500 Subject: [PATCH 4/6] feat: add execution tasks to display tasks and resolve them when making an api patch --- model/project.go | 22 ++++++++++++++ rest/model/patch.go | 8 ++--- rest/model/patch_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/model/project.go b/model/project.go index b31dd8cc726..f5b8668b0f4 100644 --- a/model/project.go +++ b/model/project.go @@ -1683,6 +1683,28 @@ func (p *Project) IgnoresAllFiles(files []string) bool { // unmatched requester (e.g. a patch-only task for a mainline commit). func (p *Project) BuildProjectTVPairs(patchDoc *patch.Patch, alias string) { patchDoc.BuildVariants, patchDoc.Tasks, patchDoc.VariantsTasks = p.ResolvePatchVTs(patchDoc, patchDoc.GetRequester(), alias, true) + + // Connect the execution tasks to the display tasks. + displayTasksToExecTasks := map[string][]string{} + for _, bv := range p.BuildVariants { + for _, dt := range bv.DisplayTasks { + displayTasksToExecTasks[dt.Name] = dt.ExecTasks + } + } + + vts := []patch.VariantTasks{} + for _, vt := range patchDoc.VariantsTasks { + dts := []patch.DisplayTask{} + for _, dt := range vt.DisplayTasks { + if ets, ok := displayTasksToExecTasks[dt.Name]; ok { + dt.ExecTasks = ets + } + dts = append(dts, dt) + } + vt.DisplayTasks = dts + vts = append(vts, vt) + } + patchDoc.VariantsTasks = vts } // ResolvePatchVTs resolves a list of build variants and tasks into a list of diff --git a/rest/model/patch.go b/rest/model/patch.go index 1d5e9f3a3cd..a62a1a2649d 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -150,6 +150,7 @@ type APIPatchArgs struct { } // BuildFromService converts from service level structs to an APIPatch. +// An APIPatch expects the VariantTasks to be populated with only non-execution tasks and display tasks. // If args are set, includes identifier, commit queue position, and/or child patches from the DB, if applicable. func (apiPatch *APIPatch) BuildFromService(p patch.Patch, args *APIPatchArgs) error { apiPatch.buildBasePatch(p) @@ -243,6 +244,8 @@ func (apiPatch *APIPatch) buildBasePatch(p patch.Patch) { } apiPatch.Tasks = tasks variantTasks := []VariantTask{} + + // We remove the execution tasks from selected display tasks to avoid duplication. execTasksToRemove := []string{} for _, vt := range p.VariantsTasks { vtasks := make([]*string, 0) @@ -258,15 +261,12 @@ func (apiPatch *APIPatch) buildBasePatch(p patch.Patch) { Tasks: vtasks, }) } - // Go through all the variant tasks and remove the tasks that are in the execTasksToRemove list. for i, vt := range variantTasks { tasks := []*string{} for j, t := range vt.Tasks { keepTask := true - // If the task is in the execTasksToRemove, we - // do not keep it in the list of tasks. for _, task := range execTasksToRemove { - if t == utility.ToStringPtr(task) { + if utility.FromStringPtr(t) == task { keepTask = false break } diff --git a/rest/model/patch_test.go b/rest/model/patch_test.go index cb84c5757fe..bff4c23c6f6 100644 --- a/rest/model/patch_test.go +++ b/rest/model/patch_test.go @@ -2,6 +2,7 @@ package model import ( "context" + "fmt" "strings" "testing" "time" @@ -224,3 +225,65 @@ func TestDownstreamTasks(t *testing.T) { assert.Len(a.DownstreamTasks[0].Tasks, 2) assert.Len(a.DownstreamTasks[0].VariantTasks, 1) } + +func TestPreselectedDisplayTasks(t *testing.T) { + require.NoError(t, db.ClearCollections(patch.Collection, model.ProjectRefCollection)) + + p := patch.Patch{ + Id: mgobson.NewObjectId(), + Description: "test", + Project: "mci", + Tasks: []string{"variant_task_1", "variant_task_2", "exec1", "exec2"}, + VariantsTasks: []patch.VariantTasks{ + { + Variant: "coverage", + Tasks: []string{"variant_task_1", "variant_task_2", "exec1", "exec2"}, + DisplayTasks: []patch.DisplayTask{ + { + Name: "display_task", + ExecTasks: []string{"exec1", "exec2"}, + }, + }, + }, + }, + } + require.NoError(t, p.Insert()) + + a := APIPatch{} + err := a.BuildFromService(p, nil) + require.NoError(t, err) + + // We expect the tasks from the patch to be only non-execution tasks + display tasks. + require.Len(t, a.VariantsTasks, 1) + assert.Len(t, a.VariantsTasks[0].Tasks, 3) + + foundTask1 := false + foundTask2 := false + foundExecTask1 := false + foundExecTask2 := false + foundDisplayTask := false + + for _, vt := range a.VariantsTasks { + for _, task := range vt.Tasks { + fmt.Println("Task:", utility.FromStringPtr(task)) + switch utility.FromStringPtr(task) { + case "variant_task_1": + foundTask1 = true + case "variant_task_2": + foundTask2 = true + case "display_task": + foundDisplayTask = true + case "exec1": + foundExecTask1 = true + case "exec2": + foundExecTask2 = true + } + } + } + + assert.True(t, foundTask1) + assert.True(t, foundTask2) + assert.False(t, foundExecTask1) + assert.False(t, foundExecTask2) + assert.True(t, foundDisplayTask) +} From 9a333a36551e2ec668ab4a464160ef2524a813a5 Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:45:09 -0500 Subject: [PATCH 5/6] refactor: remove extra comments --- rest/model/patch.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/rest/model/patch.go b/rest/model/patch.go index a62a1a2649d..1b04a256350 100644 --- a/rest/model/patch.go +++ b/rest/model/patch.go @@ -314,7 +314,6 @@ func getChildPatchesData(p patch.Patch) ([]DownstreamTasks, []APIPatch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.ToStringPtr(task)) } - // TODO FIX variantTasks = append(variantTasks, VariantTask{ Name: utility.ToStringPtr(vt.Variant), Tasks: vtasks, @@ -458,7 +457,6 @@ func (apiPatch *APIPatch) ToService() (patch.Patch, error) { for _, task := range vt.Tasks { vtasks = append(vtasks, utility.FromStringPtr(task)) } - // TODO FIX variantTasks = append(variantTasks, patch.VariantTasks{ Variant: utility.FromStringPtr(vt.Name), Tasks: vtasks, From 6753bbccb67ad635b91a942ddeec777f0cd93afd Mon Sep 17 00:00:00 2001 From: Zackary Santana <64446617+ZackarySantana@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:02:48 -0500 Subject: [PATCH 6/6] fix: clean up tests --- model/project_test.go | 5 ++++- rest/model/patch_test.go | 36 ++++++++---------------------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/model/project_test.go b/model/project_test.go index 0ab7d0c6a2d..b5782a80d75 100644 --- a/model/project_test.go +++ b/model/project_test.go @@ -1371,7 +1371,10 @@ func (s *projectSuite) TestBuildProjectTVPairsWithDisplayTaskWithDependencies() s.Contains(vt.Tasks, "very_task") s.Require().Len(vt.DisplayTasks, 1) s.Equal("memes", vt.DisplayTasks[0].Name) - s.Empty(vt.DisplayTasks[0].ExecTasks) + s.Len(vt.DisplayTasks[0].ExecTasks, 3) + s.Contains(vt.DisplayTasks[0].ExecTasks, "9001_task") + s.Contains(vt.DisplayTasks[0].ExecTasks, "very_task") + s.Contains(vt.DisplayTasks[0].ExecTasks, "another_disabled_task") } else if vt.Variant == "bv_2" { s.Len(vt.Tasks, 1) s.Contains(vt.Tasks, "a_task_2") diff --git a/rest/model/patch_test.go b/rest/model/patch_test.go index bff4c23c6f6..f8cd496781f 100644 --- a/rest/model/patch_test.go +++ b/rest/model/patch_test.go @@ -2,7 +2,6 @@ package model import ( "context" - "fmt" "strings" "testing" "time" @@ -257,33 +256,14 @@ func TestPreselectedDisplayTasks(t *testing.T) { require.Len(t, a.VariantsTasks, 1) assert.Len(t, a.VariantsTasks[0].Tasks, 3) - foundTask1 := false - foundTask2 := false - foundExecTask1 := false - foundExecTask2 := false - foundDisplayTask := false - - for _, vt := range a.VariantsTasks { - for _, task := range vt.Tasks { - fmt.Println("Task:", utility.FromStringPtr(task)) - switch utility.FromStringPtr(task) { - case "variant_task_1": - foundTask1 = true - case "variant_task_2": - foundTask2 = true - case "display_task": - foundDisplayTask = true - case "exec1": - foundExecTask1 = true - case "exec2": - foundExecTask2 = true - } - } + tasks := []string{} + for _, task := range a.VariantsTasks[0].Tasks { + tasks = append(tasks, utility.FromStringPtr(task)) } - assert.True(t, foundTask1) - assert.True(t, foundTask2) - assert.False(t, foundExecTask1) - assert.False(t, foundExecTask2) - assert.True(t, foundDisplayTask) + assert.Contains(t, tasks, "variant_task_1") + assert.Contains(t, tasks, "variant_task_2") + assert.NotContains(t, tasks, "exec1") + assert.NotContains(t, tasks, "exec2") + assert.Contains(t, tasks, "display_task") }