Skip to content

Commit

Permalink
fix(api): workflow push opts initialization (#6324)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Oct 7, 2022
1 parent f5f5a12 commit 1759beb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
27 changes: 10 additions & 17 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,11 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}
}

var fromRepo string
if opts != nil {
fromRepo = opts.FromRepository
}

tx, err := db.Begin()
if err != nil {
return nil, nil, nil, nil, sdk.WrapError(err, "unable to start tx")
Expand All @@ -1318,10 +1323,6 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
EnvironmentdSecrets: make(map[int64][]sdk.Variable),
}
for _, app := range data.Applications {
var fromRepo string
if opts != nil {
fromRepo = opts.FromRepository
}
appDB, appSecrets, msgList, err := application.ParseAndImport(ctx, tx, store, *proj, &app, application.ImportOptions{Force: true, FromRepository: fromRepo}, decryptFunc, consumer)
allMsg = append(allMsg, msgList...)
if err != nil {
Expand All @@ -1332,10 +1333,6 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}

for _, env := range data.Environments {
var fromRepo string
if opts != nil {
fromRepo = opts.FromRepository
}
envDB, envsSecrets, msgList, err := environment.ParseAndImport(ctx, tx, *proj, env, environment.ImportOptions{Force: true, FromRepository: fromRepo}, decryptFunc, consumer)
allMsg = append(allMsg, msgList...)
if err != nil {
Expand All @@ -1346,10 +1343,6 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}

for _, pip := range data.Pipelines {
var fromRepo string
if opts != nil {
fromRepo = opts.FromRepository
}
pipDB, msgList, err := pipeline.ParseAndImport(ctx, tx, store, *proj, &pip, consumer, pipeline.ImportOptions{Force: true, FromRepository: fromRepo})
allMsg = append(allMsg, msgList...)
if err != nil {
Expand All @@ -1359,17 +1352,17 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}

isDefaultBranch := true
if opts != nil {
if opts != nil && fromRepo != "" {
isDefaultBranch = opts.IsDefaultBranch
}

var importOptions = ImportOptions{
Force: true,
Force: true,
FromRepository: fromRepo,
IsDefaultBranch: isDefaultBranch,
}

if opts != nil {
importOptions.FromRepository = opts.FromRepository
importOptions.IsDefaultBranch = opts.IsDefaultBranch
importOptions.FromBranch = opts.Branch
importOptions.VCSServer = opts.VCSServer
importOptions.RepositoryName = opts.RepositoryName
Expand All @@ -1384,7 +1377,7 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}

// If the workflow is "as-code", it should always be linked to a git repository
if opts != nil && opts.FromRepository != "" {
if fromRepo != "" {
if wf.WorkflowData.Node.Context.ApplicationID == 0 {
return nil, nil, nil, nil, sdk.WithStack(sdk.ErrApplicationMandatoryOnWorkflowAsCode)
}
Expand Down
12 changes: 6 additions & 6 deletions engine/api/workflow_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ func (api *API) postWorkflowPushHandler() service.Handler {

consumer := getAPIConsumer(ctx)

var pushOptions *workflow.PushOption
pushOptions := &workflow.PushOption{}
if r.Header.Get(sdk.WorkflowAsCodeHeader) != "" {
pushOptions = &workflow.PushOption{
FromRepository: r.Header.Get(sdk.WorkflowAsCodeHeader),
IsDefaultBranch: true,
Force: service.FormBool(r, "force"),
}
pushOptions.FromRepository = r.Header.Get(sdk.WorkflowAsCodeHeader)
pushOptions.IsDefaultBranch = true
}
if service.FormBool(r, "force") {
pushOptions.Force = true
}

//Load project
Expand Down

0 comments on commit 1759beb

Please sign in to comment.