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

fix(api): rename EventIntegration #5786

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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