8000 fix(api): display hook's conditions in as code (#4756) · ovh/cds@c967013 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c967013

Browse files
bnjjjsguiheux
authored andcommitted
fix(api): display hook's conditions in as code (#4756)
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
1 parent 29b8c8a commit c967013

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

sdk/exportentities/workflow.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,18 @@ func NewWorkflow(w sdk.Workflow, opts ...WorkflowOptions) (Workflow, error) {
370370
if m == nil {
371371
return exportedWorkflow, sdk.WrapError(sdk.ErrNotFound, "unable to find hook model %s", h.HookModelName)
372372
}
373+
pipHook := HookEntry{
374+
Model: h.HookModelName,
375+
Ref: h.Ref,
376+
Config: h.Config.Values(m.DefaultConfig),
377+
Conditions: &h.Conditions,
378+
}
379+
380+
if h.Conditions.LuaScript == "" && len(h.Conditions.PlainConditions) == 0 {
381+
pipHook.Conditions = nil
382+
}
373383

374-
exportedWorkflow.Hooks[n.Name] = append(exportedWorkflow.Hooks[n.Name], HookEntry{
375-
Model: h.HookModelName,
376-
Ref: h.Ref,
377-
Config: h.Config.Values(m.DefaultConfig),
378-
})
384+
exportedWorkflow.Hooks[n.Name] = append(exportedWorkflow.Hooks[n.Name], pipHook)
379385
}
380386
}
381387
}

sdk/exportentities/workflow_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,80 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
305305
},
306306
},
307307
},
308+
// hook conditions
309+
{
310+
name: "Workflow with multiple nodes should display hook conditions",
311+
fields: fields{
312+
Workflow: map[string]exportentities.NodeEntry{
313+
"root": {
314+
PipelineName: "pipeline-root",
315+
},
316+
"child": {
317+
PipelineName: "pipeline-child",
318+
DependsOn: []string{"root"},
319+
OneAtATime: &exportentities.True,
320+
},
321+
},
322+
Hooks: map[string][]exportentities.HookEntry{
323+
"root": []exportentities.HookEntry{{
324+
Model: "Scheduler",
325+
Config: map[string]string{
326+
"crontab": "* * * * *",
327+
"payload": "{}",
328+
},
329+
Conditions: &sdk.WorkflowNodeConditions{
330+
LuaScript: "return true",
331+
},
332+
}},
333+
},
334+
},
335+
wantErr: false,
336+
want: sdk.Workflow{
337+
HistoryLength: sdk.DefaultHistoryLength,
338+
WorkflowData: &sdk.WorkflowData{
339+
Node: sdk.Node{
340+
Name: "root",
341+
Type: "pipeline",
342+
Hooks: []sdk.NodeHook{
343+
{
344+
HookModelName: "Scheduler",
345+
Conditions: sdk.WorkflowNodeConditions{
346+
LuaScript: "return true",
347+
},
348+
Config: sdk.WorkflowNodeHookConfig{
349+
"crontab": sdk.WorkflowNodeHookConfigValue{
350+
Value: "* * * * *",
351+
Configurable: true,
352+
Type: sdk.HookConfigTypeString,
353+
},
354+
"payload": sdk.WorkflowNodeHookConfigValue{
355+
Value: "{}",
356+
Configurable: true,
357+
Type: sdk.HookConfigTypeString,
358+
},
359+
},
360+
},
361+
},
362+
Context: &sdk.NodeContext{
363+
PipelineName: "pipeline-root",
364+
},
365+
Triggers: []sdk.NodeTrigger{
366+
{
367+
ChildNode: sdk.Node{
368+
Name: "child",
369+
Ref: "child",
370+
Type: "pipeline",
371+
Context: &sdk.NodeContext{
372+
PipelineName: "pipeline-child",
373+
Mutex: true,
374+
},
375+
},
376+
},
377+
},
378+
},
379+
},
380+
},
381+
},
308382
// root(pipeline-root) -> child(pipeline-child)
309383
{
310384
name: "Complexe workflow without joins and mutex should not raise an error",

0 commit comments

Comments
 (0)
0