nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: replicatedhq/kots
Pull request #161 (2019-11-26 19:51:49)

Fix request URL when channel is specified in upstream


Patch:
diff --git a/pkg/upstream/replicated.go b/pkg/upstream/replicated.go
index 0611a24d7..103710f71 100644
--- a/pkg/upstream/replicated.go
+++ b/pkg/upstream/replicated.go
@@ -215,12 +215,11 @@ func (r *ReplicatedUpstream) getRequest(method string, license *kotsv1beta1.Lice
 		hostname = fmt.Sprintf("%s:%s", u.Hostname(), u.Port())
 	}
 
-	url := fmt.Sprintf("%s://%s/release/%s?channelSequence=%s", u.Scheme, hostname, license.Spec.AppSlug, channelSequence)
-
+	urlPath := path.Join(hostname, "release", license.Spec.AppSlug)
 	if r.Channel != nil {
-		// NOTE: I don't believe this is used
-		url = fmt.Sprintf("%s/%s", url, *r.Channel)
+		urlPath = path.Join(urlPath, *r.Channel)
 	}
+	url := fmt.Sprintf("%s://%s?channelSequence=%s", u.Scheme, urlPath, channelSequence)
 
 	req, err := http.NewRequest(method, url, nil)
 	if err != nil {


Test patch:
diff --git a/pkg/upstream/replicated_test.go b/pkg/upstream/replicated_test.go
index 32c166e8e..29e7997a8 100644
--- a/pkg/upstream/replicated_test.go
+++ b/pkg/upstream/replicated_test.go
@@ -263,3 +263,53 @@ func Test_createConfigValues(t *testing.T) {
 	req.NoError(err)
 	assert.Equal(t, expected3, values3.Spec.Values)
 }
+
+func Test_getRequest(t *testing.T) {
+	beta := "beta"
+	unstable := "unstable"
+	tests := []struct {
+		endpoint        string
+		appSlug         string
+		channel         *string
+		channelSequence string
+		expectedURL     string
+	}{
+		{
+			endpoint:        "https://replicated-app",
+			appSlug:         "sluggy1",
+			channel:         nil,
+			channelSequence: "",
+			expectedURL:     "https://replicated-app/release/sluggy1?channelSequence=",
+		},
+		{
+			endpoint:        "http://localhost:30016",
+			appSlug:         "sluggy2",
+			channel:         &beta,
+			channelSequence: "",
+			expectedURL:     "http://localhost:30016/release/sluggy2/beta?channelSequence=",
+		},
+		{
+			endpoint:        "https://replicated-app",
+			appSlug:         "sluggy3",
+			channel:         &unstable,
+			channelSequence: "10",
+			expectedURL:     "https://replicated-app/release/sluggy3/unstable?channelSequence=10",
+		},
+	}
+
+	req := require.New(t)
+	for _, test := range tests {
+		license := &kotsv1beta1.License{
+			Spec: kotsv1beta1.LicenseSpec{
+				Endpoint: test.endpoint,
+				AppSlug:  test.appSlug,
+			},
+		}
+		r := &ReplicatedUpstream{
+			Channel: test.channel,
+		}
+		request, err := r.getRequest("GET", license, test.channelSequence)
+		req.NoError(err)
+		assert.Equal(t, test.expectedURL, request.URL.String())
+	}
+}
Repository: replicatedhq/kots
Pull request #163 (2019-11-27 17:58:31)

support for repl{{ }} delimiters in templates


Patch:
diff --git a/pkg/template/builder.go b/pkg/template/builder.go
index 7852954bb..3b3ea5a7b 100644
--- a/pkg/template/builder.go
+++ b/pkg/template/builder.go
@@ -143,8 +143,8 @@ func (b *Builder) BuildFuncMap() template.FuncMap {
 	return funcMap
 }
 
-func (b *Builder) GetTemplate(name, text string) (*template.Template, error) {
-	tmpl, err := template.New(name).Delims("{{repl ", "}}").Funcs(b.BuildFuncMap()).Parse(text)
+func (b *Builder) GetTemplate(name, text string, rdelim, ldelim string) (*template.Template, error) {
+	tmpl, err := template.New(name).Delims(rdelim, ldelim).Funcs(b.BuildFuncMap()).Parse(text)
 	if err != nil {
 		return nil, err
 	}
@@ -153,15 +153,27 @@ func (b *Builder) GetTemplate(name, text string) (*template.Template, error) {
 }
 
 func (b *Builder) RenderTemplate(name string, text string) (string, error) {
-	tmpl, err := b.GetTemplate(name, text)
-	if err != nil {
-		return "", errors.Wrap(err, "failed to get template")
-	}
+	delims := []struct {
+		rdelim string
+		ldelim string
+	}{
+		{"{{repl", "}}"},
+		{"repl{{", "}}"},
+	}
+
+	curText := text
+	for _, d := range delims {
+		tmpl, err := b.GetTemplate(name, curText, d.rdelim, d.ldelim)
+		if err != nil {
+			return "", errors.Wrap(err, "failed to get template")
+		}
 
-	var contents bytes.Buffer
-	if err := tmpl.Execute(&contents, nil); err != nil {
-		return "", errors.Wrap(err, "failed to execute template")
+		var contents bytes.Buffer
+		if err := tmpl.Execute(&contents, nil); err != nil {
+			return "", errors.Wrap(err, "failed to execute template")
+		}
+		curText = contents.String()
 	}
 
-	return contents.String(), nil
+	return curText, nil
 }


Test patch:
diff --git a/pkg/template/builder_test.go b/pkg/template/builder_test.go
index b39529b46..7200517a8 100644
--- a/pkg/template/builder_test.go
+++ b/pkg/template/builder_test.go
@@ -110,7 +110,7 @@ func TestBuildStrings(t *testing.T) {
 		},
 		strcase{
 			Name:     "Test ToUpper",
-			Template: `{{repl ToUpper "ABcd87-()"}}`,
+			Template: `repl{{ (ToUpper "ABcd87-()") }}`,
 			Expected: "ABCD87-()",
 		},
 		strcase{
@@ -125,7 +125,7 @@ func TestBuildStrings(t *testing.T) {
 		},
 		strcase{
 			Name:     "Test UrlEncode",
-			Template: `{{repl UrlEncode "?some url unsafe=%value"}}`,
+			Template: `repl{{ UrlEncode "?some url unsafe=%value"}}`,
 			Expected: "%3Fsome+url+unsafe%3D%25value",
 		},
 		strcase{
@@ -180,7 +180,7 @@ func TestBuildStrings(t *testing.T) {
 		},
 		uintcase{
 			Name:     "Test ParseUint",
-			Template: `{{repl ParseUint "15"}}`,
+			Template: `repl{{ ParseUint "15"}}`,
 			Expected: 15,
 		},
 		floatcase{