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

Function ValidateCopilotPAT

pkg/stringutil/pat_validation.go:77–91  ·  view source on GitHub ↗

ValidateCopilotPAT validates that a token is a valid fine-grained PAT for Copilot. Returns an error if the token is not a fine-grained PAT with a descriptive error message. Parameters: - token: The token string to validate Returns: - error: An error with a descriptive message if the token is not v

(token string)

Source from the content-addressed store, hash-verified

75// Returns:
76// - error: An error with a descriptive message if the token is not valid, nil otherwise
77func ValidateCopilotPAT(token string) error {
78 patType := ClassifyPAT(token)
79 patLog.Printf("Validating Copilot PAT: type=%s", patType)
80
81 switch patType {
82 case PATTypeFineGrained:
83 return nil
84 case PATTypeClassic:
85 return errors.New("classic personal access tokens (ghp_...) are not supported for Copilot. Please create a fine-grained PAT at https://github.com/settings/personal-access-tokens/new")
86 case PATTypeOAuth:
87 return errors.New("OAuth tokens (gho_...) are not supported for Copilot. Please create a fine-grained PAT at https://github.com/settings/personal-access-tokens/new")
88 default:
89 return errors.New("unrecognized token format. Please create a fine-grained PAT (starting with 'github_pat_') at https://github.com/settings/personal-access-tokens/new")
90 }
91}
92
93// GetPATTypeDescription returns a human-readable description of the PAT type
94func GetPATTypeDescription(token string) string {

Callers 4

ensureSecretAvailableFunction · 0.92
TestValidateCopilotPATFunction · 0.85

Calls 2

ClassifyPATFunction · 0.85
PrintfMethod · 0.45

Tested by 2

TestValidateCopilotPATFunction · 0.68