This repository was archived by the owner on Sep 9, 2024. It is now read-only.
feat: Support Github App tokens for Github backend#1100
Draft
soceanainn wants to merge 1 commit intoStaticJsCMS:mainfrom
Draft
feat: Support Github App tokens for Github backend#1100soceanainn wants to merge 1 commit intoStaticJsCMS:mainfrom
soceanainn wants to merge 1 commit intoStaticJsCMS:mainfrom
Conversation
✅ Deploy Preview for demo-staticjscms ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for staticjscms ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
39a057e to
320ca89
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1100 +/- ##
==========================================
- Coverage 55.83% 55.79% -0.04%
==========================================
Files 259 259
Lines 12362 12378 +16
Branches 3110 3116 +6
==========================================
+ Hits 6902 6906 +4
- Misses 5048 5058 +10
- Partials 412 414 +2 ☔ View full report in Codecov by Sentry. |
320ca89 to
bbd1f99
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.pushin response (hasWriteAccessfunction), 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
GithubUserobject 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,loginandavatar_url. We can workaround this issue by setting defaults for those three fields by fetching the app, and usingnameandslugfrom response to setnameandloginrespectively.avatar_urlcan be built fromidin response.