Skip to content

Commit

Permalink
fix(api): interpolate should not be replaced git.branch as git__branch (
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored and sguiheux committed Apr 9, 2018
1 parent 5002f14 commit d9c9beb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sdk/interpolate/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ func Do(input string, vars map[string]string) (string, error) {
if v == "" {
empty[k] = k
}
input = strings.Replace(input, k, kb, -1)
//The key should be used as a variable to be replaced
kAsVar := "{{." + k
kbAsVar := "{{." + kb
input = strings.Replace(input, kAsVar, kbAsVar, -1)
kAsVar = "{{. " + k
kbAsVar = "{{. " + kb
input = strings.Replace(input, kAsVar, kbAsVar, -1)
}

var helper string
Expand Down
27 changes: 27 additions & 0 deletions sdk/interpolate/interpolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ func TestDo(t *testing.T) {
},
want: `{"HOST": "customermyprefix.lb"}`,
},
{
name: "git.branch in payload should not be interpolated",
args: args{
input: `
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
vars: map[string]string{
"git.branch": "master",
"git.author": "",
},
},
want: `
name: "w{{.cds.pip.docker.image}}-generated"
version: v1.0
workflow:
build-go:
pipeline: build-go-generated
payload:
git.author: ""
git.branch: master`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit d9c9beb

Please sign in to comment.