<s> from datetime import datetime <EOL> from sqlalchemy import Column , String , DateTime , ForeignKey , Text <EOL> from sqlalchemy . dialects . postgresql import ARRAY <EOL> from sqlalchemy . orm import relationship <EOL> from fnmatch import fnmatch <EOL> from changes . config import db <EOL> from changes . db . types . guid import GUID <EOL> class Revision ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> repository_id = Column ( GUID , ForeignKey ( '<STR_LIT>' ) , primary_key = True ) <EOL> sha = Column ( String ( <NUM_LIT> ) , primary_key = True ) <EOL> author_id = Column ( GUID , ForeignKey ( '<STR_LIT>' ) ) <EOL> committer_id = Column ( GUID , ForeignKey ( '<STR_LIT>' ) ) <EOL> message = Column ( Text ) <EOL> parents = Column ( ARRAY ( String ( <NUM_LIT> ) ) ) <EOL> branches = Column ( ARRAY ( String ( <NUM_LIT> ) ) ) <EOL> date_created = Column ( DateTime , default = datetime . utcnow ) <EOL> date_committed = Column ( DateTime , default = datetime . utcnow ) <EOL> date_created_signal = Column ( DateTime , nullable = True ) <EOL> repository = relationship ( '<STR_LIT>' ) <EOL> author = relationship ( '<STR_LIT>' , foreign_keys = [ author_id ] , innerjoin = False ) <EOL> committer = relationship ( '<STR_LIT>' , foreign_keys = [ committer_id ] , innerjoin = False ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( Revision , self ) . __init__ ( ** kwargs ) <EOL> if self . date_created is None : <EOL> self . date_created = datetime . utcnow ( ) <EOL> if self . date_committed is None : <EOL> self . date_committed = self . date_created <EOL> @ classmethod <EOL> def get_by_sha_prefix_query ( self , repository_id , sha_prefix ) : <EOL> """<STR_LIT>""" <EOL> return Revision . query . filter ( <EOL> Revision . repository_id == repository_id , <EOL> Revision . sha . like ( '<STR_LIT>' . format ( sha_prefix ) ) , <EOL> ) <EOL> @ property <EOL> def subject ( self ) : <EOL> return self . message . splitlines ( ) [ <NUM_LIT:0> ] <EOL> def should_build_branch ( self , allowed_branches ) : <EOL> if not self . branches and '<STR_LIT:*>' in allowed_branches : <EOL> return True <EOL> for branch in self . branches : <EOL> if any ( fnmatch ( branch , pattern ) for pattern in allowed_branches ) : <EOL> return True <EOL> return False </s>
