nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: aws-cloudformation/rain
Pull request #34 (2020-10-11 00:27:46)

Fix for bare timestamps in yaml being converted to dates
*Issue #, if available:*

*Description of changes:*

When parsing templates with timestamp versions `rain` would fail.

This at the top of a template would break it.

```
"AWSTemplateFormatVersion": 2010-09-09
```

So to mitigate this I am using the transform to ensure all timestamps are converted to strings.

I have added testes to illustrate the problem, these fail without the change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.



Patch:
diff --git a/cfn/parse/transform.go b/cfn/parse/transform.go
index 3baba3f0..4dca0d63 100644
--- a/cfn/parse/transform.go
+++ b/cfn/parse/transform.go
@@ -32,6 +32,11 @@ func transform(node *yaml.Node) {
 		node.Tag = "!!str"
 	}
 
+	// Fix badly-parsed timestamps which are often used for versions in cloudformation
+	if node.ShortTag() == "!!timestamp" {
+		node.Tag = "!!str"
+	}
+
 	// See if we're dealing with a Fn:: tag
 	for _, tag := range tags {
 		if node.ShortTag() == "!"+tag {


Test patch:
diff --git a/cfn/parse/parse_test.go b/cfn/parse/parse_test.go
index a486ea0b..c200e148 100644
--- a/cfn/parse/parse_test.go
+++ b/cfn/parse/parse_test.go
@@ -51,6 +51,22 @@ var expected = cfn.Template(map[string]interface{}{
 				},
 			},
 		},
+		"ExecutionRole": map[string]interface{}{
+			"Properties": map[string]interface{}{
+				"AssumeRolePolicyDocument": map[string]interface{}{
+					"Statement": []interface{}{
+						map[string]interface{}{
+							"Action":    "sts:AssumeRole",
+							"Effect":    "Allow",
+							"Principal": map[string]interface{}{"Service": "lambda.amazonaws.com"},
+						},
+					},
+					"Version": "2012-10-17",
+				},
+				"Path": "/",
+			},
+			"Type": "AWS::IAM::Role",
+		},
 	},
 	"Outputs": map[string]interface{}{
 		"Bucket1Arn": map[string]interface{}{
@@ -75,6 +91,7 @@ var expected = cfn.Template(map[string]interface{}{
 			},
 		},
 	},
+	"AWSTemplateFormatVersion": "2010-09-09",
 })
 
 func init() {
diff --git a/cfn/parse/test.yaml b/cfn/parse/test.yaml
index cf9e215e..5aeea149 100644
--- a/cfn/parse/test.yaml
+++ b/cfn/parse/test.yaml
@@ -25,6 +25,18 @@ Resources:
       BucketName: !Base64
         Ref: Cakes
 
+  ExecutionRole:
+    Type: AWS::IAM::Role
+    Properties:
+      AssumeRolePolicyDocument:
+        Version: 2012-10-17
+        Statement:
+          - Effect: Allow
+            Principal:
+              Service: lambda.amazonaws.com
+            Action: sts:AssumeRole
+      Path: /
+
 Outputs:
   Bucket1Arn:
     Value: !GetAtt Bucket1.Arn
@@ -35,3 +47,4 @@ Outputs:
       Fn::GetAtt:
         - Bucket2
         - Arn
+AWSTemplateFormatVersion: 2010-09-09
Repository: aws-cloudformation/rain
Pull request #104 (2023-02-15 16:12:19)

build now omits the properties field in template if properties is empty
*Issue #, if available:*

*Description of changes:* rain build will now omit the `Properties` field if it's empty. example:

before:

`rain build AWS::S3::Bucket -b`
```
AWSTemplateFormatVersion: "2010-09-09"

Description: Template generated by rain

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties: {}
```

now:

`rain build AWS::S3::Bucket -b`
```
AWSTemplateFormatVersion: "2010-09-09"

Description: Template generated by rain

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
```

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.



Patch:
diff --git a/cft/build/build.go b/cft/build/build.go
index 435d04b4..f299d2bd 100644
--- a/cft/build/build.go
+++ b/cft/build/build.go
@@ -98,10 +98,16 @@ func (b builder) newResource(resourceType string) (map[string]interface{}, []*cf
 		}
 	}
 
