MCPcopy Create free account
hub / github.com/github/gh-aw / validateBranchPrefix

Function validateBranchPrefix

pkg/workflow/repo_memory_validation.go:30–58  ·  view source on GitHub ↗

validateBranchPrefix validates that the branch prefix meets requirements

(prefix string)

Source from the content-addressed store, hash-verified

28
29// validateBranchPrefix validates that the branch prefix meets requirements
30func validateBranchPrefix(prefix string) error {
31 if prefix == "" {
32 return nil // Empty means use default
33 }
34
35 repoMemValidationLog.Printf("Validating branch prefix: %q", prefix)
36
37 // Check length (4-32 characters)
38 if len(prefix) < 4 {
39 return fmt.Errorf("branch-prefix must be at least 4 characters long, got %d", len(prefix))
40 }
41 if len(prefix) > 32 {
42 return fmt.Errorf("branch-prefix must be at most 32 characters long, got %d", len(prefix))
43 }
44
45 // Check for alphanumeric and branch-friendly characters (alphanumeric, hyphens, underscores)
46 // Use pre-compiled regex from package level for performance
47 if !branchPrefixValidPattern.MatchString(prefix) {
48 return fmt.Errorf("branch-prefix must contain only alphanumeric characters, hyphens, and underscores, got '%s'", prefix)
49 }
50
51 // Cannot be "copilot"
52 if strings.EqualFold(prefix, "copilot") {
53 return errors.New("branch-prefix cannot be 'copilot' (reserved)")
54 }
55
56 repoMemValidationLog.Printf("Branch prefix %q passed validation", prefix)
57 return nil
58}
59
60// validateNoDuplicateMemoryIDs checks for duplicate memory IDs and returns an error if found.
61// Uses the generic validateNoDuplicateIDs helper for consistent duplicate detection.

Callers 2

Calls 2

PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1