Repository: diggerhq/digger
Pull request #355 (2023-06-12 11:39:14)

fix: handle extra args with identations


Patch:
diff --git a/pkg/configuration/digger_config.go b/pkg/configuration/digger_config.go
index f6a4d103..8992a579 100644
--- a/pkg/configuration/digger_config.go
+++ b/pkg/configuration/digger_config.go
@@ -232,6 +232,13 @@ func (s *Step) extract(stepMap map[string]interface{}, action string) {
 				extraArgs = append(extraArgs, v.(string))
 			}
 			s.ExtraArgs = extraArgs
+		} else {
+			if v, ok := stepMap[action].(map[string]interface{})["extra_args"]; ok {
+				for _, v := range v.([]interface{}) {
+					extraArgs = append(extraArgs, v.(string))
+				}
+				s.ExtraArgs = extraArgs
+			}
 		}
 	}
 }
diff --git a/pkg/github/github.go b/pkg/github/github.go
index 0aeac2aa..f85e8400 100644
--- a/pkg/github/github.go
+++ b/pkg/github/github.go
@@ -145,8 +145,10 @@ func ConvertGithubEventToCommands(event models.Event, impactedProjects []configu
 			}
 
 			stateEnvVars, commandEnvVars := configuration.CollectEnvVars(workflow.EnvVars)
+
 			coreApplyStage := workflow.Apply.ToCoreStage()
 			corePlanStage := workflow.Plan.ToCoreStage()
+
 			if event.Action == "closed" && event.PullRequest.Merged && event.PullRequest.Base.Ref == event.Repository.DefaultBranch {
 				commandsPerProject = append(commandsPerProject, dg_models.ProjectCommand{
 					ProjectName:      project.Name,


Test patch:
diff --git a/pkg/configuration/digger_config_test.go b/pkg/configuration/digger_config_test.go
index d7d9f641..54fb2ead 100644
--- a/pkg/configuration/digger_config_test.go
+++ b/pkg/configuration/digger_config_test.go
@@ -194,24 +194,38 @@ func TestDefaultValuesForWorkflowConfiguration(t *testing.T) {
 	diggerCfg := `
 projects:
 - name: dev
+  dir: .
+  workflow: dev
+
 workflows:
+  dev:
+    plan:
+      steps:
+        - run: rm -rf .terraform
+        - init
+        - plan:
+          extra_args: ["-var-file=vars/dev.tfvars"]  
   default:
     plan:
       steps:
-      - init
-      - plan:
-        extra_args: ["-var-file=terraform.tfvars"]
-      - run: echo "hello"
-        shell: zsh
+        - run: rm -rf .terraform
+        - init
+        - plan:
+            extra_args: ["-var-file=vars/dev.tfvars"]
+
 `
 	deleteFile := createFile(path.Join(tempDir, "digger.yaml"), diggerCfg)
 	defer deleteFile()
 
 	dg, err := LoadDiggerConfig(tempDir, &FileSystemDirWalker{})
 	assert.NoError(t, err, "expected error to be nil")
-	assert.Equal(t, Step{Action: "init", ExtraArgs: nil, Shell: ""}, dg.Workflows["default"].Plan.Steps[0], "parsed struct does not match expected struct")
-	assert.Equal(t, Step{Action: "plan", ExtraArgs: []string{"-var-file=terraform.tfvars"}, Shell: ""}, dg.Workflows["default"].Plan.Steps[1], "parsed struct does not match expected struct")
-	assert.Equal(t, Step{Action: "run", Value: "echo \"hello\"", Shell: "zsh"}, dg.Workflows["default"].Plan.Steps[2], "parsed struct does not match expected struct")
+	assert.Equal(t, Step{Action: "run", Value: "rm -rf .terraform", Shell: ""}, dg.Workflows["dev"].Plan.Steps[0], "parsed struct does not match expected struct")
+	assert.Equal(t, Step{Action: "init", ExtraArgs: nil, Shell: ""}, dg.Workflows["dev"].Plan.Steps[1], "parsed struct does not match expected struct")
+	assert.Equal(t, Step{Action: "plan", ExtraArgs: []string{"-var-file=vars/dev.tfvars"}, Shell: ""}, dg.Workflows["dev"].Plan.Steps[2], "parsed struct does not match expected struct")
+
+	assert.Equal(t, Step{Action: "run", Value: "rm -rf .terraform", Shell: ""}, dg.Workflows["default"].Plan.Steps[0], "parsed struct does not match expected struct")
+	assert.Equal(t, Step{Action: "init", ExtraArgs: nil, Shell: ""}, dg.Workflows["default"].Plan.Steps[1], "parsed struct does not match expected struct")
+	assert.Equal(t, Step{Action: "plan", ExtraArgs: []string{"-var-file=vars/dev.tfvars"}, Shell: ""}, dg.Workflows["default"].Plan.Steps[2], "parsed struct does not match expected struct")
 }
 
 func TestDiggerGenerateProjects(t *testing.T) {