44
55
66class Reply :
7- def __init__ (self , project_id , merge_request_iid ):
7+ def __init__ (self , config ):
8+ if not isinstance (config , dict ):
9+ raise Exception ('Reply config should be a dict.' )
10+ if 'type' not in config :
11+ raise Exception ('Reply config should contain a type field.' )
12+ self .config = config
813 self .replies = []
914 self .lock = threading .Lock ()
10- self .project_id = project_id
11- self .merge_request_iid = merge_request_iid
1215
1316 def add_reply (self , reply_msg ):
1417 # reply 格式检查:title, content 必选
@@ -40,7 +43,7 @@ def send(self):
4043 self .__parse_msg (main_msg , msg_list )
4144 ret = True
4245 for target , msg in msg_list .items ():
43- reply_target = ReplyFactory .get_reply_instance (target , self .project_id , self . merge_request_iid )
46+ reply_target = ReplyFactory .get_reply_instance (target , self .config )
4447 ret &= reply_target .send (msg )
4548 return ret
4649
@@ -53,7 +56,7 @@ def send_single_message(self, reply):
5356 targets = ReplyFactory .get_all_targets ()
5457 ret = True
5558 for target in targets :
56- reply_target = ReplyFactory .get_reply_instance (target , self .project_id , self . merge_request_iid )
59+ reply_target = ReplyFactory .get_reply_instance (target , self .config )
5760 # 如果title不为__IGNORE__ or __MAIN_REVIEW__, 则发送带有标题的消息
5861 if 'title' not in reply or reply ['title' ] not in ['__IGNORE__' , '__MAIN_REVIEW__' ]:
5962 ret &= reply_target .send (f"## { reply ['title' ]} \n \n { reply ['content' ]} \n \n " )
@@ -75,7 +78,9 @@ def __parse_msg(self, msg, msg_list):
7578
7679
7780if __name__ == '__main__' :
78- reply = Reply (9885 , 18 )
81+ reply = Reply ({'type' : 'merge_request' ,
82+ 'project_id' : 9885 ,
83+ 'merge_request_iid' : 18 })
7984 threads = []
8085 for i in range (10 ):
8186 threads .append (threading .Thread (target = reply .add_reply , args = (
0 commit comments