8000 fix(api): rename EventIntegration (#5786) · ovh/cds@00d5b6f · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 00d5b6f

Browse files
authored
fix(api): rename EventIntegration (#5786)
1 parent bfe36c6 commit 00d5b6f

File tree

8 files changed

+34
-24
lines changed
  • workflow
  • sdk
  • 8 files changed

    +34
    -24
    lines changed

    engine/api/event/publish_workflow.go

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -39,7 +39,7 @@ func PublishWorkflowAdd(ctx context.Context, projKey string, w sdk.Workflow, u s
    3939
    e := sdk.EventWorkflowAdd{
    4040
    Workflow: w,
    4141
    }
    42-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    42+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    4343
    }
    4444

    4545
    // PublishWorkflowUpdate publishes an event for the update of the given Workflow
    @@ -48,15 +48,15 @@ func PublishWorkflowUpdate(ctx context.Context, projKey string, w sdk.Workflow,
    4848
    NewWorkflow: w,
    4949
    OldWorkflow: oldw,
    5050
    }
    51-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    51+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    5252
    }
    5353

    5454
    // PublishWorkflowDelete publishes an event for the deletion of the given Workflow
    5555
    func PublishWorkflowDelete(ctx context.Context, projKey string, w sdk.Workflow, u sdk.Identifiable) {
    5656
    e := sdk.EventWorkflowDelete{
    5757
    Workflow: w,
    5858
    }
    59-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    59+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    6060
    }
    6161

    6262
    // 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
    6565
    WorkflowID: w.ID,
    6666
    Permission: gp,
    6767
    }
    68-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    68+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    6969
    }
    7070

    7171
    // PublishWorkflowPermissionUpdate publishes an event when updating a permission on a workflow
    @@ -75,7 +75,7 @@ func PublishWorkflowPermissionUpdate(ctx context.Context, projKey string, w sdk.
    7575
    NewPermission: gp,
    7676
    OldPermission: gpOld,
    7777
    }
    78-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    78+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    7979
    }
    8080

    8181
    // PublishWorkflowPermissionDelete publishes an event when deleting a permission on a workflow
    @@ -84,7 +84,7 @@ func PublishWorkflowPermissionDelete(ctx context.Context, projKey string, w sdk.
    8484
    WorkflowID: w.ID,
    8585
    Permission: gp,
    8686
    }
    87-
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.EventIntegrations, u)
    87+
    publishWorkflowEvent(ctx, e, projKey, w.Name, w.GetEventIntegration(), u)
    8888
    }
    8989

    9090
    func PublishWorkflowRetentionDryRun(ctx context.Context, projKey string, workflowName string, status string, error string, runsToKeep []sdk.WorkflowRunToKeep, nbRunsAnalyzed int64, u sdk.Identifiable) {

    engine/api/event/publish_workflow_run.go

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -73,7 +73,7 @@ func PublishWorkflowRun(ctx context.Context, wr sdk.WorkflowRun, projectKey stri
    7373
    workflowRunSubNum: wr.LastSubNumber,
    7474
    status: wr.Status,
    7575
    workflowRunTags: wr.Tags,
    76-
    eventIntegrations: wr.Workflow.EventIntegrations,
    76+
    eventIntegrations: wr.Workflow.GetEventIntegration(),
    7777
    }
    7878
    publishRunWorkflow(ctx, e, data)
    7979
    }
    @@ -190,7 +190,7 @@ func PublishWorkflowNodeRun(ctx context.Context, nr sdk.WorkflowNodeRun, w sdk.W
    190190
    workflowRunNum: nr.Number,
    191191
    workflowRunSubNum: nr.SubNumber,
    192192
    status: nr.Status,
    193-
    eventIntegrations: w.EventIntegrations,
    193+
    eventIntegrations: w.GetEventIntegration(),
    194194
    workflowNodeRunID: nr.ID,
    195195
    }
    196196
    publishRunWorkflow(ctx, e, data)
    @@ -214,7 +214,7 @@ func PublishWorkflowNodeJobRun(ctx context.Context, pkey string, wr sdk.Workflow
    214214
    workflowRunSubNum: wr.LastSubNumber,
    215215
    status: jr.Status,
    216216
    workflowRunTags: wr.Tags,
    217-
    eventIntegrations: wr.Workflow.EventIntegrations,
    217+
    eventIntegrations: wr.Workflow.GetEventIntegration(),
    218218
    workflowNodeRunID: jr.WorkflowNodeRunID,
    219219
    }
    220220
    publishRunWorkflow(ctx, e, data)

    engine/api/workflow/dao.go

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -187,7 +187,7 @@ func (w *Workflow) PreUpdate(db gorp.SqlExecutor) error {
    187187

    188188
    // PostUpdate is a db hook
    189189
    func (w *Workflow) PostUpdate(db gorp.SqlExecutor) error {
    190-
    for _, integ := range w.EventIntegrations {
    190+
    for _, integ := range w.Integrations {
    191191
    if err := integration.AddOnWorkflow(db, w.ID, integ.ID); err != nil {
    192192
    return sdk.WrapError(err, "cannot add project event integration (%d) on workflow (%d)", integ.ID, w.ID)
    193193
    }
    @@ -984,13 +984,13 @@ func checkProjectIntegration(proj sdk.Project, w *sdk.Workflow, n *sdk.Node) err
    984984

    985985
    // checkEventIntegration checks event integration data
    986986
    func checkEventIntegration(proj sdk.Project, w *sdk.Workflow) error {
    987-
    for i := range w.EventIntegrations {
    988-
    eventIntegration := w.EventIntegrations[i]
    987+
    for i := range w.Integrations {
    988+
    eventIntegration := w.Integrations[i]
    989989
    found := false
    990990
    for _, projInt := range proj.Integrations {
    991991
    if eventIntegration.Name == projInt.Name {
    992992
    eventIntegration.ID = projInt.ID
    993-
    w.EventIntegrations[i] = eventIntegration
    993+
    w.Integrations[i] = eventIntegration
    994994
    found = true
    995995
    break
    996996
    }

    engine/api/workflow/factory_dao.go

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -502,7 +502,7 @@ func (dao WorkflowDAO) withIntegrations(db gorp.SqlExecutor, ws *[]Workflow) err
    502502
    for x := range *ws {
    503503
    w := &(*ws)[x]
    504504
    var err error
    505-
    w.EventIntegrations, err = integration.LoadWorkflowIntegrationsByWorkflowID(db, w.ID)
    505+
    w.Integrations, err = integration.LoadWorkflowIntegrationsByWorkflowID(db, w.ID)
    506506
    if err != nil {
    507507
    return err
    508508
    }

    engine/api/workflow/resync_workflow.go

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -38,7 +38,7 @@ func Resync(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj sd
    3838
    wr.Workflow.Applications = wf.Applications
    3939
    wr.Workflow.Environments = wf.Environments
    4040
    wr.Workflow.ProjectIntegrations = wf.ProjectIntegrations
    41-
    wr.Workflow.EventIntegrations = wf.EventIntegrations
    41+
    wr.Workflow.Integrations = wf.Integrations
    4242
    wr.Workflow.HookModels = wf.HookModels
    4343
    wr.Workflow.OutGoingHookModels = wf.OutGoingHookModels
    4444

    engine/api/workflow_test.go

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -843,7 +843,7 @@ func Test_putWorkflowHandler(t *testing.T) {
    843843
    },
    844844
    },
    845845
    },
    846-
    EventIntegrations: []sdk.ProjectIntegration{projInt},
    846+
    Integrations: []sdk.ProjectIntegration{projInt},
    847847
    }
    848848
    workflow1.WorkflowData.Node.Hooks[0].Config[sdk.HookConfigEventFilter] = sdk.WorkflowNodeHookConfigValue{
    849849
    Value: "push;create",
    @@ -865,7 +865,7 @@ func Test_putWorkflowHandler(t *testing.T) {
    865865

    866866
    assert.NotEqual(t, 0, workflow1.WorkflowData.Node.Context.ApplicationID)
    867867
    assert.NotNil(t, workflow1.WorkflowData.Node.Context.DefaultPayload)
    868-
    assert.NotNil(t, workflow1.EventIntegrations)
    868+
    assert.NotNil(t, workflow1.Integrations)
    869869

    870870
    payload, err := workflow1.WorkflowData.Node.Context.DefaultPayloadToMap()
    871871
    test.NoError(t, err)
    @@ -965,7 +965,7 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) {
    965965
    },
    966966
    },
    967967
    },
    968-
    EventIntegrations: []sdk.ProjectIntegration{projInt},
    968+
    Integrations: []sdk.ProjectIntegration{projInt},
    969969
    }
    970970

    971971
    req = assets.NewAuthentifiedRequest(t, u, pass, "PUT", uri, &workflow1)
    @@ -982,8 +982,8 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) {
    982982

    983983
    assert.NotEqual(t, 0, workflow1.WorkflowData.Node.Context.ApplicationID)
    984984
    assert.NotNil(t, workflow1.WorkflowData.Node.Context.DefaultPayload)
    985-
    assert.NotNil(t, workflow1.EventIntegrations)
    986-
    assert.Equal(t, len(workflow1.EventIntegrations), 1)
    985+
    assert.NotNil(t, workflow1.Integrations)
    986+
    assert.Equal(t, len(workflow1.Integrations), 1)
    987987

    988988
    vars["integrationID"] = fmt.Sprintf("%d", projInt.ID)
    989989
    uri = router.GetRoute("DELETE", api.deleteWorkflowEventsIntegrationHandler, vars)
    @@ -997,7 +997,7 @@ func Test_deleteWorkflowEventIntegrationHandler(t *testing.T) {
    997997
    wfUpdated, err := workflow.Load(context.TODO(), api.mustDB(), api.Cache, *proj, wf.Name, workflow.LoadOptions{WithIntegrations: true})
    998998
    test.NoError(t, err, "cannot load workflow")
    999999

    1000-
    test.Equal(t, 0, len(wfUpdated.EventIntegrations))
    1000+
    test.Equal(t, 0, len(wfUpdated.Integrations))
    10011001
    }
    10021002

    10031003
    func Test_postWorkflowHandlerWithError(t *testing.T) {

    sdk/exportentities/v2/workflow_notification.go

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -100,7 +100,7 @@ func craftNotifications(ctx context.Context, w sdk.Workflow, exportedWorkflow *W
    100100
    }
    101101
    exportedWorkflow.Notifications[i] = notifEntry
    102102
    }
    103-
    for _, e := range w.EventIntegrations {
    103+
    for _, e := range w.Integrations {
    104104
    entry := NotificationEntry{
    105105
    Integration: e.Name,
    106106
    Type: sdk.EventsNotification,
    @@ -189,7 +189,7 @@ func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error {
    189189
    if notif.Integration == "" {
    190190
    return sdk.NewErrorFrom(sdk.ErrWrongRequest, "notification of type event must be linked to an integration")
    191191
    }
    192-
    wrkflw.EventIntegrations = append(wrkflw.EventIntegrations, sdk.ProjectIntegration{Name: notif.Integration})
    192+
    wrkflw.Integrations = append(wrkflw.Integrations, sdk.ProjectIntegration{Name: notif.Integration})
    193193
    continue
    194194
    }
    195195
    n, err := ProcessNotificationValues(notif)

    sdk/workflow.go

    Lines changed: 11 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -60,7 +60,7 @@ type Workflow struct {
    6060
    ToDelete bool `json:"to_delete" db:"to_delete" cli:"-"`
    6161
    Favorite bool `json:"favorite" db:"-" cli:"favorite"`
    6262
    WorkflowData WorkflowData `json:"workflow_data" db:"workflow_data" cli:"-"`
    63-
    EventIntegrations []ProjectIntegration `json:"event_integrations,omitempty" db:"-" cli:"-"`
    63+
    Integrations []ProjectIntegration `json:"event_integrations,omitempty" db:"-" cli:"-"`
    6464
    AsCodeEvent []AsCodeEvent `json:"as_code_events,omitempty" db:"-" cli:"-"`
    6565
    // aggregates
    6666
    TemplateInstance *WorkflowTemplateInstance `json:"template_instance,omitempty" db:"-" cli:"-"`
    @@ -369,6 +369,16 @@ func (w *Workflow) ValidateType() error {
    369369
    return nil
    370370
    }
    371371

    372+
    func (w *Workflow) GetEventIntegration() []ProjectIntegration {
    373+
    eventsIntegrations := make([]ProjectIntegration, 0)
    374+
    for _, i := range w.Integrations {
    375+
    if i.Model.Event {
    376+
    eventsIntegrations = append(eventsIntegrations, i)
    377+
    }
    378+
    }
    379+
    return eventsIntegrations
    380+
    }
    381+
    372382
    //WorkflowNodeConditions is either an array of WorkflowNodeCondition or a lua script
    373383
    type WorkflowNodeConditions struct {
    374384
    PlainConditions []WorkflowNodeCondition `json:"plain,omitempty" yaml:"check,omitempty"`

    0 commit comments

    Comments
     (0)
    0