From 00d5b6f44d1b1705d328db17864749ecaa5f3bf1 Mon Sep 17 00:00:00 2001 From: Guiheux Steven Date: Thu, 8 Apr 2021 10:55:09 +0200 Subject: [PATCH] fix(api): rename EventIntegration (#5786) --- engine/api/event/publish_workflow.go | 12 ++++++------ engine/api/event/publish_workflow_run.go | 6 +++--- engine/api/workflow/dao.go | 8 ++++---- engine/api/workflow/factory_dao.go | 2 +- engine/api/workflow/resync_workflow.go | 2 +- engine/api/workflow_test.go | 12 ++++++------ sdk/exportentities/v2/workflow_notification.go | 4 ++-- sdk/workflow.go | 12 +++++++++++- 8 files changed, 34 insertions(+), 24 deletions(-) diff --git a/engine/api/event/publish_workflow.go b/engine/api/event/publish_workflow.go index c186f03ab6..7ef0ddc3cc 100644 --- a/engine/api/event/publish_workflow.go +++ b/engine/api/event/publish_workflow.go @@ -39,7 +39,7 @@ func PublishWorkflowAdd(ctx context.Context, projKey string, w sdk.Workflow, u s e := sdk.EventWorkflowAdd{ Workflow: w, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } // PublishWorkflowUpdate publishes an event for the update of the given Workflow @@ -48,7 +48,7 @@ func PublishWorkflowUpdate(ctx context.Context, projKey string, w sdk.Workflow, NewWorkflow: w, OldWorkflow: oldw, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } // PublishWorkflowDelete publishes an event for the deletion of the given Workflow @@ -56,7 +56,7 @@ func PublishWorkflowDelete(ctx context.Context, projKey string, w sdk.Workflow, e := sdk.EventWorkflowDelete{ Workflow: w, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } // PublishWorkflowPermissionAdd publishes an event when adding a permission on a workflow @@ -65,7 +65,7 @@ func PublishWorkflowPermissionAdd(ctx context.Context, projKey string, w sdk.Wor WorkflowID: w.ID, Permission: gp, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } // PublishWorkflowPermissionUpdate publishes an event when updating a permission on a workflow @@ -75,7 +75,7 @@ func PublishWorkflowPermissionUpdate(ctx context.Context, projKey string, w sdk. NewPermission: gp, OldPermission: gpOld, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } // PublishWorkflowPermissionDelete publishes an event when deleting a permission on a workflow @@ -84,7 +84,7 @@ func PublishWorkflowPermissionDelete(ctx context.Context, projKey string, w sdk. WorkflowID: w.ID, Permission: gp, } - publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u) + publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u) } func PublishWorkflowRetentionDryRun(ctx context.Context, projKey string, workflowName string, status string, error string, runsToKeep []sdk.WorkflowRunToKeep, nbRunsAnalyzed int64, u sdk.Identifiable) { diff --git a/engine/api/event/publish_workflow_run.go b/engine/api/event/publish_workflow_run.go index 07c1a84aec..2c5efb34c2 100644 --- a/engine/api/event/publish_workflow_run.go +++ b/engine/api/event/publish_workflow_run.go @@ -73,7 +73,7 @@ func PublishWorkflowRun(ctx context.Context, wr sdk.WorkflowRun, projectKey stri workflowRunSubNum: wr.LastSubNumber, status: wr.Status, workflowRunTags: wr.Tags, - eventIntegrations: wr.Workflow.EventIntegrations, + eventIntegrations: wr.Workflow.GetEventIntegration(), } publishRunWorkflow(ctx, e, data) } @@ -190,7 +190,7 @@ func PublishWorkflowNodeRun(ctx context.Context, nr sdk.WorkflowNodeRun, w sdk.W workflowRunNum: nr.Number, workflowRunSubNum: nr.SubNumber, status: nr.Status, - eventIntegrations: w.EventIntegrations, + eventIntegrations: w.GetEventIntegration(), workflowNodeRunID: nr.ID, } publishRunWorkflow(ctx, e, data) @@ -214,7 +214,7 @@ func PublishWorkflowNodeJobRun(ctx context.Context, pkey string, wr sdk.Workflow workflowRunSubNum: wr.LastSubNumber, status: jr.Status, workflowRunTags: wr.Tags, - eventIntegrations: wr.Workflow.EventIntegrations, + eventIntegrations: wr.Workflow.GetEventIntegration(), workflowNodeRunID: jr.WorkflowNodeRunID, } publishRunWorkflow(ctx, e, data) diff --git a/engine/api/workflow/dao.go b/engine/api/workflow/dao.go index 813c30f61a..a24f58c03f 100644 --- a/engine/api/workflow/dao.go +++ b/engine/api/workflow/dao.go @@ -187,7 +187,7 @@ func (w *Workflow) PreUpdate(db gorp.SqlExecutor) error { // PostUpdate is a db hook func (w *Workflow) PostUpdate(db gorp.SqlExecutor) error { - for _, integ := range w.EventIntegrations { + for _, integ := range w.Integrations { if err := integration.AddOnWorkflow(db, w.ID, integ.ID); err != nil { return sdk.WrapError(err, "cannot add project event integration (%d) on workflow (%d)", integ.ID, w.ID) } @@ -984,13 +984,13 @@ func checkProjectIntegration(proj sdk.Project, w *sdk.Workflow, n *sdk.Node) err // checkEventIntegration checks event integration data func checkEventIntegration(proj sdk.Project, w *sdk.Workflow) error { - for i := range w.EventIntegrations { - eventIntegration := w.EventIntegrations[i] + for i := range w.Integrations { + eventIntegration := w.Integrations[i] found := false for _, projInt := range proj.Integrations { if eventIntegration.Name == projInt.Name { eventIntegration.ID = projInt.ID - w.EventIntegrations[i] = eventIntegration + w.Integrations[i] = eventIntegration found = true break } diff --git a/engine/api/workflow/factory_dao.go b/engine/api/workflow/factory_dao.go index 6b6ae8bba3..468f52d33a 100644 --- a/engine/api/workflow/factory_dao.go +++ b/engine/api/workflow/factory_dao.go @@ -502,7 +502,7 @@ func (dao WorkflowDAO) withIntegrations(db gorp.SqlExecutor, ws *[]Workflow) err for x := range *ws { w := &(*ws)[x] var err error - w.EventIntegrations, err = integration.LoadWorkflowIntegrationsByWorkflowID(db, w.ID) + w.Integrations, err = integration.LoadWorkflowIntegrationsByWorkflowID(db, w.ID) if err != nil { return err } diff --git a/engine/api/workflow/resync_workflow.go b/engine/api/workflow/resync_workflow.go index 4211d1cdca..9543f25ee0 100644 --- a/engine/api/workflow/resync_workflow.go +++ b/engine/api/workflow/resync_workflow.go @@ -38,7 +38,7 @@ func Resync(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj sd wr.Workflow.Applications = wf.Applications wr.Workflow.Environments = wf.Environments wr.Workflow.ProjectIntegrations = wf.ProjectIntegrations - wr.Workflow.EventIntegrations = wf.EventIntegrations + wr.Workflow.Integrations = wf.Integrations wr.Workflow.HookModels = wf.HookModels wr.Workflow.OutGoingHookModels = wf.OutGoingHookModels diff --git a/engine/api/workflow_test.go b/engine/api/workflow_test.go index 96a696cd0f..3b1015c1dd 100644 --- a/engine/api/workflow_test.go +++ b/engine/api/workflow_test.go @@ -843,7 +843,7 @@ func Test_putWorkflowHandler(t *testing.T) { }, }, }, - EventIntegrations: []sdk.ProjectIntegration{projInt}, + Integrations: []sdk.ProjectIntegration{projInt}, } workflow1.WorkflowData.Node.Hooks[0].Config[sdk.HookConfigEventFilter] = sdk.WorkflowNodeHookConfigValue{ Value: "push;create", @@ -865,7 +865,7 @@ func Test_putWorkflowHandler(t *testing.T) { assert.NotEqual(t, 0, workflow1.WorkflowData.Node.Context.ApplicationID) assert.NotNil(t, workflow1.WorkflowData.Node.Context.DefaultPayload) - assert.NotNil(t, workflow1.EventIntegrations) + assert.NotNil(t, workflow1.Integrations) payload, err := workflow1.WorkflowData.Node.Context.DefaultPayloadToMap() test.NoError(t, err) @@ -965,7 +965,7 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) { }, }, }, - EventIntegrations: []sdk.ProjectIntegration{projInt}, + Integrations: []sdk.ProjectIntegration{projInt}, } req = assets.NewAuthentifiedRequest(t, u, pass, "PUT", uri, &workflow1) @@ -982,8 +982,8 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) { assert.NotEqual(t, 0, workflow1.WorkflowData.Node.Context.ApplicationID) assert.NotNil(t, workflow1.WorkflowData.Node.Context.DefaultPayload) - assert.NotNil(t, workflow1.EventIntegrations) - assert.Equal(t, len(workflow1.EventIntegrations), 1) + assert.NotNil(t, workflow1.Integrations) + assert.Equal(t, len(workflow1.Integrations), 1) vars["integrationID"] = fmt.Sprintf("%d", projInt.ID) uri = router.GetRoute("DELETE", api.deleteWorkflowEventsIntegrationHandler, vars) @@ -997,7 +997,7 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) { wfUpdated, err := workflow.Load(context.TODO(), api.mustDB(), api.Cache, *proj, wf.Name, workflow.LoadOptions{WithIntegrations: true}) test.NoError(t, err, "cannot load workflow") - test.Equal(t, 0, len(wfUpdated.EventIntegrations)) + test.Equal(t, 0, len(wfUpdated.Integrations)) } func Test_postWorkflowHandlerWithError(t *testing.T) { diff --git a/sdk/exportentities/v2/workflow_notification.go b/sdk/exportentities/v2/workflow_notification.go index 05d26ac0ea..1976908a6c 100644 --- a/sdk/exportentities/v2/workflow_notification.go +++ b/sdk/exportentities/v2/workflow_notification.go @@ -100,7 +100,7 @@ func craftNotifications(ctx context.Context, w sdk.Workflow, exportedWorkflow *W } exportedWorkflow.Notifications[i] = notifEntry } - for _, e := range w.EventIntegrations { + for _, e := range w.Integrations { entry := NotificationEntry{ Integration: e.Name, Type: sdk.EventsNotification, @@ -189,7 +189,7 @@ func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error { if notif.Integration == "" { return sdk.NewErrorFrom(sdk.ErrWrongRequest, "notification of type event must be linked to an integration") } - wrkflw.EventIntegrations = append(wrkflw.EventIntegrations, sdk.ProjectIntegration{Name: notif.Integration}) + wrkflw.Integrations = append(wrkflw.Integrations, sdk.ProjectIntegration{Name: notif.Integration}) continue } n, err := ProcessNotificationValues(notif) diff --git a/sdk/workflow.go b/sdk/workflow.go index 60de67ad48..a496f04c0a 100644 --- a/sdk/workflow.go +++ b/sdk/workflow.go @@ -60,7 +60,7 @@ type Workflow struct { ToDelete bool `json:"to_delete" db:"to_delete" cli:"-"` Favorite bool `json:"favorite" db:"-" cli:"favorite"` WorkflowData WorkflowData `json:"workflow_data" db:"workflow_data" cli:"-"` - EventIntegrations []ProjectIntegration `json:"event_integrations,omitempty" db:"-" cli:"-"` + Integrations []ProjectIntegration `json:"event_integrations,omitempty" db:"-" cli:"-"` AsCodeEvent []AsCodeEvent `json:"as_code_events,omitempty" db:"-" cli:"-"` // aggregates TemplateInstance *WorkflowTemplateInstance `json:"template_instance,omitempty" db:"-" cli:"-"` @@ -369,6 +369,16 @@ func (w *Workflow) ValidateType() error { return nil } +func (w *Workflow) GetEventIntegration() []ProjectIntegration { + eventsIntegrations := make([]ProjectIntegration, 0) + for _, i := range w.Integrations { + if i.Model.Event { + eventsIntegrations = append(eventsIntegrations, i) + } + } + return eventsIntegrations +} + //WorkflowNodeConditions is either an array of WorkflowNodeCondition or a lua script type WorkflowNodeConditions struct { PlainConditions []WorkflowNodeCondition `json:"plain,omitempty" yaml:"check,omitempty"`