This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
shared.go
83 lines (70 loc) · 1.79 KB
/
shared.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package connectors
import (
"regexp"
"strings"
"sigs.k8s.io/yaml"
)
type OwnerWithRepo struct {
Repo string
Owner string
}
type CICDPlatform struct {
Name string
RelevantFilesRegex string
GithubValid bool
GitlabValid bool
}
type PipelineFile struct {
RelativePath string `json:"relativePath"`
Filename string `json:"filename"`
Origin string `json:"origin"`
Content map[string]interface{} `json:"content"`
}
var SUPPORTED_CICD_PLATFORMS = []CICDPlatform{
{
Name: "github_actions",
RelevantFilesRegex: "\\.github/workflows/.*\\.ya?ml",
GithubValid: true,
GitlabValid: false,
},
{
Name: "jfrog_pipelines",
RelevantFilesRegex: "jfrog.*\\.ya?ml",
GithubValid: true,
GitlabValid: true,
},
{
Name: "gitlab_ci",
RelevantFilesRegex: "\\.gitlab-ci\\.ya?ml",
GithubValid: false,
GitlabValid: true,
},
// {
// Name: "jenkins",
// RelevantFilesRegex: "(?i)jenkinsfile[^/]*$",
// },
}
func SplitParentRepo(args []string) []*OwnerWithRepo {
ownersWithRepos := make([]*OwnerWithRepo, 0)
for _, arg := range args {
splits := strings.Split(arg, "/")
owner := splits[0]
var repo string
if len(splits) > 1 {
repo = splits[1]
}
ownersWithRepos = append(ownersWithRepos, &OwnerWithRepo{
Repo: repo,
Owner: owner,
})
}
return ownersWithRepos
}
func YamlToJson(byteContent []byte) ([]byte, error) {
strContent := string(byteContent)
modifiedStr := regexp.MustCompile(`[^$]{{.*}}`).ReplaceAllString(strContent, " DYNAMIC_VALUE")
return yaml.YAMLToJSON([]byte(modifiedStr))
}
func EscapeJsonKey(key string) string {
return strings.ReplaceAll(key, ".", "[ESCAPED_DOT]")
}