internal/policy/topic.go
20 lines · 532 bytes
3 symbols in this file
1package policy
2
3import (
4 "fmt"
5 "regexp"
6)
7
8// MaxTopics caps topics per repository.
9const MaxTopics = 20
10
11var topicPat = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,34}$`)
12
13// ValidateTopic checks a repository topic: lowercase alphanumerics and
14// dashes, must start with an alphanumeric, max 35 chars.
15func ValidateTopic(topic string) error {
16 if !topicPat.MatchString(topic) {
17 return fmt.Errorf("invalid topic %q: lowercase letters, digits, and '-' only; must start with a letter or digit; max 35 chars", topic)
18 }
19 return nil
20}