Skip to content

Commit

Permalink
fix(api): rename workflow as code & import
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Aug 6, 2019
1 parent 8e6f08a commit 38a07d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ func checkHooks(db gorp.SqlExecutor, w *sdk.Workflow, n *sdk.Node) error {
for i := range d.MultipleChoiceList {
if h.Config[k].Value == d.MultipleChoiceList[i] {
found = true
break
break
}
}
if !found {
Expand Down
9 changes: 8 additions & 1 deletion engine/api/workflow/workflow_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflow
import (
"context"
"fmt"

"github.com/go-gorp/gorp"
"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/engine/api/event"
Expand Down Expand Up @@ -63,7 +64,13 @@ func Import(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj *s
if h.Ref != "" && h.UUID == "" {
if oldH, has := oldHooksByRef[h.Ref]; has {
if len(h.Config) == 0 {
h.Config = oldH.Config
h.Config = oldH.Config.Clone()
// the oldW can have a different name than the workflow to import
//we have to rename the workflow name in the hook config retrieve from old workflow
h.Config[sdk.HookConfigWorkflow] = sdk.WorkflowNodeHookConfigValue{
Value: w.Name,
Configurable: false,
}
}
h.UUID = oldH.UUID
continue
Expand Down
11 changes: 7 additions & 4 deletions engine/api/workflow/workflow_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,24 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, store cache.Store,
h := &w.WorkflowData.Node.Hooks[i]
if h.HookModelName == sdk.RepositoryWebHookModel.Name {
h.UUID = oldRepoWebHook.UUID
h.Config = oldRepoWebHook.Config
h.Config = oldRepoWebHook.Config.Clone()
h.Config[sdk.HookConfigWorkflow] = sdk.WorkflowNodeHookConfigValue{Value: w.Name}
currentRepoWebHook = h
break
}
}

// If not found
if currentRepoWebHook == nil {
w.WorkflowData.Node.Hooks = append(w.WorkflowData.Node.Hooks, sdk.NodeHook{
h := sdk.NodeHook{
UUID: oldRepoWebHook.UUID,
HookModelName: oldRepoWebHook.HookModelName,
Config: oldRepoWebHook.Config,
Config: oldRepoWebHook.Config.Clone(),
Ref: oldRepoWebHook.Ref,
HookModelID: oldRepoWebHook.HookModelID,
})
}
h.Config[sdk.HookConfigWorkflow] = sdk.WorkflowNodeHookConfigValue{Value: w.Name}
w.WorkflowData.Node.Hooks = append(w.WorkflowData.Node.Hooks, h)
}
} else {
// Init new repo webhook
Expand Down

0 comments on commit 38a07d4

Please sign in to comment.