mszostok / codeowners-validator

The GitHub CODEOWNERS file validator
Apache License 2.0
212 stars 48 forks source link

Validate GitHub token scopes when `owners` check is enabled #139

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Description

Currently, if you will pass GitHub token, it won't be validated. If it lacks necessary scopes, a misleading error can be returned. For example:

==> Executing Valid Owner Checker (184.722866ms)
    [err] line 8: User "@mszostok" is not a member of the organization
    [err] line 11: HTTP error occurred while calling GitHub: GET https://api.github.com/orgs/GitHubCODEOWNERS/teams?per_page=100: 403 Must have admin rights to Repository. []

but in real, the problem is that the token doesn't have the "read:org" scope.

To avoid such problems, we need to check if token has the "read:org" and "public_repo" scopes when owners check is enabled.