-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.go
More file actions
38 lines (30 loc) · 839 Bytes
/
validate.go
File metadata and controls
38 lines (30 loc) · 839 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
35
36
37
38
package main
import (
"fmt"
"regexp"
"strings"
)
var colorRegex = regexp.MustCompile(`^#?[0-9a-fA-F]{6}$`)
// Validates and normalizes a hex color
func validateColor(color string) (string, error) {
if !colorRegex.MatchString(color) {
return "", fmt.Errorf("invalid color format: %s (expected hex like #d73a4a)", color)
}
// Normalize to 6 chars without #
color = strings.TrimPrefix(color, "#")
return color, nil
}
// Validates a label before creation
func validateLabel(label Label) error {
if strings.TrimSpace(label.Name) == "" {
return fmt.Errorf("label name cannot be empty")
}
if _, err := validateColor(label.Color); err != nil {
return err
}
// GitHub limits description to 100 chars
if len(label.Description) > 100 {
return fmt.Errorf("label description too long (max 100 chars)")
}
return nil
}