Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow brackets inside Tekton expressions #375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pkg/template/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func applyEventValuesToParams(params []pipelinev1.Param, body []byte, header htt
for idx, p := range params {
pValue := p.Value.StringVal
// Find all expressions wrapped in $() from the value
expressions := tektonVar.FindAllString(pValue, -1)
expressions := findTektonExpressions(pValue)
for _, expr := range expressions {
val, err := ParseJSONPath(event, expr)
if err != nil {
Expand All @@ -100,3 +100,24 @@ func applyEventValuesToParams(params []pipelinev1.Param, body []byte, header htt
}
return params, nil
}

// findTektonExpressions searches for and returns a slice of
// all substrings that are wrapped in $()
func findTektonExpressions(in string) []string {
results := []string{}

// No expressions to return
if !strings.Contains(in, "$(") {
return results
}
// Splits string on $( to find potential Tekton expressions
s := strings.Split(in, "$(")
for _, i := range s {
// Only a Tekton expression if it also contains a ) following the $(
if strings.Contains(i, ")") {
// Extract until the last instance of ) and wrap it in $()
results = append(results, fmt.Sprintf("$(%s)", i[:strings.LastIndex(i, ")")]))
}
}
return results
}
Loading