Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 7ca1a1d

Browse files
feat: add strings.ReplaceAll (#348)
Signed-off-by: Ryota Sakamoto <sakamo.ryota+github@gmail.com>
1 parent 138d46a commit 7ca1a1d

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

docs/functions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Returns an instance of Golang [Time](https://golang.org/pkg/time/#Time).
1212

1313
Parses specified string using RFC3339 layout. Returns an instance of Golang [Time](https://golang.org/pkg/time/#Time).
1414

15+
### **strings**
16+
String related functions.
17+
18+
<hr>
19+
**`strings.ReplaceAll() string`**
20+
21+
Executes function built-in Golang [strings.ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) function.
22+
1523
### **repo**
1624
Functions that provide additional information about Application source repository.
1725
<hr>
@@ -52,4 +60,4 @@ Returns application details. `AppDetail` fields:
5260
* `GetFileParameterPathByName(Name string)` Retrieve path by name in FileParameters field
5361
* `Ksonnet *apiclient.KsonnetAppSpec` - Ksonnet details
5462
* `Kustomize *apiclient.KustomizeAppSpec` - Kustomize details
55-
* `Directory *apiclient.DirectoryAppSpec` - Directory details
63+
* `Directory *apiclient.DirectoryAppSpec` - Directory details

expr/expr.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package expr
22

33
import (
44
"github.com/argoproj-labs/argocd-notifications/expr/repo"
5+
"github.com/argoproj-labs/argocd-notifications/expr/strings"
56
"github.com/argoproj-labs/argocd-notifications/expr/time"
67
"github.com/argoproj-labs/argocd-notifications/shared/argocd"
78
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -12,6 +13,7 @@ var helpers = map[string]interface{}{}
1213
func init() {
1314
helpers = make(map[string]interface{})
1415
register("time", time.NewExprs())
16+
register("strings", strings.NewExprs())
1517
}
1618

1719
func register(namespace string, entry map[string]interface{}) {

expr/expr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func TestExpr(t *testing.T) {
1010
namespaces := []string{
1111
"time",
1212
"repo",
13+
"strings",
1314
}
1415

1516
for _, ns := range namespaces {

expr/strings/strings.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package strings
2+
3+
import "strings"
4+
5+
func NewExprs() map[string]interface{} {
6+
return map[string]interface{}{
7+
"ReplaceAll": replaceAll,
8+
}
9+
}
10+
11+
func replaceAll(s, old, new string) string {
12+
return strings.ReplaceAll(s, old, new)
13+
}

expr/strings/strings_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package strings
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestNewExprs(t *testing.T) {
10+
funcs := []string{
11+
"ReplaceAll",
12+
}
13+
14+
for _, fn := range funcs {
15+
stringsExprs := NewExprs()
16+
_, hasFunc := stringsExprs[fn]
17+
assert.True(t, hasFunc)
18+
}
19+
}

0 commit comments

Comments
 (0)