Skip to content

GitHub import: return early if request to import does not have correct scope

We recently updated the default requested scopes for any GitHub imports done via OAuth: Update OAuth scopes for GitHub import (!138251 - merged)

But, if someone is using a Personal Access Token and they select "Import Collaborators" , that requires the read:org scope.

If a PAT is passed with the incorrect scope, we allow the import to proceed but collaborator imports will fail and the following error is raised:

Octokit::Forbidden GET https://api.github.com/user/orgs?per_page=100: 403 - You need at least read:org scope or user scope to list your organizations. // See: https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user

Example.

We should also ensure that we check for the repo token, now that it is a minimum requirement.

Instead of letting the import proceed, we should exit the import early if it is kicked off with a token that has the incorrect scope.

Edited by Carla Drago