1package utils
 2
 3import (
 4	"fmt"
 5	"path/filepath"
 6	"strings"
 7	"unicode"
 8)
 9
10// SanitizeRepo returns a sanitized version of the given repository name.
11func SanitizeRepo(repo string) string {
12	repo = strings.TrimPrefix(repo, "/")
13	repo = filepath.Clean(repo)
14	repo = strings.TrimSuffix(repo, ".git")
15	return repo
16}
17
18// ValidateUsername returns an error if any of the given usernames are invalid.
19func ValidateUsername(username string) error {
20	if username == "" {
21		return fmt.Errorf("username cannot be empty")
22	}
23
24	if !unicode.IsLetter(rune(username[0])) {
25		return fmt.Errorf("username must start with a letter")
26	}
27
28	for _, r := range username {
29		if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '-' {
30			return fmt.Errorf("username can only contain letters, numbers, and hyphens")
31		}
32	}
33
34	return nil
35}