Skip to content

Commit

Permalink
fix(api): rename EventIntegration (#5786)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Apr 8, 2021
1 parent bfe36c6 commit 00d5b6f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
12 changes: 6 additions & 6 deletions engine/api/event/publish_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,15 +48,15 @@ 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
func PublishWorkflowDelete(ctx context.Context, projKey string, w sdk.Workflow, u sdk.Identifiable) {
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions engine/api/event/publish_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow/factory_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow/resync_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions engine/api/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/exportentities/v2/workflow_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion sdk/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 00d5b6f

Please sign in to comment.