Repository: diggerhq/digger
Pull request #262 (2023-05-16 14:05:28)

change CollectUsageData *bool to bool


Patch:
diff --git a/pkg/configuration/digger_config.go b/pkg/configuration/digger_config.go
index 3bade0f9..6c867960 100644
--- a/pkg/configuration/digger_config.go
+++ b/pkg/configuration/digger_config.go
@@ -21,7 +21,7 @@ type DiggerConfigYaml struct {
 	Projects               []Project               `yaml:"projects"`
 	AutoMerge              bool                    `yaml:"auto_merge"`
 	Workflows              map[string]Workflow     `yaml:"workflows"`
-	CollectUsageData       *bool                   `yaml:"collect_usage_data"`
+	CollectUsageData       bool                    `yaml:"collect_usage_data"`
 	GenerateProjectsConfig *GenerateProjectsConfig `yaml:"generate_projects"`
 }
 
@@ -34,7 +34,7 @@ type EnvVarConfig struct {
 type DiggerConfig struct {
 	Projects         []Project
 	AutoMerge        bool
-	CollectUsageData *bool
+	CollectUsageData bool
 	Workflows        map[string]Workflow
 }
 
diff --git a/pkg/digger/digger.go b/pkg/digger/digger.go
index ff69f80b..707fa728 100644
--- a/pkg/digger/digger.go
+++ b/pkg/digger/digger.go
@@ -358,18 +358,17 @@ type DiggerExecutor struct {
 }
 
 type CommandRun interface {
-	Run(workingDir string, shell string, command string) (string, string, error)
+	Run(shell string, command string) (string, string, error)
 }
 
 type CommandRunner struct {
 }
 
-func (c CommandRunner) Run(workingDir string, shell string, command string) (string, string, error) {
+func (c CommandRunner) Run(shell string, command string) (string, string, error) {
 	if shell == "" {
 		shell = "bash"
 	}
 	cmd := exec.Command(shell, "-c", command)
-	cmd.Dir = workingDir
 
 	var stdout, stderr bytes.Buffer
 	mwout := io.MultiWriter(os.Stdout, &stdout)
@@ -443,7 +442,7 @@ func (d DiggerExecutor) Plan(prNumber int) error {
 				d.CIService.PublishComment(prNumber, comment)
 			}
 			if step.Action == "run" {
-				stdout, stderr, err := d.CommandRunner.Run(d.ProjectPath, step.Shell, step.Value)
+				stdout, stderr, err := d.CommandRunner.Run(step.Shell, step.Value)
 				log.Printf("Running %v for **%v**\n%v%v", step.Value, d.ProjectLock.LockId(), stdout, stderr)
 				if err != nil {
 					return fmt.Errorf("error running command: %v", err)
@@ -507,7 +506,7 @@ func (d DiggerExecutor) Apply(prNumber int) error {
 					}
 				}
 				if step.Action == "run" {
-					stdout, stderr, err := d.CommandRunner.Run(d.ProjectPath, step.Shell, step.Value)
+					stdout, stderr, err := d.CommandRunner.Run(step.Shell, step.Value)
 					log.Printf("Running %v for **%v**\n%v%v", step.Value, d.ProjectLock.LockId(), stdout, stderr)
 					if err != nil {
 						return fmt.Errorf("error running command: %v", err)
diff --git a/pkg/utils/usage.go b/pkg/utils/usage.go
index d24e3839..d953438e 100644
--- a/pkg/utils/usage.go
+++ b/pkg/utils/usage.go
@@ -81,9 +81,9 @@ func init() {
 	if err != nil {
 		return
 	}
-	if config.CollectUsageData != nil && !*config.CollectUsageData {
+	if !config.CollectUsageData {
 		collect_usage_data = false
-	} else if config.CollectUsageData == nil && os.Getenv("COLLECT_USAGE_DATA") == "false" {
+	} else if os.Getenv("COLLECT_USAGE_DATA") == "false" {
 		collect_usage_data = false
 	} else {
 		collect_usage_data = true


Test patch:
diff --git a/pkg/digger/digger_test.go b/pkg/digger/digger_test.go
index 3743e734..5db3f5a3 100644
--- a/pkg/digger/digger_test.go
+++ b/pkg/digger/digger_test.go
@@ -21,8 +21,8 @@ type MockCommandRunner struct {
 	Commands []RunInfo
 }
 
-func (m *MockCommandRunner) Run(workDir string, shell string, command string) (string, string, error) {
-	m.Commands = append(m.Commands, RunInfo{"Run", workDir + " " + shell + " " + command, time.Now()})
+func (m *MockCommandRunner) Run(shell string, command string) (string, string, error) {
+	m.Commands = append(m.Commands, RunInfo{"Run", shell + " " + command, time.Now()})
 	return "", "", nil
 }
 
@@ -182,7 +182,7 @@ func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock, planStorage)
 
-	assert.Equal(t, []string{"RetrievePlan #.tfplan", "IsMergeable 1", "Lock 1", "Init ", "Apply ", "LockId ", "PublishComment 1 <details>\n  <summary>Apply for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run   echo", "LockId "}, commandStrings)
+	assert.Equal(t, []string{"RetrievePlan #.tfplan", "IsMergeable 1", "Lock 1", "Init ", "Apply ", "LockId ", "PublishComment 1 <details>\n  <summary>Apply for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run  echo", "LockId "}, commandStrings)
 }
 
 func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
@@ -224,7 +224,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock, planStorage)
 
-	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out #.tfplan", "StorePlan #.tfplan", "LockId ", "PublishComment 1 <details>\n  <summary>Plan for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run   echo", "LockId "}, commandStrings)
+	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out #.tfplan", "StorePlan #.tfplan", "LockId ", "PublishComment 1 <details>\n  <summary>Plan for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run  echo", "LockId "}, commandStrings)
 }
 
 func allCommandsInOrderWithParams(terraformExecutor *MockTerraformExecutor, commandRunner *MockCommandRunner, prManager *MockPRManager, lock *MockProjectLock, planStorage *MockPlanStorage) []string {