Allow null avatars from Gitlab

Not all gitlab repositories have defined owners, meaning we cannot always get an avatar_url for the namespace

Fixes https://sentry.io/coreos/backend-production/issues/241774339/
This commit is contained in:
Joseph Schorr 2017-04-04 13:41:38 -04:00
parent 1bfca871ec
commit eae151ff96
3 changed files with 7 additions and 6 deletions

View file

@ -21,7 +21,7 @@ NAMESPACES_SCHEMA = {
'description': 'Score of the relevance of the namespace',
},
'avatar_url': {
'type': 'string',
'type': ['string', 'null'],
'description': 'URL of the avatar for this namespace',
},
'url': {

View file

@ -281,11 +281,12 @@ class GitLabBuildTrigger(BuildTriggerHandler):
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'],
'title': namespace['name'],
'avatar_url': repo['owner']['avatar_url'],
'avatar_url': avatar_url,
'score': 1,
'url': gl_client.host + '/' + namespace['path'],
}

View file

@ -47,7 +47,7 @@
ng-value="namespace">
</td>
<td>
<img class="namespace-avatar" ng-src="{{ namespace.avatar_url }}">
<img class="namespace-avatar" ng-src="{{ namespace.avatar_url }}" ng-if="namespace.avatar_url">
<span class="anchor"
href="{{ namespace.url }}"
is-text-only="!namespace.url">{{ namespace.id }}</span>
@ -89,7 +89,7 @@
<h3>Select Repository</h3>
<strong>
Select a repository in
<img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}">
<img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}" ng-if="$ctrl.local.selectedNamespace.avatar_url">
{{ $ctrl.local.selectedNamespace.id }}
</strong>
@ -187,7 +187,7 @@
<h3>Configure Trigger</h3>
<strong>
Configure trigger options for
<img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}">
<img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}" ng-if="$ctrl.local.selectedNamespace.avatar_url">
{{ $ctrl.local.selectedNamespace.id }}/{{ $ctrl.local.selectedRepository.name }}
</strong>
@ -317,7 +317,7 @@
ng-if="$ctrl.local.triggerAnalysis.status == 'error'">
<h3 class="error"><i class="fa fa-exclamation-circle"></i> Verification Error</h3>
<strong>
There was an error when verifying the state of <img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}">
There was an error when verifying the state of <img class="namespace-avatar" ng-src="{{ $ctrl.local.selectedNamespace.avatar_url }}" ng-if="$ctrl.local.selectedNamespace.avatar_url">
{{ $ctrl.local.selectedNamespace.id }}/{{ $ctrl.local.selectedRepository.name }}
</strong>