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

[server] For GitLab projects without an owner avatar, fall back to the namespace avatar, or generate the default GitLab avatar #8824

Merged
merged 1 commit into from
Apr 4, 2022

Conversation

jankeromnes
Copy link
Contributor

@jankeromnes jankeromnes commented Mar 15, 2022

Description

For GitLab projects belonging to a group, it seems that there is no owner.avatar_url to be found here:

const accountAvatarUrl = anyProject.owner?.avatar_url as string;

Example group project from GitLab's API:

{
  "id": 23116976,
  "description": "",
  "name": "sample-project",
  "name_with_namespace": "reproduction-group / sample-project",
  /* ... (no "owner") ... */
  "namespace": {
    "id": 10408914,
    "name": "reproduction-group",
    /* ... */
    "avatar_url": "/uploads/-/system/group/avatar/10408914/gitpod-ua.png",
    "web_url": "https://gitlab.com/groups/reproduction-group"
  },
  /* ... */
}

As you can see, there is no "owner", but there is an avatar URL on the "namespace" (although it's relative).

When there is no owner avatar URL, this Pull Request falls back to the namespace avatar URL if available.

EDIT: When no avatar is available, it generates a SVG avatar that looks like GitLab's own default group avatar.

Related Issue(s)

Fixes #5330

How to test

  1. Connect with GitLab
  2. Be part of a group which has an avatar (e.g. https://gitlab.com/reproduction-group)
  3. Go to /new -- the GitLab group should have the set avatar visible

Release Notes

[server] For GitLab projects without an owner avatar, fall back to the namespace avatar, or generate the default GitLab avatar

Documentation

@jankeromnes jankeromnes requested a review from a team March 15, 2022 12:51
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Mar 15, 2022
@jankeromnes
Copy link
Contributor Author

Note: When there is no avatar, it would be nice to use the same default avatar as GitLab (i.e. a big letter with a pastel background). However, I couldn't find how to generate this, so for now I left the avatar URL empty when there is no avatar.

@jankeromnes jankeromnes requested a review from gtsiolis March 15, 2022 13:03
@gtsiolis
Copy link
Contributor

gtsiolis commented Mar 15, 2022

Looking at this now! 👀

Copy link
Contributor

@gtsiolis gtsiolis left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up, @jankeromnes!

Commented below about two outstanding issues related to UX here.

components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
return anyProject.owner.avatar_url;
}
if (anyProject.namespace?.avatar_url) {
let url = anyProject.namespace.avatar_url;
Copy link
Contributor

@gtsiolis gtsiolis Mar 15, 2022

Choose a reason for hiding this comment

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

issue: Not sure if this is the correct line to comment this but the avatar seems broken now while before it was just a white blank space, see screenshots below. But maybe this is an improvement step towards resolving this issue?

fyi: The one before the last one below is the gitlab-org group which has an avatar.

BEFORE AFTER
list-before list-after

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for catching this @gtsiolis. If you inspect the broken icons, what does the avatar URL look like?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jankeromnes for all of the ones with a missing avatar, including the gitlab-org group which has an avatar, I see the following in dev tools:

Screenshot 2022-03-15 at 5 41 06 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Thanks for fixing this, work like a charm. ✨

Copy link
Contributor

Choose a reason for hiding this comment

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

The groups with custom avatars still seems broken. What do you think of opening a follow up issue for this to keep track of this?

Frame 370

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder what's special about these groups 🤔 needs more debugging (e.g. maybe you can invite me to one of these, or I can create another Pull Request with more debug logs and ask you to reproduce in there).

Filed follow-up issue: #9112

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to be working ok now for all but one of the groups in there, posted a comment in #9112 (comment).

@jankeromnes
Copy link
Contributor Author

Taking this back to draft as there is some work left to do.

@stale
Copy link

stale bot commented Mar 26, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label Mar 26, 2022
@gtsiolis gtsiolis removed the meta: stale This issue/PR is stale and will be closed soon label Mar 28, 2022
@jankeromnes jankeromnes force-pushed the jx/fix-gitlab-group-avatars branch from 2e92b16 to 84c3c59 Compare March 28, 2022 14:03
@roboquat roboquat added size/M and removed size/S labels Mar 28, 2022
@jankeromnes jankeromnes force-pushed the jx/fix-gitlab-group-avatars branch from 84c3c59 to 7e5c93e Compare March 28, 2022 17:07
@jankeromnes jankeromnes changed the title [server] For GitLab projects without an owner avatar, fall back to the namespace avatar [server] For GitLab projects without an owner avatar, fall back to the namespace avatar, or generate the default GitLab avatar Mar 28, 2022
@jankeromnes jankeromnes force-pushed the jx/fix-gitlab-group-avatars branch 2 times, most recently from 4eb07ee to 25f5c1c Compare March 28, 2022 17:42
@jankeromnes jankeromnes marked this pull request as ready for review March 28, 2022 17:43
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Mar 28, 2022

Ready for another round of reviews! 🚀

I've implemented a default avatar generator similar to GitLab's one (thanks @gtsiolis for linking the relevant code! 🎯) so there should always be an avatar now.

I've also implemented more specific types (instead of using any), based on the official types from our library (gitbeaker) with the additional missing fields.

@jankeromnes jankeromnes requested review from gtsiolis and a team March 28, 2022 17:45
@gtsiolis
Copy link
Contributor

gtsiolis commented Mar 28, 2022

Taking another look now! 👀

Copy link
Contributor

@gtsiolis gtsiolis left a comment

Choose a reason for hiding this comment

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

Took another look and left some more comments below. Thanks, @jankeromnes! 🏀

components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
// - https://gitlab.com/gitlab-org/gitlab-foss/-/blob/84b4743475246e91dc78c3f25f9b335c40be84cd/app/assets/stylesheets/startup/startup-general.scss#L420-422
const text = owner.name[0].toUpperCase();
const backgroundColor = ["#fcf1ef", "#f4f0ff", "#f1f1ff", "#e9f3fc", "#ecf4ee", "#fdf1dd", "#f0f0f0"][
owner.id % 7
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: It so much fun to see the same logic here. Good memories! 🦊

components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
@jankeromnes jankeromnes force-pushed the jx/fix-gitlab-group-avatars branch from 25f5c1c to ab4af90 Compare March 30, 2022 14:42
@jankeromnes jankeromnes requested a review from gtsiolis March 30, 2022 14:58
@jankeromnes
Copy link
Contributor Author

Briefly taking this back to Draft for some quick debugging.

@jankeromnes jankeromnes marked this pull request as draft March 31, 2022 06:30
@jankeromnes jankeromnes force-pushed the jx/fix-gitlab-group-avatars branch 2 times, most recently from 17db447 to 55d9ce7 Compare March 31, 2022 09:54
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Mar 31, 2022

Phew. Okay now this should be ready to rock'n'roll. 🎸😁

@gtsiolis please take another look when you have some time. 🙏

(For what it's worth, I initially estimated this work as a 0.25 day effort / 1 iteration -- looks like I was about 10x off on both. 😅)

@jankeromnes jankeromnes marked this pull request as ready for review March 31, 2022 12:14
easyCZ
easyCZ previously approved these changes Apr 4, 2022
Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

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

Code-wise looks good to me. Adding hold to resolve remaining questions.

/hold

components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
@@ -237,7 +237,11 @@ export default function NewProject() {

const accounts = new Map<string, { avatarUrl: string }>();
reposInAccounts.forEach((r) => {
if (!accounts.has(r.account)) accounts.set(r.account, { avatarUrl: r.accountAvatarUrl });
if (!accounts.has(r.account)) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 Much nicer on the eyes

@gtsiolis
Copy link
Contributor

gtsiolis commented Apr 4, 2022

Taking another look at this now! 👀

gtsiolis
gtsiolis previously approved these changes Apr 4, 2022
Copy link
Contributor

@gtsiolis gtsiolis left a comment

Choose a reason for hiding this comment

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

LGTM, @jankeromnes! 🔮

const backgroundColor = ["#fcf1ef", "#f4f0ff", "#f1f1ff", "#e9f3fc", "#ecf4ee", "#fdf1dd", "#f0f0f0"][
owner.id % 7
];
// Uppercase first character of the name, support emojis, default to whitespace.
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Lovely comment! 💯

components/server/ee/src/gitlab/gitlab-app-support.ts Outdated Show resolved Hide resolved
…e top-level group avatar, or generate the default GitLab avatar
@jankeromnes
Copy link
Contributor Author

jankeromnes commented Apr 4, 2022

Nits addressed & follow-ups filed! 🎉

@easyCZ or @gtsiolis could you please re-approve?

/unhold

Copy link
Contributor

@gtsiolis gtsiolis left a comment

Choose a reason for hiding this comment

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

Works like a charm, @jankeromnes! 🔮

Thanks for also opening the follow up issue in #8824 (comment) to track one potentially minor edge case. 💯

Approving for UX, but you'll still need an approval from someone from the WebApp team.

Waiting on code owner review from gitpod-io/engineering-webapp.

@jankeromnes jankeromnes requested review from easyCZ and a team April 4, 2022 17:04
@roboquat roboquat merged commit 1d52870 into main Apr 4, 2022
@roboquat roboquat deleted the jx/fix-gitlab-group-avatars branch April 4, 2022 17:24
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/M team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Group avatars fail to load for GitLab groups
5 participants