Add GL_GROUP group avatars (auto-update)
Add GL_GROUP group avatars (auto-update). Every 7 days, we look if the avatar on GitLab has changed (we already do this for GitHub).
Part of https://gitlab.com/gitlab-org/gitter/webapp/issues/2393
Dev notes
My quick link (need to clear cache): http://localhost:5000/api/private/avatars/group/i/5df865d638da38f1fa1ecd9f
db.groups.insert({
"name" : "_test-gitlab-group-test-community",
"uri" : "_test-gitlab-group-test-community",
"lcUri" : "_test-gitlab-group-test-community",
"lcHomeUri" : "_test-gitlab-group-test-community/home",
"homeUri" : "_test-gitlab-group-test-community/home",
"sd" : {
"externalId" : "3281315",
"linkPath" : "gitter-integration-tests-group",
"public" : true,
"admins" : "GL_GROUP_MAINTAINER",
"members" : "PUBLIC",
"type" : "GL_GROUP"
},
});
db.groups.update({ "lcUri" : "_test-gitlab-group-test-community" }, {
$unset: {
"avatarUrl" : 1,
"avatarCheckedDate" :1,
"avatarVersion" : 1
}
});
GitHub Avatars
GitHub has a nice predictable constructable URL: https://avatars.githubusercontent.com/<username-or-group>?s=<size>
GitLab Avatars
Avatars from GitLab don't have a predictable URL.
If there is a custom upload, then the filename is whatever you uploaded:
- https://assets.gitlab-static.net/uploads/-/system/project/avatar/3601513/gitter_logo.png?width=15
- https://assets.gitlab-static.net/uploads/-/system/group/avatar/9970/logo-extra-whitespace.png?width=64
This MR isn't supporting user namespaces. But users use Gravatar unless you upload something,
- https://secure.gravatar.com/avatar/4d634a2b818e2265fa2924b5f4c2da71?s=180&d=identicon
- https://assets.gitlab-static.net/uploads/-/system/user/avatar/1577466/avatar.png?width=90
TODO
-
Since GitLab doesn't have a predictable avatar URL we can't construct the URL on the fly. We need to find a place to store the avatarURL
after we fetch it. We can usegroup.avatarUrl
but need to make sure not to overwrite someones separate custom upload- Currently, this is protected because we have a early return if a custom avatar(
group.avatarUrl
) is set
- Currently, this is protected because we have a early return if a custom avatar(
-
Write migration for groups with custom avata set(group.avatarUrl
) togroup.avatarCheckedDate = new Date(3000)
Testing strategy
- Insert a new GitLab Gitter group into Mongo
db.groups.insert({ "name" : "_test-gitlab-group-test-community", "uri" : "_test-gitlab-group-test-community", "lcUri" : "_test-gitlab-group-test-community", "lcHomeUri" : "_test-gitlab-group-test-community/home", "homeUri" : "_test-gitlab-group-test-community/home", "sd" : { "externalId" : "3281315", "linkPath" : "gitter-integration-tests-group", "public" : true, "admins" : "GL_GROUP_MAINTAINER", "members" : "PUBLIC", "type" : "GL_GROUP" }, });
- Get the group ID:
db.groups.findOne({ "lcUri" : "_test-gitlab-group-test-community" })
- Visit
http://localhost:5000/api/private/avatars/group/i/<groupId>
, it will go tohttps://avatars.githubusercontent.com/undefined?s=128
but now the avatar is updated - Empty cache and hard reload
- Visit
http://localhost:5000/api/private/avatars/group/i/<groupId>
again, it should go tohttps://assets.gitlab-static.net/uploads/-/system/group/avatar/3281315/test-avatar1.png?width=128?v=1
You can reset and test again by clearing out the avatar properties:
db.groups.update({ "lcUri" : "_test-gitlab-group-test-community" }, {
$unset: {
"avatarUrl" : 1,
"avatarCheckedDate" :1,
"avatarVersion" : 1
}
});
Edited by Eric Eastwood