<s> from __future__ import absolute_import , division , unicode_literals <EOL> from changes . api . base import APIView , error <EOL> from changes . config import db <EOL> from changes . models . build import Build <EOL> from changes . models . job import Job <EOL> from changes . models . phabricatordiff import PhabricatorDiff <EOL> from changes . utils . phabricator_utils import PhabricatorClient <EOL> class DiffBuildsIndexAPIView ( APIView ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , diff_ident ) : <EOL> if not diff_ident . startswith ( '<STR_LIT:D>' ) or not diff_ident [ <NUM_LIT:1> : ] . isdigit ( ) : <EOL> return error ( '<STR_LIT>' ) <EOL> phabricator_info = { } <EOL> try : <EOL> request = PhabricatorClient ( ) <EOL> request . connect ( ) <EOL> phabricator_info = request . call ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : [ int ( diff_ident [ <NUM_LIT:1> : ] ) ] <EOL> } ) <EOL> if len ( phabricator_info ) == <NUM_LIT:0> : <EOL> return error ( '<STR_LIT>' % diff_ident , http_code = <NUM_LIT> ) <EOL> assert len ( phabricator_info ) == <NUM_LIT:1> <EOL> phabricator_info = phabricator_info [ <NUM_LIT:0> ] <EOL> phabricator_info [ "<STR_LIT>" ] = True <EOL> except Exception as e : <EOL> print e <EOL> phabricator_info = { <EOL> "<STR_LIT>" : False <EOL> } <EOL> pass <EOL> rows = list ( db . session . query ( <EOL> Build , PhabricatorDiff <EOL> ) . join ( <EOL> PhabricatorDiff , Build . source_id == PhabricatorDiff . source_id , <EOL> ) . filter ( <EOL> PhabricatorDiff . revision_id == diff_ident [ <NUM_LIT:1> : ] <EOL> ) ) <EOL> build_ids = set ( [ row . Build . id for row in rows ] ) <EOL> jobs = [ ] <EOL> if len ( build_ids ) > <NUM_LIT:0> : <EOL> jobs = self . serialize ( list ( Job . query . filter ( <EOL> Job . build_id . in_ ( build_ids ) <EOL> ) ) ) <EOL> serialized_builds = zip ( <EOL> self . serialize ( [ row . Build for row in rows ] ) , <EOL> [ row . PhabricatorDiff for row in rows ] <EOL> ) <EOL> build_info = { } <EOL> for build , phabricator_diff in serialized_builds : <EOL> single_diff_id = phabricator_diff . diff_id <EOL> if single_diff_id not in build_info : <EOL> build_info [ single_diff_id ] = { <EOL> '<STR_LIT:id>' : phabricator_diff . id , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : phabricator_diff . diff_id , <EOL> '<STR_LIT>' : phabricator_diff . revision_id , <EOL> '<STR_LIT:url>' : phabricator_diff . url , <EOL> '<STR_LIT>' : phabricator_diff . source_id , <EOL> '<STR_LIT>' : phabricator_diff . date_created <EOL> } <EOL> build [ '<STR_LIT>' ] = [ j for j in jobs if j [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] == build [ '<STR_LIT:id>' ] ] <EOL> build_info [ single_diff_id ] [ '<STR_LIT>' ] . append ( build ) <EOL> phabricator_info [ '<STR_LIT>' ] = build_info <EOL> return self . respond ( phabricator_info ) </s>
