(scope: string)
| 114 | } |
| 115 | |
| 116 | export async function expectTokenScope(scope: string): Promise<void> { |
| 117 | const token = await expectToken(); |
| 118 | const api = pageDetect.isEnterprise() |
| 119 | ? `${location.origin}/api/v3/` |
| 120 | : 'https://api.github.com/'; |
| 121 | |
| 122 | const {scopes: tokenScopes} = await getTokenInfo(api, token); |
| 123 | if (!tokenScopes.includes(scope)) { |
| 124 | throw new Error( |
| 125 | 'The token you provided does not have ' + (tokenScopes.length > 0 |
| 126 | ? `the \`${scope}\` scope. It only includes \`${tokenScopes.join(', ')}\`.` |
| 127 | : 'any scope. You can change the scope of your token at https://github.com/settings/tokens'), |
| 128 | ); |
| 129 | } |
| 130 | } |
no test coverage detected