Merge pull request #2532 from coreos-inc/fix-gitlab-avatar-url

Fix avatar URLs for non-owner namespaces in Gitlab
This commit is contained in:
josephschorr 2017-04-11 15:03:31 -04:00 committed by GitHub
commit e47ac22012
2 changed files with 18 additions and 6 deletions

View file

@ -277,11 +277,17 @@ class GitLabBuildTrigger(BuildTriggerHandler):
for repo in repositories:
namespace = repo['namespace']
namespace_id = namespace['id']
avatar_url = ''
if 'avatar' in namespace:
avatar_url = namespace.get('avatar', {}).get('url')
elif 'owner' in repo:
avatar_url = repo.get('owner', {}).get('avatar_url')
if namespace_id in namespaces:
namespaces[namespace_id]['score'] = namespaces[namespace_id]['score'] + 1
else:
owner = repo['namespace']['name']
avatar_url = repo.get('owner', {}).get('avatar_url')
namespaces[namespace_id] = {
'personal': owner == current_user['username'],
'id': namespace['path'],

View file

@ -26,8 +26,8 @@ def get_currentuser_mock():
'username': 'knownuser'
}
def project(namespace, name):
return {
def project(namespace, name, is_org=False):
data = {
'id': '%s/%s' % (namespace, name),
'default_branch': 'master',
'namespace': {
@ -52,11 +52,17 @@ def project(namespace, name):
}
}
if is_org:
del data['owner']['avatar_url']
data['namespace']['avatar'] = {'url': 'avatarurl'}
return data
def getprojects_mock(page=1, per_page=100):
return [
project('knownuser', 'somerepo'),
project('someorg', 'somerepo'),
project('someorg', 'anotherrepo'),
project('someorg', 'somerepo', is_org=True),
project('someorg', 'anotherrepo', is_org=True),
]
def getproject_mock(project_name):
@ -64,7 +70,7 @@ def getproject_mock(project_name):
return project('knownuser', 'somerepo')
if project_name == 'foo/bar':
return project('foo', 'bar')
return project('foo', 'bar', is_org=True)
return False