This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
feat: Support Github App tokens for Github backend #1100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change introduces support for Github App tokens. Supporting Github App tokens will allow for custom authentication through e.g. AWS Lambda.
There are essentially two differences when dealing with app tokens:
$.permissions.push
in response (hasWriteAccess
function), this value will never be true for app tokens (even those with appropriate permissions).For (1) we simply bypass the additional permissions check (validating that the repo can be fetched by the app token is probably enough for most cases).
For (2) we need to create a mock user object for use by StaticCMS (discussed below).
This change also aims to eliminate any redundant calls to fetch the user / repo from Github across the API and implementation code, by having at most one call each.
Creating a mock user for app token
Normally we fetch a
GithubUser
object using the Github API user endpoint and use that to represent the user (based on the token obtained through auth page).Github App tokens won't have a user defined for them so we cannot use the user endpoint.Luckily we only seem to use three fields from this object in code:
name
,login
andavatar_url
. We can workaround this issue by setting defaults for those three fields by fetching the app, and usingname
andslug
from response to setname
andlogin
respectively.avatar_url
can be built fromid
in response.