mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 12:21:03 +00:00
23 lines
412 B
Go
23 lines
412 B
Go
package script
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func Inject(script string, params map[string]string) string {
|
|
if params == nil {
|
|
return script
|
|
}
|
|
keys := []string{}
|
|
for k, _ := range params {
|
|
keys = append(keys, k)
|
|
}
|
|
sort.Sort(sort.Reverse(sort.StringSlice(keys)))
|
|
injected := script
|
|
for _, k := range keys {
|
|
v := params[k]
|
|
injected = strings.Replace(injected, "$$"+k, v, -1)
|
|
}
|
|
return injected
|
|
}
|