forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_git.go
More file actions
34 lines (29 loc) · 797 Bytes
/
function_git.go
File metadata and controls
34 lines (29 loc) · 797 Bytes
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
package function
import (
"fmt"
"strings"
giturls "github.com/whilp/git-urls"
)
type Git struct {
URL string `yaml:"url,omitempty"`
Revision string `yaml:"revision,omitempty"`
ContextDir string `yaml:"contextDir,omitempty"`
}
// validateGit validates input Git option from Function config
func validateGit(git Git) (errors []string) {
if git.URL != "" {
_, err := giturls.ParseTransport(git.URL)
if err != nil {
_, err = giturls.ParseScp(git.URL)
}
if err != nil {
errMsg := fmt.Sprintf("specified option \"git.url=%s\" is not valid", git.URL)
originalErr := err.Error()
if !strings.HasSuffix(originalErr, "is not a valid transport") {
errMsg = fmt.Sprintf("%s, error: %s", errMsg, originalErr)
}
errors = append(errors, errMsg)
}
}
return
}