11import threading
22
3- from reply_module . reply_factory import ReplyFactory
3+ from response_module . response_factory import ResponseFactory
44
55
6- class Reply :
6+ class ReviewResponse :
77 def __init__ (self , config ):
88 """
99 初始化 Reply 实例
@@ -17,6 +17,7 @@ def __init__(self, config):
1717 self .config = config
1818 self .replies = []
1919 self .lock = threading .Lock ()
20+ self .oter_res_state = {}
2021
2122 def add_reply (self , reply_msg ):
2223 """
@@ -68,7 +69,7 @@ def send(self):
6869 self .__parse_msg (main_msg , msg_groups )
6970 ret = True
7071 for target , msg_group in msg_groups .items ():
71- reply_target = ReplyFactory . get_reply_instance (target , self .config )
72+ reply_target = ResponseFactory . get_message_instance (target , self .config )
7273 for msg in msg_group :
7374 ret &= reply_target .send (msg )
7475 return ret
@@ -84,10 +85,10 @@ def send_single_message(self, reply):
8485 """
8586 targets = [t .strip () for t in reply ['target' ].split (',' )]
8687 if 'all' in targets :
87- targets = ReplyFactory . get_all_targets ()
88+ targets = ResponseFactory . get_all_message_targets ()
8889 ret = True
8990 for target in targets :
90- reply_target = ReplyFactory . get_reply_instance (target , self .config )
91+ reply_target = ResponseFactory . get_message_instance (target , self .config )
9192 if ('TITLE_IGNORE' in reply ['msg_type' ] or 'MAIN' in reply ['msg_type' ]
9293 or 'title' not in reply or not reply ['title' ]):
9394 ret &= reply_target .send (reply ['content' ])
@@ -99,7 +100,7 @@ def send_single_message(self, reply):
99100 def __parse_msg (self , msg , msg_groups ):
100101 targets = [t .strip () for t in msg ['target' ].split (',' )]
101102 if 'target' not in msg or 'all' in targets :
102- targets = ReplyFactory . get_all_targets ()
103+ targets = ResponseFactory . get_all_message_targets ()
103104 for target in targets :
104105 if target not in msg_groups :
105106 msg_groups [target ] = {}
@@ -112,8 +113,19 @@ def __parse_msg(self, msg, msg_groups):
112113 title = f"## { msg ['title' ]} \n \n " if 'title' in msg else ''
113114 msg_groups [target ][msg ['group_id' ]].append (f"{ title } { msg ['content' ]} \n \n " )
114115
116+ def set_state (self , res_type , * args , ** kwargs ):
117+ self .oter_res_state [res_type ] = (args , kwargs )
118+
119+ def send_by_other (self , response_type , * args , ** kwargs ):
120+ sender = ResponseFactory .get_other_instance (response_type , self .config )
121+ if sender is None :
122+ raise Exception (f'No such type { response_type } in other response.' )
123+ if self .oter_res_state .get (response_type ):
124+ sender .set_state (* self .oter_res_state [response_type ])
125+ return sender .send (* args , ** kwargs )
126+
115127if __name__ == '__main__' :
116- reply = Reply ({'type' : 'merge_request' ,
128+ reply = ReviewResponse ({'type' : 'merge_request' ,
117129 'project_id' : 9885 ,
118130 'merge_request_iid' : 18 })
119131 threads = []
0 commit comments