diff --git a/endpoints/web.py b/endpoints/web.py index 122b35095..f7acf49b4 100644 --- a/endpoints/web.py +++ b/endpoints/web.py @@ -212,22 +212,19 @@ def build_status_badge(namespace, repository): abort(404) # Lookup the tags for the repository. - - # Lookup the current/recent build. - status = 'none' + tags = model.list_repository_tags(namespace, repository) + is_empty = len(list(tags)) == 0 build = model.get_recent_repository_build(namespace, repository) - if build: - if build.phase == 'error': - status = 'failed' - elif build.phase == 'complete': - status = 'ready' - else: - status = 'building' - else: - tags = model.list_repository_tags(namespace, repository) - if list(tags): - status = 'ready' - response = make_response(STATUS_TAGS[status]) + if not is_empty and (not build or build.phase == 'complete'): + status_name = 'ready' + elif build and build.phase == 'error': + status_name = 'failed' + elif build: + status_name = 'building' + else: + status_name = 'none' + + response = make_response(STATUS_TAGS[status_name]) response.content_type = 'image/svg+xml' return response