Skip to content

Support GitHub Enterprise avatars via Enterprise REST service and optionally Gravatar #4497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

kabel
Copy link
Contributor

@kabel kabel commented Feb 3, 2023

In GitHub Enterprise, the avatarUrl endpoints that the APIs return require authentication in standard configuration. There is currently no way to do token authentication to these endpoints, so a fallback is necessary to render an image.

The interface was previously coded to handle fallback to the Gravatar service (just like GitHub Desktop did), but this behavior was disabled in 13ab0a7 and 6769dd4 because of end-user preference for making this feature configurable.

Recently an enterprise-only REST API was discovered that allows us to proxy the avatar image. This allows us to fetch the binary and encode it as a data URI to inject into the various views that otherwise render the avatar with standard http requests. If this API fails for some reason, Gravatar remains an optional fallback choice.

A new setting githubPullRequests.defaultGravatarsStyle has been added of type enum with values for each of the Gravatar supported fallback styles. Setting this value to none (the default) disables Gravatar integration.

These settings provide a richer user experience for GitHub Enterprise pull requests, allowing users to opt-in/out on avatar rendering via a third-party service with multiple options for the default fallback image style.

For consistency in multiple interface areas where <Avatar> is rendered, the GraphQL queries (and matching typescript interfaces) have been updated to include the necessary email property for integration with Gravatar.

REST provided actors are missing email. If missing email and using GitHub Enterprise and it's needed by Gravatar, make another REST API call to the user endpoint to get email. This allows a fallback avatar to be generated.

This fixes GitHub Enterprise avatars not being rendered in the tree views too.

The utility functions have been adjusted to support doing the fallback image URL generation directly after the raw results have been loaded from the normal REST and GraphQL APIs. This should be a cleaner implementation.

@kabel
Copy link
Contributor Author

kabel commented Feb 3, 2023

This is a long overdue PR requested by @alexr00

@alexr00 alexr00 added this to the February 2023 milestone Feb 3, 2023
@alexr00 alexr00 self-assigned this Feb 3, 2023
@kabel
Copy link
Contributor Author

kabel commented Feb 3, 2023

Example Overview render with default settings:
image

Now with real GitHub Enterprise Avatars (in tree view):
image

Including avatars for GitHub Enterprise app/integrations:
image

@kabel
Copy link
Contributor Author

kabel commented Feb 3, 2023

Looks like I'm referencing outdated information. GitHub Desktop now appears to be using an undocumented GitHub Enterprise REST API endpoint at /api/v3/enterprise/avatars/u/e?email=

image

Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I've pushed a commit with a few small changes (nothing functional, just to make it easier for me to review).

I'm seeing a discrepancy with which avatars are shown in the description page with this change:
image

I've also left a few comments with some questions/concerns I have.

@kabel
Copy link
Contributor Author

kabel commented Feb 8, 2023

Thanks for the review/questions.

Based on the availability of the Enterprise REST API (as now used in GitHub Desktop), I added a bit of scope creep to this request. In c0145681df76ef688929ab21181245974db7725e the fallback logic will first check the REST API for the avatar image binary. If the API returns the image binary, it is converted to a data URI to be rendered by the webviews and treeviews. I updated the CSP meta of the webviews to allow img-src data: to make that work. If that's too much for this PR, I can save that commit for a future request.

Other comments that don't require additional feedback should now be addressed.

@kabel kabel requested a review from alexr00 February 8, 2023 22:05
@alexr00
Copy link
Member

alexr00 commented Feb 10, 2023

I'm sorry @kabel but this PR has become too big for me to continue reviewing now and it mostly seems to be because of fetching the user email when parsing user results from the GitHub REST API. I started reviewing and left some comments, but scope of this change has just gotten to big for me to review at this time.

I will try to plan time to review in the next couple months, but ideally the PR would be much smaller.

Thank you again for this change. If I hear from users that gravatars are important I will definitely reference your changes to see how to enable them.

@alexr00 alexr00 modified the milestones: February 2023, March 2023 Feb 10, 2023
@alexr00 alexr00 mentioned this pull request Feb 10, 2023
@alexr00
Copy link
Member

alexr00 commented Feb 10, 2023

I've opened an issue to try to gauge how much desire there is for this feature: #4517

@kabel kabel changed the title Add configurable avatar fallback for GitHub Enterprise Support GitHub Enterprise avatars via Enterprise REST service and optionally Gravatar Feb 11, 2023
@kabel
Copy link
Contributor Author

kabel commented Feb 11, 2023

Sounds fair @alexr00. I've got the latest push down to a more manageable size (mostly added lines for the new Enterprise REST integration), but I'll wait for more time to become available. Having a better Enterprise experience continues to be important for me, but I can understand how avatars aren't going to be a huge win feature-wise for folks.

@kabel kabel force-pushed the redo-issue-2771 branch 2 times, most recently from d950471 to cec122d Compare February 20, 2023 00:03
@kabel kabel force-pushed the redo-issue-2771 branch from cec122d to b627a3a Compare March 21, 2023 15:38
@alexr00 alexr00 modified the milestones: March 2023, On Deck Mar 22, 2023
@kabel kabel force-pushed the redo-issue-2771 branch from b627a3a to a8a20e4 Compare April 26, 2023 21:44
kabel added 2 commits April 26, 2023 17:02
In GitHub Enterprise, the avatarUrl endpoints that the APIs return require authentication in standard configuration. There is currently no way to do token authentication to these endpoints, so a fallback is necessary to render an image.

The interface was previously coded to handle fallback to the Gravatar service (just like GitHub Desktop [did](desktop/desktop#3513)), but this behavior was disabled in 13ab0a7 and 6769dd4 because of end-user preference for making this feature configurable.

A new setting has been added

* `githubPullRequests.defaultGravatarsStyle` is an `enum` of the Gravatar supported fallback styles plus an internal value of `none` to disable the integration

These settings provide a richer user experience for GitHub Enterprise pull requests, allowing users to opt-in/out on avatar rendering via a third-party service with multiple options for the default fallback image style.

For consistency in multiple interface areas where `<Avatar>` is rendered, the graphQL queryies (and matching typescript interfaces) have been updated to include the necessary `email` property for integration with Gravatar.

REST provided actors are missing email. If missing email and using GitHub Enterprise, make another REST API call to the user endpoiint to get email. This allows a fallback avatar to be generated.

This fixes GitHub Enterprise avatars not being rendered in the tree views.
Uses the undocumented enterprise avatar REST service to construct a data uri for the webviews.

The REST service is protected from too many concurrent requests by the `p-queue` package that should be compatible with all runtimes.

Undoes some async APIs by making the enterprise decorations (avatarUrl replacement and/or email fetching) their own utility functions, run only when necessary.

Consolidates the test for Enterprise auth.
kabel added 2 commits April 26, 2023 17:02
Also implements HTTP caching client by saving the avatar REST headers and responses to the globalStorage.
@kabel kabel force-pushed the redo-issue-2771 branch from a8a20e4 to d311536 Compare April 26, 2023 22:04
@kabel kabel requested a review from alexr00 April 26, 2023 22:06
@kabel kabel closed this Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants