问题
We use Octokit to automate some workflows at work, but most of the time the issues we have is that the users haven't set-up their personal access token correctly, with the right scopes.
We would like to have a check before the app runs, to check if the token given has the right scope and give the engineer a meaningful error message right in the beginning, instead of failing later in the process.
回答1:
Yes, the scopes for a personal access token is listed in the response header, you can access it like this
const { headers } = await octokit.request('HEAD /')
const scopes = headers['x-oauth-scopes'].split(', ')
See: Understanding scopes for OAuth Apps
来源:https://stackoverflow.com/questions/56006959/is-there-a-way-to-list-a-personal-access-tokens-scopes-using-octokit-rest-js