-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpipeline.go
41 lines (32 loc) · 957 Bytes
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"errors"
"regexp"
"strings"
)
// Pipe is an interface for plugins that can be used to generate a branch name from summary
type Pipe func(s string, args ...string) (string, error)
func ToLower(s string, args ...string) (string, error) {
return strings.ToLower(s), nil
}
func Replace(s string, args ...string) (string, error) {
if len(args) < 2 {
return s, errors.New("invalid function usage: replace <string> <old> <new>")
}
return strings.ReplaceAll(s, args[0], args[1]), nil
}
func ReplaceRegexp(s string, args ...string) (string, error) {
if len(args) < 2 {
return s, errors.New("invalid function usage: replace_regexp <string> <regexp> <new>")
}
reg, err := regexp.Compile(args[0])
if err != nil {
return s, err
}
return reg.ReplaceAllString(s, args[1]), nil
}
var PipelineMap map[string]Pipe = map[string]Pipe{
"to_lower": ToLower,
"replace_regexp": ReplaceRegexp,
"replace": Replace,
}