|
@ -203,10 +203,13 @@ def pause(request, code): |
|
|
|
|
|
|
|
|
@never_cache |
|
|
@never_cache |
|
|
@cors("GET") |
|
|
@cors("GET") |
|
|
def badge(request, badge_key, signature, tag, format="svg"): |
|
|
|
|
|
|
|
|
def badge(request, badge_key, signature, tag, fmt="svg"): |
|
|
if not check_signature(badge_key, tag, signature): |
|
|
if not check_signature(badge_key, tag, signature): |
|
|
return HttpResponseNotFound() |
|
|
return HttpResponseNotFound() |
|
|
|
|
|
|
|
|
|
|
|
if fmt not in ("svg", "json", "shields"): |
|
|
|
|
|
return HttpResponseNotFound() |
|
|
|
|
|
|
|
|
q = Check.objects.filter(project__badge_key=badge_key) |
|
|
q = Check.objects.filter(project__badge_key=badge_key) |
|
|
if tag != "*": |
|
|
if tag != "*": |
|
|
q = q.filter(tags__contains=tag) |
|
|
q = q.filter(tags__contains=tag) |
|
@ -225,7 +228,7 @@ def badge(request, badge_key, signature, tag, format="svg"): |
|
|
if check_status == "down": |
|
|
if check_status == "down": |
|
|
down += 1 |
|
|
down += 1 |
|
|
status = "down" |
|
|
status = "down" |
|
|
if format == "svg": |
|
|
|
|
|
|
|
|
if fmt == "svg": |
|
|
# For SVG badges, we can leave the loop as soon as we |
|
|
# For SVG badges, we can leave the loop as soon as we |
|
|
# find the first "down" |
|
|
# find the first "down" |
|
|
break |
|
|
break |
|
@ -234,7 +237,16 @@ def badge(request, badge_key, signature, tag, format="svg"): |
|
|
if status == "up": |
|
|
if status == "up": |
|
|
status = "late" |
|
|
status = "late" |
|
|
|
|
|
|
|
|
if format == "json": |
|
|
|
|
|
|
|
|
if fmt == "shields": |
|
|
|
|
|
color = "success" |
|
|
|
|
|
if status == "down": |
|
|
|
|
|
color = "critical" |
|
|
|
|
|
elif status == "late": |
|
|
|
|
|
color = "important" |
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse({"label": label, "message": status, "color": color}) |
|
|
|
|
|
|
|
|
|
|
|
if fmt == "json": |
|
|
return JsonResponse( |
|
|
return JsonResponse( |
|
|
{"status": status, "total": total, "grace": grace, "down": down} |
|
|
{"status": status, "total": total, "grace": grace, "down": down} |
|
|
) |
|
|
) |
|
|