(headers: Headers)
| 73 | } |
| 74 | |
| 75 | function parseTokenScopes(headers: Headers): string[] { |
| 76 | // If `X-OAuth-Scopes` is not present, the token may be not a classic token. |
| 77 | const scopesHeader = headers.get('X-OAuth-Scopes'); |
| 78 | if (!scopesHeader) { |
| 79 | // If the request succeeded but lacked this header, it's likely a fine-grained token |
| 80 | // https://github.com/orgs/community/discussions/25259#discussioncomment-3247158 |
| 81 | return ['valid_token', 'unknown']; |
| 82 | } |
| 83 | |
| 84 | const scopes = scopesHeader.split(', '); |
| 85 | scopes.push('valid_token'); |
| 86 | if (scopes.includes('repo')) { |
| 87 | scopes.push('public_repo'); |
| 88 | } |
| 89 | |
| 90 | if (scopes.includes('project')) { |
| 91 | scopes.push('read:project'); |
| 92 | } |
| 93 | |
| 94 | return scopes; |
| 95 | } |
| 96 | |
| 97 | type TokenInfo = { |
| 98 | scopes: string[]; |
no test coverage detected