#NEWLINE# def get_collection_context( builds ) : #NEWLINE# #INDENT# '\n    Given a non-empty list of finished builds, returns a context for\n    rendering the build results.\n    ' #NEWLINE# def sort_builds( builds_context ) : #NEWLINE# #INDENT# result_priority_order = ( Result . passed , Result . skipped , Result . unknown , Result . aborted , Result . infra_failed , Result . failed ) #NEWLINE# return sorted ( builds_context , key = ( lambda build : ( result_priority_order . index ( build [ 'build' ] . result ) , build [ 'failing_tests_count' ] , build [ 'failing_logs_count' ] ) ) , reverse = True ) #NEWLINE# #UNINDENT# builds_context = sort_builds ( map ( _get_build_context , builds ) ) #NEWLINE# if all ( map ( ( lambda build : build [ 'is_passing' ] ) , builds_context ) ) : #NEWLINE# #INDENT# result = Result . passed #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if any ( imap ( ( lambda build : build [ 'is_failing' ] ) , builds_context ) ) : #NEWLINE# #INDENT# result = Result . failed #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = Result . unknown #NEWLINE# #UNINDENT# #UNINDENT# build = builds [ 0 ] #NEWLINE# ( target , target_uri ) = _get_build_target ( build ) #NEWLINE# date_created = min ( [ _build . date_created for _build in builds ] ) #NEWLINE# return { #NEWLINE# #INDENT# 'title' : _get_title ( target , build . label , result ) , #NEWLINE# 'builds' : builds_context , #NEWLINE# 'result' : result , #NEWLINE# 'target_uri' : target_uri , #NEWLINE# 'target' : target , #NEWLINE# 'label' : build . label , #NEWLINE# 'date_created' : date_created , #NEWLINE# 'author' : build . author , #NEWLINE# 'commit_message' : ( build . message or '' ) , #NEWLINE# 'failing_tests_count' : _aggregate_count ( builds_context , 'failing_tests_count' ) , #NEWLINE# #UNINDENT# }