ClassifyPAT determines the type of a GitHub Personal Access Token based on its prefix. Token prefixes: - "github_pat_" = Fine-grained PAT (required for Copilot) - "ghp_" = Classic PAT (not supported for Copilot) - "gho_" = OAuth token (not a PAT at all) Parameters: - token: The token string to cla
(token string)
| 51 | // Returns: |
| 52 | // - PATType: The type of the token |
| 53 | func ClassifyPAT(token string) PATType { |
| 54 | var patType PATType |
| 55 | switch { |
| 56 | case strings.HasPrefix(token, "github_pat_"): |
| 57 | patType = PATTypeFineGrained |
| 58 | case strings.HasPrefix(token, "ghp_"): |
| 59 | patType = PATTypeClassic |
| 60 | case strings.HasPrefix(token, "gho_"): |
| 61 | patType = PATTypeOAuth |
| 62 | default: |
| 63 | patType = PATTypeUnknown |
| 64 | } |
| 65 | patLog.Printf("Classified PAT type: %s", patType) |
| 66 | return patType |
| 67 | } |
| 68 | |
| 69 | // ValidateCopilotPAT validates that a token is a valid fine-grained PAT for Copilot. |
| 70 | // Returns an error if the token is not a fine-grained PAT with a descriptive error message. |