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)
| 75 | // Returns: |
| 76 | // - error: An error with a descriptive message if the token is not valid, nil otherwise |
| 77 | func 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 |
| 94 | func GetPATTypeDescription(token string) string { |