1package utils23import (4 "fmt"5 "path"6 "strings"7 "unicode"8)910// SanitizeRepo returns a sanitized version of the given repository name.11func SanitizeRepo(repo string) string {12 // We need to use an absolute path for the path to be cleaned correctly.13 repo = strings.TrimPrefix(repo, "/")14 repo = "/" + repo1516 // We're using path instead of filepath here because this is not OS dependent17 // looking at you Windows18 repo = path.Clean(repo)19 repo = strings.TrimSuffix(repo, ".git")20 return repo[1:]21}2223// ValidateUsername returns an error if any of the given usernames are invalid.24func ValidateUsername(username string) error {25 if username == "" {26 return fmt.Errorf("username cannot be empty")27 }2829 if !unicode.IsLetter(rune(username[0])) {30 return fmt.Errorf("username must start with a letter")31 }3233 for _, r := range username {34 if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '-' {35 return fmt.Errorf("username can only contain letters, numbers, and hyphens")36 }37 }3839 return nil40}4142// ValidateRepo returns an error if the given repository name is invalid.43func ValidateRepo(repo string) error {44 if repo == "" {45 return fmt.Errorf("repo cannot be empty")46 }4748 for _, r := range repo {49 if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '-' && r != '_' && r != '.' && r != '/' {50 return fmt.Errorf("repo can only contain letters, numbers, hyphens, underscores, periods, and slashes")51 }52 }5354 return nil55}