Skip to content

Commit fef0f25

Browse files
authored
fix(api): reload old workflow just before update it (#5037)
1 parent a60684e commit fef0f25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+236
-233
lines changed

cli/cdsctl/workflow_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func workflowRunManualRun(v cli.Values) error {
121121
}
122122

123123
// Check if we are on the same repository and if we have a git.branch in the default payload
124-
if wf.WorkflowData != nil && wf.WorkflowData.Node.Context != nil && wf.WorkflowData.Node.Context.ApplicationID != 0 {
124+
if wf.WorkflowData.Node.Context != nil && wf.WorkflowData.Node.Context.ApplicationID != 0 {
125125
app := wf.GetApplication(wf.WorkflowData.Node.Context.ApplicationID)
126126
if remoteURL != "" && strings.Contains(remoteURL, app.RepositoryFullname) && currentBranch != "" {
127127
defaultPayload, err := wf.WorkflowData.Node.Context.DefaultPayloadToMap()

engine/api/application/dao_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestLoadByWorkflowID(t *testing.T) {
182182
Name: "test_1",
183183
ProjectID: proj.ID,
184184
ProjectKey: proj.Key,
185-
WorkflowData: &sdk.WorkflowData{
185+
WorkflowData: sdk.WorkflowData{
186186
Node: sdk.Node{
187187
Type: sdk.NodeTypePipeline,
188188
Context: &sdk.NodeContext{

engine/api/ascode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ vcs_ssh_key: proj-blabla
356356
Name: sdk.RandomString(10),
357357
ProjectID: p.ID,
358358
ProjectKey: p.Key,
359-
WorkflowData: &sdk.WorkflowData{
359+
WorkflowData: sdk.WorkflowData{
360360
Node: sdk.Node{
361361
Name: "root",
362362
Type: sdk.NodeTypePipeline,

engine/api/pipeline/pipeline_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestLoadByWorkflowID(t *testing.T) {
167167
Name: "test_1",
168168
ProjectID: proj.ID,
169169
ProjectKey: proj.Key,
170-
WorkflowData: &sdk.WorkflowData{
170+
WorkflowData: sdk.WorkflowData{
171171
Node: sdk.Node{
172172
Type: sdk.NodeTypePipeline,
173173
Context: &sdk.NodeContext{

engine/api/project_group_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Test_ProjectPerms(t *testing.T) {
3030

3131
newWf := sdk.Workflow{
3232
Name: sdk.RandomString(10),
33-
WorkflowData: &sdk.WorkflowData{
33+
WorkflowData: sdk.WorkflowData{
3434
Node: sdk.Node{
3535
Name: "root",
3636
Type: sdk.NodeTypePipeline,

engine/api/repositories_manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ func (api *API) attachRepositoriesManagerHandler() service.Handler {
557557
return err
558558
}
559559

560+
// second load for publish the event below
560561
wfOld, err := workflow.LoadByID(ctx, db, api.Cache, *proj, wf.ID, workflow.LoadOptions{})
561562
if err != nil {
562563
return err
@@ -585,7 +586,7 @@ func (api *API) attachRepositoriesManagerHandler() service.Handler {
585586

586587
wfDB.WorkflowData.Node.Context.DefaultPayload = defaultPayload
587588

588-
if err := workflow.Update(ctx, db, api.Cache, *proj, wfDB, workflow.UpdateOptions{DisableHookManagement: true, OldWorkflow: wfOld}); err != nil {
589+
if err := workflow.Update(ctx, db, api.Cache, *proj, wfDB, workflow.UpdateOptions{DisableHookManagement: true}); err != nil {
589590
return sdk.WrapError(err, "cannot update node context %d", wf.WorkflowData.Node.Context.ID)
590591
}
591592

engine/api/repositories_manager_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ func TestAPI_detachRepositoriesManagerHandler(t *testing.T) {
139139
if err := enc.Encode(pr); err != nil {
140140
return writeError(w, err)
141141
}
142+
case "/vcs/github/repos/sguiheux/demo/hooks?url=http%3A%2F%2Flolcat.host&id=666":
143+
// do nothing
142144
default:
143145
t.Fatalf("UNKNOWN ROUTE: %s", r.URL.String())
144146
}
@@ -194,7 +196,7 @@ vcs_ssh_key: proj-blabla
194196
Name: "test_1",
195197
ProjectID: proj.ID,
196198
ProjectKey: proj.Key,
197-
WorkflowData: &sdk.WorkflowData{
199+
WorkflowData: sdk.WorkflowData{
198200
Node: sdk.Node{
199201
Name: "node1",
200202
Ref: "node1",

engine/api/test/assets/assets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func InsertTestWorkflow(t *testing.T, db gorp.SqlExecutor, store cache.Store, pr
534534
Name: name,
535535
ProjectID: proj.ID,
536536
ProjectKey: proj.Key,
537-
WorkflowData: &sdk.WorkflowData{
537+
WorkflowData: sdk.WorkflowData{
538538
Node: sdk.Node{
539539
Name: "node1",
540540
Ref: "node1",

engine/api/worker_model_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func Test_WorkerModelUsage(t *testing.T) {
253253
Name: "workflow1",
254254
ProjectID: proj.ID,
255255
ProjectKey: proj.Key,
256-
WorkflowData: &sdk.WorkflowData{
256+
WorkflowData: sdk.WorkflowData{
257257
Node: sdk.Node{
258258
Name: "root",
259259
Context: &sdk.NodeContext{

engine/api/workflow.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,6 @@ func (api *API) postWorkflowHandler() service.Handler {
368368
return err
369369
}
370370

371-
if data.WorkflowData == nil {
372-
return sdk.WrapError(sdk.ErrWrongRequest, "no node found")
373-
}
374-
375371
if err := workflow.RenameNode(ctx, api.mustDB(), &data); err != nil {
376372
return err
377373
}
@@ -457,7 +453,7 @@ func (api *API) putWorkflowHandler() service.Handler {
457453
}
458454
defer tx.Rollback() // nolint
459455

460-
if err := workflow.Update(ctx, tx, api.Cache, *p, &wf, workflow.UpdateOptions{OldWorkflow: oldW}); err != nil {
456+
if err := workflow.Update(ctx, tx, api.Cache, *p, &wf, workflow.UpdateOptions{}); err != nil {
461457
return sdk.WrapError(err, "cannot update workflow")
462458
}
463459

0 commit comments

Comments
 (0)