-	return map[string]interface{}{
+	resource := map[string]interface{}{
 		"Type":       resourceType,
 		"Properties": properties,
-	}, comments
+	}
+
+	if len(properties) == 0 {
+		delete(resource, "Properties")
+	}
+
+	return resource, comments
 }
 
 func (b builder) newProperty(resourceType, propertyName string, pSpec *spec.Property) (interface{}, []*cft.Comment) {


Test patch:
diff --git a/internal/cmd/build/build_test.go b/internal/cmd/build/build_test.go
index 36b52be1..959fff4b 100644
--- a/internal/cmd/build/build_test.go
+++ b/internal/cmd/build/build_test.go
@@ -22,5 +22,4 @@ func Example_build_bucket() {
 	// Resources:
 	//   MyBucket:
 	//     Type: AWS::S3::Bucket
-	//     Properties: {}
 }
Repository: aws-cloudformation/rain
Pull request #119 (2023-04-14 21:17:54)

Fix DependsOn in module extension


Patch:
diff --git a/cft/pkg/module.go b/cft/pkg/module.go
index 02bd120a..937702e3 100644
--- a/cft/pkg/module.go
+++ b/cft/pkg/module.go
@@ -70,7 +70,11 @@ func addPolicy(ext *yaml.Node, name string, moduleExtension *yaml.Node, template
 
 // Rename a resource defined in the module to add the template resource name
 func rename(logicalId string, resourceName string) string {
-	return logicalId + resourceName
+	if resourceName == "ModuleExtension" {
+		return logicalId
+	} else {
+		return logicalId + resourceName
+	}
 }
 
 // Recursive function to find all refs in properties
@@ -228,11 +232,6 @@ func processModule(module *yaml.Node,
 			return false, errors.New("expected ModuleExtension.Metadata.Extends")
 		}
 
-		_, moduleProps := s11n.GetMapValue(moduleExtension, "Properties")
-		if moduleProps == nil {
-			return false, errors.New("expected ModuleExtension.Properties")
-		}
-
 		// Create a new node to contain the extended resource.
 		// This will be added to the template, and the original resource node will be removed
 		ext := &yaml.Node{}


Test patch:
diff --git a/test/modules/bucket.yaml b/test/modules/bucket.yaml
index 51e0fe7c..0d918748 100644
--- a/test/modules/bucket.yaml
+++ b/test/modules/bucket.yaml
@@ -76,4 +76,9 @@ Resources:
   AdditionalResource2:
     Type: AWS::S3::Bucket
 
+  DependsOnModuleExtension:
+    Type: AWS::S3::Bucket
+    DependsOn: ModuleExtension
+
+
 
diff --git a/test/modules/expect.yaml b/test/modules/expect.yaml
index fafca969..0c1570c7 100644
--- a/test/modules/expect.yaml
+++ b/test/modules/expect.yaml
@@ -69,6 +69,11 @@ Resources:
   ModuleExampleAdditionalResource2:
     Type: AWS::S3::Bucket
 
+  ModuleExampleDependsOnModuleExtension:
+    Type: AWS::S3::Bucket
+    DependsOn:
+      - ModuleExample
+
   WithoutExtensionBucketA:
     Type: AWS::S3::Bucket
     Properties:
diff --git a/test/modules/ext-ref.yaml b/test/modules/ext-ref.yaml
new file mode 100644
index 00000000..e327dd5e
--- /dev/null
+++ b/test/modules/ext-ref.yaml
@@ -0,0 +1,15 @@
+Description: |
+  For testing Refs on the ModuleExtension itself
+
+Resources:
+
+  ModuleExtension:
+    Metadata:
+      Extends: AWS::S3::Bucket
+
+  DependsOnModuleExtension:
+    Type: AWS::S3::Bucket
+    DependsOn: ModuleExtension
+
+
+
diff --git a/test/templates/ext-ref-module.yaml b/test/templates/ext-ref-module.yaml
new file mode 100644
index 00000000..6bc3e8d5
--- /dev/null
+++ b/test/templates/ext-ref-module.yaml
@@ -0,0 +1,8 @@
+Resources:
+
+  ModuleExample:
+    Type: !Rain::Module "file://../../modules/ext-ref.yaml"
+    Properties:
+      BucketName: ezbeard-cep-test-module-bucket
+
+
Repository: aws-cloudformation/rain
Pull request #198 (2023-09-14 00:24:46)

fix: support literal with chomping indicator
*Issue #110, if available:*
Sometimes YAML package generates multiline strings with chomping (e.g. |2+), but the rain format post-processing seems to ignore this.

*Description of changes:*
Change from an exact match of `|` or `>` to a regex match that complies with YAML spec.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.



Patch:
diff --git a/cft/format/format.go b/cft/format/format.go
index 369410b4..244f2712 100644
--- a/cft/format/format.go
+++ b/cft/format/format.go
@@ -3,6 +3,7 @@
 package format
 
 import (
+	"regexp"
 	"strings"
 
 	"github.com/aws-cloudformation/rain/cft"
@@ -21,6 +22,13 @@ type Options struct {
 	Unsorted bool
 }
 
+func CheckMultilineBegin(s string) bool {
+	// Match block header
+	// https://yaml.org/spec/1.2.2/#8112-block-chomping-indicator
+	r, _ := regexp.Compile("[|>](([0-9]*[+-])|([+-][0-9]*))?$")
+	return r.MatchString(s)
+}
+
 // String returns a string representation of the supplied cft.Template
 func String(t cft.Template, opt Options) string {
 	node := t.Node
@@ -70,7 +78,7 @@ func String(t cft.Template, opt Options) string {
 			}
 		}
 		trimmedRight := strings.TrimRight(part, " ")
-		if strings.HasSuffix(trimmedRight, "|") || strings.HasSuffix(trimmedRight, ">") {
+		if CheckMultilineBegin(trimmedRight) {
 			startMultilineIndent = indent
 		}
 


Test patch:
diff --git a/cft/format/format_test.go b/cft/format/format_test.go
index 3b32dc64..f887d21d 100644
--- a/cft/format/format_test.go
+++ b/cft/format/format_test.go
@@ -1,6 +1,7 @@
 package format_test
 
 import (
+	"strings"
 	"testing"
 
 	"github.com/aws-cloudformation/rain/cft/format"
@@ -383,6 +384,35 @@ const expectedUnsortedJson = `{
 }
 `
 
+const correctMultilineBlockHeaders = `
+|+
+|2+
+|+2
+|-
+|2-
+|-2
+>+
+>2+
+>+2
+>-
+>2-
+>-2
+|10+
+|+10
+>10+
+>+10
+`
+
+const wrongMultilineBlockHeaders = `
+|2+2
+>2+2
+|+2+
+>+2+
+|++
+>++
+>2+ a
+`
+
 func checkMatch(t *testing.T, expected string, opt format.Options) {
 	template, err := parse.String(input)
 	if err != nil {
@@ -396,6 +426,18 @@ func checkMatch(t *testing.T, expected string, opt format.Options) {
 	}
 }
 
+func checkMultilineBlockHeaders(t *testing.T, s string, expected bool) {
+	parts := strings.Split(s, "\n")
+	for _, part := range parts {
+		if part == "" {
+			continue
+		}
+		if format.CheckMultilineBegin(part) != expected {
+			t.Errorf(part)
+		}
+	}
+}
+
 func TestFormatDefault(t *testing.T) {
 	checkMatch(t, expectedYaml, format.Options{})
 	checkMatch(t, expectedYamlUnsorted, format.Options{
@@ -408,4 +450,6 @@ func TestFormatDefault(t *testing.T) {
 		JSON:     true,
 		Unsorted: true,
 	})
+	checkMultilineBlockHeaders(t, correctMultilineBlockHeaders, true)
+	checkMultilineBlockHeaders(t, wrongMultilineBlockHeaders, false)
 }