zed icon indicating copy to clipboard operation
zed copied to clipboard

GitHub avatars: support enterprise avatars with GITHUB_TOKEN, handle failure better

Open vuon9 opened this issue 1 year ago • 6 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Zed made multiple unsuccessful attempts to retrieve the avatar from my private GH enterprise account. I believe it would be better if the retry attempts were limited, and having a default avatar type, such as using the first characters of the first and last names as a fallback, would be ideal.

Zed log:

image

My avatar is blank: image

Environment

Zed: v0.156.1 (Zed) OS: macOS 14.6.0 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

image

If applicable, attach your Zed.log file to this issue.

Zed.log

vuon9 avatar Oct 15 '24 04:10 vuon9

Yeah, I ran into this previously and just dug up the slack conversation. It appears that when a user is inside a GitHub hosted Enterprise (not surely exactly which plans/settings trigger this) the GitHub API behaves very differently for these users.

For example to fetch my avatar, we would hit: https://api.github.com/users/notpeter which returns a nice json object including an avatar_url of https://avatars.githubusercontent.com/u/145113?v=4.

Where as for a random gh hosted enterprise user it just straight 404s. Similarly, if you hit the profile link it redirects you to an enterprise login. Wild.

We absolutely should handle this better:

  1. stop retrying so much
  2. have a fallback icon
  3. (potentially) use GITHUB_TOKEN to make it work

Do you use the gh cli and potentially have a token which could be made available via export GITHUB_TOKEN="$(gh auth token)"?

notpeter avatar Oct 16 '24 14:10 notpeter

export GITHUB_TOKEN="$(gh auth token)"

Indeed, I do have it. I successfully tested the calling profile API on terminal, using that GH token and receive the same response data structure like public GH account could have.

vuon9 avatar Oct 17 '24 05:10 vuon9

A user reported a similar issue (repeated failed attempts to load an avatar) for a deleted/renamed github user here:

  • https://github.com/zed-industries/zed/issues/19460

We should fail gracefully in that situation as well.

notpeter avatar Oct 21 '24 15:10 notpeter

Two things to do here:

  1. Take GITHUB_TOKEN into account for GHE
  2. If image fails to load, show placeholder avatar and do not try to re-render (or at least backoff and try to slowly reload)

mrnugget avatar Nov 04 '24 16:11 mrnugget

I am no longer able to reproduce the spamming GitHub issue. It has likely been fixed with the image cache: https://github.com/zed-industries/zed/pull/27774

I hardcoded all avatars to load a specific url I knew would fail, and it is only logging once (I am only seeing one when it fails the first time)

I will keep digging into how we can actually support enterprise images though.

benbrandt avatar Jun 03 '25 15:06 benbrandt

@benbrandt I believe the solution would likely be to use a GITHUB_TOKEN for requests:

  • https://github.com/zed-industries/zed/issues/9483

notpeter avatar Jun 03 '25 18:06 notpeter

#32164 would allow for using a GitHub token if provided, however this has a few potential concerns:

  1. The user can only do this if they set an env variable and launch Zed from the CLI
  2. If the token is expired, we may cause more issues throughout the app, which that PR doesn't handle currently

We could do some form of oauth/refresh token route for the user, but this would be a larger change.

It seems like, no matter what having fallback avatars would be a better experience in the app, because there are other reasons we might fail to load the image.

We will circle back with @iamnbutler and @danilo-leal on their previous work here and see if we can manage to get some form of avatar fallbacks in the app.

benbrandt avatar Jun 05 '25 19:06 benbrandt

I discovered if you have the github user id (not just the username) you can directly retrieve the avatar image by-id which (1) saves a 302 http redirect (2) works for github enterprise users.

# curl -I 'https://github.com/notpeter.png?size=128' |grep location
location: https://avatars.githubusercontent.com/u/145113?s=128&v=4

notpeter avatar Jun 27 '25 12:06 notpeter

hi @notpeter, the link actually only works if I request within the browser that I have a live session of that GitHub account, it's failed in another browser profile OR just 404 in Zed.

Here is the log I have in Zed.

2025-11-03T11:02:44+07:00 ERROR [gpui::asset_cache] Failed to load asset: unexpected http status for https://github.com/your_enterprise_gh_username.png?size=128: 404 Not Found, body: Not Found

vuon9 avatar Nov 03 '25 04:11 vuon9