feat(*): support repositories

Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
storyicon 2021-07-23 14:56:00 +08:00
parent 1c73b92f0f
commit 9a99c53c5b
No known key found for this signature in database
GPG key ID: 245915D985F966CF
18 changed files with 542 additions and 255 deletions

View file

@ -24,6 +24,19 @@ import (
"syscall"
)
// DeduplicateSlice is used to deduplicate slice items stably
func DeduplicateSliceStably(items []string) []string {
data := make([]string, 0, len(items))
deduplicate := map[string]struct{}{}
for _, val := range items {
if _, exists := deduplicate[val]; !exists {
deduplicate[val] = struct{}{}
data = append(data, val)
}
}
return data
}
// ContainsEmpty is used to check whether items contains empty string
func ContainsEmpty(items ...string) bool {
return Contains(items, "")
@ -75,10 +88,17 @@ func GetExitCode(err error) int {
var regexpEnvironmentVar = regexp.MustCompile(`\$[A-Za-z_]+`)
// RenderPathWithEnv is used to render path with environment
func RenderPathWithEnv(path string) string {
func RenderPathWithEnv(path string, ext map[string]string) string {
matches := regexpEnvironmentVar.FindAllString(path, -1)
for _, match := range matches {
path = strings.ReplaceAll(path, match, os.Getenv(match[1:]))
key := match[1:]
val := ext[key]
if val == "" {
val = os.Getenv(key)
}
if val != "" {
path = strings.ReplaceAll(path, match, val)
}
}
return filepath.Clean(path)
}