Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): workflow push opts initialization #6324

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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