Skip to content
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 into
StaticJsCMS:mainfrom
gael-cms:gael-cms/support-app-tokens-for-github-backend
Draft

feat: Support Github App tokens for Github backend#1100
soceanainn wants to merge 1 commit into
StaticJsCMS:mainfrom
gael-cms:gael-cms/support-app-tokens-for-github-backend

Conversation

@soceanainn

@soceanainnsoceanainn commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

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.

@netlify

netlifyBot commented Apr 2, 2024

Copy link
Copy Markdown

Deploy Preview for demo-staticjscms ready!

NameLink
🔨 Latest commitbbd1f99
🔍 Latest deploy loghttps://app.netlify.com/sites/demo-staticjscms/deploys/660d268cfc2e7c0008510c9a
😎 Deploy Previewhttps://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.

@netlify

netlifyBot commented Apr 2, 2024

Copy link
Copy Markdown

Deploy Preview for staticjscms ready!

NameLink
🔨 Latest commitbbd1f99
🔍 Latest deploy loghttps://app.netlify.com/sites/staticjscms/deploys/660d268cc351d10008e0e2fc
😎 Deploy Previewhttps://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.

@soceanainnsoceanainn changed the title Support app tokens for Github backendfeat: Support app tokens for Github backendApr 2, 2024
@soceanainn
soceanainnforce-pushed the gael-cms/support-app-tokens-for-github-backend branch from 39a057e to 320ca89CompareApril 2, 2024 15:39
@codecov

codecovBot commented Apr 2, 2024

Copy link
Copy Markdown

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).

FilesPatch %Lines
...ckages/core/src/backends/github/implementation.tsx5.55%15 Missing and 2 partials ⚠️
packages/core/src/backends/github/API.ts37.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.

@soceanainnsoceanainn changed the title feat: Support app tokens for Github backendfeat: Support Github App tokens for Github backendApr 3, 2024
@soceanainn
soceanainn marked this pull request as draft April 3, 2024 09:28
@soceanainn
soceanainnforce-pushed the gael-cms/support-app-tokens-for-github-backend branch from 320ca89 to bbd1f99CompareApril 3, 2024 09:51
Sign up for freeto 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

@soceanainn