Skip to content
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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

soceanainn
Copy link
Contributor

@soceanainn soceanainn commented Apr 2, 2024

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:

  1. When fetching the repo and checking $.permissions.push in response (hasWriteAccess function), this value will never be true for app tokens (even those with appropriate permissions).
  2. We can't fetch a user using the Github user endpoint for those tokens

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 and avatar_url. We can workaround this issue by setting defaults for those three fields by fetching the app, and using name and slug from response to set name and login respectively. avatar_url can be built from id in response.

Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for demo-staticjscms ready!

Name Link
🔨 Latest commit bbd1f99
🔍 Latest deploy log https://app.netlify.com/sites/demo-staticjscms/deploys/660d268cfc2e7c0008510c9a
😎 Deploy Preview https://deploy-preview-1100.demo.staticcms.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for staticjscms ready!

Name Link
🔨 Latest commit bbd1f99
🔍 Latest deploy log https://app.netlify.com/sites/staticjscms/deploys/660d268cc351d10008e0e2fc
😎 Deploy Preview https://deploy-preview-1100.staticcms.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@soceanainn soceanainn changed the title Support app tokens for Github backend feat: Support app tokens for Github backend Apr 2, 2024
@soceanainn soceanainn force-pushed the gael-cms/support-app-tokens-for-github-backend branch from 39a057e to 320ca89 Compare April 2, 2024 15:39
Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 15.38462% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 55.79%. Comparing base (734cecd) to head (bbd1f99).

Files Patch % Lines
...ckages/core/src/backends/github/implementation.tsx 5.55% 15 Missing and 2 partials ⚠️
packages/core/src/backends/github/API.ts 37.50% 4 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

@soceanainn soceanainn changed the title feat: Support app tokens for Github backend feat: Support Github App tokens for Github backend Apr 3, 2024
@soceanainn soceanainn marked this pull request as draft April 3, 2024 09:28
@soceanainn soceanainn force-pushed the gael-cms/support-app-tokens-for-github-backend branch from 320ca89 to bbd1f99 Compare April 3, 2024 09:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant