Skip to content

Commit

Permalink
feat(api): push a workflow and remove ascode link (#6320)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt committed Oct 6, 2022
1 parent 4570dfc commit 5ab9d16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
14 changes: 13 additions & 1 deletion cli/cdsctl/workflow_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk/cdsclient"
)

var workflowPushCmd = cli.Command{
Expand All @@ -30,6 +31,12 @@ For example if you have a workflow with pipelines build and tests you can push y
Name: "yaml-file",
},
Flags: []cli.Flag{
{
Type: cli.FlagBool,
Name: "force",
Usage: "Override workflow if exists",
Default: "false",
},
{
Type: cli.FlagBool,
Name: "skip-update-files",
Expand Down Expand Up @@ -83,8 +90,13 @@ func workflowPushRun(c cli.Values) error {
btes := buf.Bytes()
r := bytes.NewBuffer(btes)

var mods []cdsclient.RequestModifier
if c.GetBool("force") {
mods = append(mods, cdsclient.Force())
}

// Push it !
msgList, tr, err := client.WorkflowPush(c.GetString(_ProjectKey), r)
msgList, tr, err := client.WorkflowPush(c.GetString(_ProjectKey), r, mods...)
for _, msg := range msgList {
fmt.Println(msg)
}
Expand Down
13 changes: 10 additions & 3 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,9 +1294,16 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}
}

// if a old workflow as code exists, we want to check if the new workflow is also as code on the same repository
if oldWf != nil && oldWf.FromRepository != "" && (opts == nil || opts.FromRepository != oldWf.FromRepository) {
return nil, nil, nil, nil, sdk.WithStack(sdk.ErrWorkflowAlreadyAsCode)
// If a old workflow as code exists, we want to check if the new workflow is also as code on the same repository
if oldWf != nil && oldWf.FromRepository != "" {
// If no repository info are given but force option is set, allow workflow override
if (opts == nil || opts.FromRepository == "") && !opts.Force {
return nil, nil, nil, nil, sdk.WithStack(sdk.ErrWorkflowAlreadyAsCode)
}
// Force option will not allow to change the repository of an existing workflow
if opts != nil && opts.FromRepository != oldWf.FromRepository {
return nil, nil, nil, nil, sdk.WithStack(sdk.ErrWorkflowAlreadyAsCode)
}
}

tx, err := db.Begin()
Expand Down

0 comments on commit 5ab9d16

Please sign in to comment.