nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: diggerhq/digger
Pull request #128 (2023-04-12 15:06:41)

fix: add validation for missing projects in digger.yaml
https://github.com/diggerhq/digger/issues/114


Patch:
diff --git a/pkg/configuration/digger_config.go b/pkg/configuration/digger_config.go
index f07fb5d3..0a4e017b 100644
--- a/pkg/configuration/digger_config.go
+++ b/pkg/configuration/digger_config.go
@@ -175,8 +175,7 @@ func NewDiggerConfig(workingDir string, walker DirWalker) (*DiggerConfig, error)
 		}
 	}
 
-	data, err := os.ReadFile(fileName)
-	if err != nil {
+	if fileName == "" {
 		config.Projects = make([]Project, 1)
 		config.Projects[0] = defaultProject()
 		config.Workflows = make(map[string]Workflow)
@@ -212,10 +211,19 @@ func NewDiggerConfig(workingDir string, walker DirWalker) (*DiggerConfig, error)
 		return c, nil
 	}
 
+	data, err := os.ReadFile(fileName)
+	if err != nil {
+		return nil, fmt.Errorf("failed to read config file %s: %v", fileName, err)
+	}
+
 	if err := yaml.Unmarshal(data, config); err != nil {
 		return nil, fmt.Errorf("error parsing '%s': %v", fileName, err)
 	}
 
+	if (config.Projects == nil || len(config.Projects) == 0) && config.GenerateProjectsConfig == nil {
+		return nil, fmt.Errorf("no projects configuration found in '%s'", fileName)
+	}
+
 	c, err := ConvertDiggerYamlToConfig(config, workingDir, walker)
 	if err != nil {
 		return nil, err


Test patch:
diff --git a/pkg/configuration/digger_config_test.go b/pkg/configuration/digger_config_test.go
index d72a370a..5fe0e794 100644
--- a/pkg/configuration/digger_config_test.go
+++ b/pkg/configuration/digger_config_test.go
@@ -97,6 +97,8 @@ func TestDefaultValuesForWorkflowConfiguration(t *testing.T) {
 	defer teardown()
 
 	diggerCfg := `
+projects:
+- name: dev
 workflows:
   default:
     plan:
@@ -201,6 +203,20 @@ generate_projects:
 	assert.Equal(t, 1, len(dg.Projects))
 }
 
+func TestMissingProjectsReturnsError(t *testing.T) {
+	tempDir, teardown := setUp()
+	defer teardown()
+
+	diggerCfg := `
+`
+	deleteFile := createFile(path.Join(tempDir, "digger.yaml"), diggerCfg)
+	defer deleteFile()
+	walker := &MockDirWalker{}
+
+	_, err := NewDiggerConfig(tempDir, walker)
+	assert.ErrorContains(t, err, "no projects configuration found")
+}
+
 func createTempDir() string {
 	dir, err := os.MkdirTemp("", "tmp")
 	if err != nil {
Repository: diggerhq/digger
Pull request #163 (2023-04-25 11:52:10)

fix: add fix plan args


Patch:
diff --git a/pkg/digger/digger.go b/pkg/digger/digger.go
index 90a5cf14..7db0ca89 100644
--- a/pkg/digger/digger.go
+++ b/pkg/digger/digger.go
@@ -365,7 +365,7 @@ func (d DiggerExecutor) Plan(prNumber int) error {
 			if step.Action == "plan" {
 				planArgs := []string{"-out", d.planFileName()}
 				planArgs = append(planArgs, step.ExtraArgs...)
-				isNonEmptyPlan, stdout, stderr, err := d.terraformExecutor.Plan(step.ExtraArgs)
+				isNonEmptyPlan, stdout, stderr, err := d.terraformExecutor.Plan(planArgs)
 				if err != nil {
 					return fmt.Errorf("error executing plan: %v", err)
 				}


Test patch:
diff --git a/pkg/digger/digger_test.go b/pkg/digger/digger_test.go
index 06e01ef9..b1ba052b 100644
--- a/pkg/digger/digger_test.go
+++ b/pkg/digger/digger_test.go
@@ -196,7 +196,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock)
 
-	assert.Equal(t, []string{"Lock 1", "Init ", "Plan ", "LockId ", "PublishComment 1 Plan for ****\n```terraform\n\n```", "Run echo", "LockId ", "PublishComment 1 Running echo for ****\n"}, commandStrings)
+	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out .tfplan", "LockId ", "PublishComment 1 Plan for ****\n```terraform\n\n```", "Run echo", "LockId ", "PublishComment 1 Running echo for ****\n"}, commandStrings)
 }
 
 func allCommandsInOrderWithParams(terraformExecutor *MockTerraformExecutor, commandRunner *MockCommandRunner, prManager *MockPRManager, lock *MockProjectLock) []string {