- if request['object_attributes']['work_in_progress']:
- wip = "WIP"
- else:
- wip = ""
- url = request['object_attributes']['url']
- state = request['object_attributes']['state']
- title = request['object_attributes']['title']
-
- author_id = request['object_attributes']['author_id'] # map this to user name ...
- author = self.gitlab.getuser(author_id)
- author_name = author['username']
-
- target_project_id = request['object_attributes']['target_project_id']
- iid = request['object_attributes']['iid']
-
- user_name = request['user']['username'] # will this always be Administrator ?
-
- message = "Reviews: {} has opened a new {} MR: {}\n{}".format(author_name, wip, title, url)
-
- # TODO: Maybe also check the notify_<room> labels assigned to the MR as well ?
- #mr_rooms = self.get_mr_rooms(target_project_id)
- for a_room in rooms.split(','):
- if self.config:
- self.send( self.build_identifier(a_room + '@' + self.chatroom_host ), message)
-
- with self.mutable('OPEN_MRS') as open_mrs:
- open_mrs[(target_project_id,iid,rooms)] = True
-
+
+ # TODO:
+ # - check for reopened / request['object_attributes']['action'] == 'reopn'
+ # (there's no 'action': 'opened' for MRs are created...
+ # - pop open_mrs when MRs are closed (action == close / state == closed
+
+ if request['object_attributes']['work_in_progress']:
+ wip = "WIP"
+ else:
+ wip = ""
+ url = request['project']['homepage']
+ state = request['object_attributes']['state']
+ title = request['object_attributes']['title']
+
+ author_id = request['object_attributes']['author_id'] # map this to user name ...
+ author = self.gitlab.getuser(author_id)
+ author_name = author['username']
+
+ target_project_id = request['object_attributes']['target_project_id']
+ iid = request['object_attributes']['iid']
+
+ user_name = request['user']['username'] # will this always be Administrator ?
+
+ msg_template = "New Review: {} has opened a new {} MR: \"{}\"\n{}/merge_requests/{}"
+ msg = msg_template.format(author_name, wip, title, url, iid)
+
+ for a_room in rooms.split(','):
+ if self.config:
+ self.send(self.build_identifier(a_room + '@' + self.chatroom_host), msg)
+
+ if 'OPEN_MRS' not in self.keys():
+ empty_dict = {}
+ self['OPEN_MRS'] = empty_dict
+
+ with self.mutable('OPEN_MRS') as open_mrs:
+ open_mrs[(target_project_id, iid, rooms)] = True
+