<s> from config import SHOW_AVATARS <EOL> class Payload ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . data = data <EOL> def user_link ( self ) : <EOL> name = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> avatar = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] + "<STR_LIT>" <EOL> return self . create_user_link ( name , url , avatar ) <EOL> def create_user_link ( self , name , url , avatar ) : <EOL> if SHOW_AVATARS : <EOL> return "<STR_LIT>" % ( avatar , name , url ) <EOL> return "<STR_LIT>" % ( name , url ) <EOL> def repo_link ( self ) : <EOL> name = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return "<STR_LIT>" % ( name , url ) <EOL> def preview ( self , text ) : <EOL> if not text : <EOL> return text <EOL> l = text . split ( "<STR_LIT:\n>" ) <EOL> result = l [ <NUM_LIT:0> ] <EOL> if result [ - <NUM_LIT:1> ] in "<STR_LIT>" : <EOL> result = result [ : - <NUM_LIT:1> ] <EOL> if result != text : <EOL> result += "<STR_LIT>" <EOL> return result <EOL> class PullRequest ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . number = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . title = self . data [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> self . body = self . data [ '<STR_LIT>' ] [ '<STR_LIT:body>' ] <EOL> self . url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> def opened ( self ) : <EOL> body = self . preview ( self . body ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . number , self . title , <EOL> self . url , self . repo_link ( ) , body ) <EOL> return msg <EOL> def assigned ( self ) : <EOL> to_name = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> to_url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> to_avatar = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] + "<STR_LIT>" <EOL> to = self . create_user_link ( to_name , to_url , to_avatar ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , <EOL> to , self . number , self . title , self . url ) <EOL> return msg <EOL> def closed ( self ) : <EOL> merged = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> action = "<STR_LIT>" if merged else "<STR_LIT>" <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , <EOL> action , self . number , self . title , self . url ) <EOL> return msg <EOL> class PullRequestComment ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . number = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . title = self . data [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> self . body = self . data [ '<STR_LIT>' ] [ '<STR_LIT:body>' ] <EOL> self . url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> def created ( self ) : <EOL> body = self . preview ( self . body ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . number , self . title , self . url , body ) <EOL> return msg <EOL> class Issue ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . number = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . title = self . data [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> self . url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . body = self . data [ '<STR_LIT>' ] [ '<STR_LIT:body>' ] <EOL> def opened ( self ) : <EOL> body = self . preview ( self . body ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . number , self . title , self . url , self . repo_link ( ) , body ) <EOL> return msg <EOL> def labeled ( self ) : <EOL> label = self . data [ '<STR_LIT:label>' ] [ '<STR_LIT:name>' ] <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , label , self . number , self . title , self . url , self . repo_link ( ) ) <EOL> return msg <EOL> def closed ( self ) : <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . number , self . title , self . url , self . repo_link ( ) ) <EOL> return msg <EOL> def assigned ( self ) : <EOL> name = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> avatar = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] + "<STR_LIT>" <EOL> assignee = self . create_user_link ( name , url , avatar ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , assignee , self . number , self . title , self . url , self . repo_link ( ) ) <EOL> return msg <EOL> class IssueComment ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . number = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . title = self . data [ '<STR_LIT>' ] [ '<STR_LIT:title>' ] <EOL> self . url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . body = self . data [ '<STR_LIT>' ] [ '<STR_LIT:body>' ] <EOL> def created ( self ) : <EOL> body = self . preview ( self . body ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . number , self . title , self . url , body ) <EOL> return msg <EOL> class CommitComment ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . cid = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ : <NUM_LIT:7> ] <EOL> self . url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . body = self . data [ '<STR_LIT>' ] [ '<STR_LIT:body>' ] <EOL> def created ( self ) : <EOL> body = self . preview ( self . body ) <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . cid , self . url , body ) <EOL> return msg <EOL> class Repository ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> def created ( self ) : <EOL> descr = self . data [ '<STR_LIT>' ] [ '<STR_LIT:description>' ] <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , self . repo_link ( ) , descr ) <EOL> return msg <EOL> class Branch ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . name = self . data [ '<STR_LIT>' ] <EOL> def created ( self ) : <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , <EOL> self . name , self . repo_link ( ) ) <EOL> return msg <EOL> def deleted ( self ) : <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , <EOL> self . name , self . repo_link ( ) ) <EOL> return msg <EOL> class Tag ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> self . name = self . data [ '<STR_LIT>' ] <EOL> def created ( self ) : <EOL> msg = """<STR_LIT>""" % ( self . user_link ( ) , <EOL> self . name , self . repo_link ( ) ) <EOL> return msg <EOL> class Push ( Payload ) : <EOL> def __init__ ( self , data ) : <EOL> Payload . __init__ ( self , data ) <EOL> def commits ( self ) : <EOL> commits = self . data [ '<STR_LIT>' ] <EOL> branch = self . data [ '<STR_LIT>' ] . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> branch_url = self . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] + "<STR_LIT>" + branch <EOL> if not commits : <EOL> commits = [ self . data [ '<STR_LIT>' ] ] <EOL> changeset = "<STR_LIT>" if len ( commits ) > <NUM_LIT:1> else "<STR_LIT>" <EOL> msg = [ ] <EOL> msg . append ( "<STR_LIT>" % ( self . user_link ( ) , len ( commits ) , changeset , branch , branch_url , self . repo_link ( ) ) ) <EOL> for commit in commits : <EOL> cid = commit [ '<STR_LIT:id>' ] [ : <NUM_LIT:7> ] <EOL> curl = commit [ '<STR_LIT:url>' ] <EOL> cmsg = self . preview ( commit [ '<STR_LIT:message>' ] ) <EOL> ctext = "<STR_LIT>" % ( cid , curl , cmsg ) <EOL> msg . append ( "<STR_LIT:\n>" ) <EOL> msg . append ( ctext ) <EOL> return "<STR_LIT>" . join ( msg ) </s>
