Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1759beb

Browse files
authored
fix(api): workflow push opts initialization (#6324)
1 parent f5f5a12 commit 1759beb

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

engine/api/workflow/dao.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,11 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
13061306
}
13071307
}
13081308

1309+
var fromRepo string
1310+
if opts != nil {
1311+
fromRepo = opts.FromRepository
1312+
}
1313+
13091314
tx, err := db.Begin()
13101315
if err != nil {
13111316
return nil, nil, nil, nil, sdk.WrapError(err, "unable to start tx")
@@ -1318,10 +1323,6 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
13181323
EnvironmentdSecrets: make(map[int64][]sdk.Variable),
13191324
}
13201325
for _, app := range data.Applications {
1321-
var fromRepo string
1322-
if opts != nil {
1323-
fromRepo = opts.FromRepository
1324-
}
13251326
appDB, appSecrets, msgList, err := application.ParseAndImport(ctx, tx, store, *proj, &app, application.ImportOptions{Force: true, FromRepository: fromRepo}, decryptFunc, consumer)
13261327
allMsg = append(allMsg, msgList...)
13271328
if err != nil {
@@ -1332,10 +1333,6 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
13321333
}
13331334

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

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

13611354
isDefaultBranch := true
1362-
if opts != nil {
1355+
if opts != nil && fromRepo != "" {
13631356
isDefaultBranch = opts.IsDefaultBranch
13641357
}
13651358

13661359
var importOptions = ImportOptions{
1367-
Force: true,
1360+
Force: true,
1361+
FromRepository: fromRepo,
1362+
IsDefaultBranch: isDefaultBranch,
13681363
}
13691364

13701365
if opts != nil {
1371-
importOptions.FromRepository = opts.FromRepository
1372-
importOptions.IsDefaultBranch = opts.IsDefaultBranch
13731366
importOptions.FromBranch = opts.Branch
13741367
importOptions.VCSServer = opts.VCSServer
13751368
importOptions.RepositoryName = opts.RepositoryName
@@ -1384,7 +1377,7 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
13841377
}
13851378

13861379
// If the workflow is "as-code", it should always be linked to a git repository
1387-
if opts != nil && opts.FromRepository != "" {
1380+
if fromRepo != "" {
13881381
if wf.WorkflowData.Node.Context.ApplicationID == 0 {
13891382
return nil, nil, nil, nil, sdk.WithStack(sdk.ErrApplicationMandatoryOnWorkflowAsCode)
13901383
}

engine/api/workflow_import.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,13 @@ func (api *API) postWorkflowPushHandler() service.Handler {
294294

295295
consumer := getAPIConsumer(ctx)
296296

297-
var pushOptions *workflow.PushOption
297+
pushOptions := &workflow.PushOption{}
298298
if r.Header.Get(sdk.WorkflowAsCodeHeader) != "" {
299-
pushOptions = &workflow.PushOption{
300-
FromRepository: r.Header.Get(sdk.WorkflowAsCodeHeader),
301-
IsDefaultBranch: true,
302-
Force: service.FormBool(r, "force"),
303-
}
299+
pushOptions.FromRepository = r.Header.Get(sdk.WorkflowAsCodeHeader)
300+
pushOptions.IsDefaultBranch = true
301+
}
302+
if service.FormBool(r, "force") {
303+
pushOptions.Force = true
304304
}
305305

306306
//Load project

0 commit comments

Comments
 (0)