if (target_project_id, iid, rooms) not in open_mrs:
for a_room in rooms.split(','):
if self.config:
- self.send(self.build_identifier(a_room + '@' + self.chatroom_host), msg)
+ self.send(self.build_identifier('~' + a_room), msg) # No chatroom host for mattermost
self.log.info("webhook: Saving ({}, {}, {})".format(target_project_id, iid, rooms))
open_mrs[(target_project_id, iid, rooms)] = True
self.log.info("mr_status_msg: a_mr: {}".format(a_mr))
mr_attrs = a_mr.attributes
- # Only weed out MRs less than the soak time for the crontab output (where author==None)
now = datetime.now(timezone.utc)
creation_time = parser.parse(mr_attrs['created_at'], tzinfos=[tzutc()]).astimezone(timezone.utc)
- if not author:
- self.log.info("times: {}, {}, {}".format(creation_time, self.soak_delta, now))
- if creation_time + self.soak_delta > now:
- project_id = mr_attrs['target_project_id']
- mr_id = mr_attrs['id']
- soak_hours = self.config['CRONTAB_SOAK_HOURS']
- info_template = "skipping: MR <{},{}> was opened less than {} hours ago"
- info_msg = info_template.format(project_id, mr_id, soak_hours)
- self.log.info(info_msg)
- return None
str_open_since = deltastr(now - creation_time)
# initialize the reminders
rooms = self.rooms()
for a_room in rooms:
- self.log.info("poller: a_room.node: {}".format(a_room.node))
- reminder_msg[a_room.node] = []
+ self.log.info("poller: a_room.name: {}".format(a_room.name)) # XMPP was a_room.node instead of a_room.name
+ reminder_msg[a_room.name] = []
still_open_mrs = {}
for a_room, room_msg_list in reminder_msg.items():
if room_msg_list != []:
if self.config:
- to_room = a_room + '@' + self.config['CHATROOM_HOST']
+ to_room = "~" + a_room # No CHATROOM_HOST in mattermost
msg = tenv().get_template('reviews.md').render(msg_list=room_msg_list)
self.send(self.build_identifier(to_room), msg)
self.log.info('project: {}, id: {}, a_mr: {}'.format(project, id, a_mr))
- # If the MR is tagged 'never-close' or 'abandoned', ignore it
+ # If the MR is tagged 'never-close' or 'abondoned' ignore it
if 'labels' in mr_attrs and ('never-close' in mr_attrs['labels'] or 'abandoned' in mr_attrs['labels']):
continue
msg = "Couldn't find {} hooks".format(repo)
self.log.error("watchrepo: {}".format(msg))
return msg
+
for a_hook in hooks:
self.log.info('a_hook: {}'.format(a_hook))
hook_attributes = a_hook.attributes
url = "{}{}".format(self.webhook_url, rooms) # webhooks_url will end in '/'
hook_updated = True
if marge_hook:
+
old_rooms = marge_hook.attributes['url'].split(self.webhook_url, 1)[1]
if old_rooms == rooms:
- msg = "Already reporting {} MRs to the {} room(s)".format(repo, rooms)
+ msg = "Already reporting {} MRs to the {} room(s). Run !reviews to see the MR list.".format(repo, rooms)
self.log.info('watchrepo: {}'.format(msg))
return msg
try:
new_open_mrs[(project_id, mr_id, old_rooms)] = True
# pragma pylint: enable=simplifiable-if-statement
open_mrs = new_open_mrs
-
- # If adding a new repo, check for existing opened MRs in the repo.
- else:
- for state in ['opened']:
- a_project = self.gitlab.projects.get(target_project_id)
- mr_list = a_project.mergerequests.list(state=state)
- for an_mr in mr_list:
- mr_count += 1
- mr_id = an_mr.attributes['iid']
- open_mrs[(target_project_id, mr_id, rooms)] = True
+ mr_count = len(new_open_mrs)
+
+ # check for existing opened MRs in the repo.
+ # (add any MR that may have been opened while marge was down)
+ for state in ['opened']:
+ a_project = self.gitlab.projects.get(target_project_id)
+ mr_list = a_project.mergerequests.list(state=state)
+ for an_mr in mr_list:
+ mr_count += 1
+ mr_id = an_mr.attributes['iid']
+ open_mrs[(target_project_id, mr_id, rooms)] = True
self['OPEN_MRS'] = open_mrs
assert 'Already reporting group/new_repo MRs to the room1,room2,room3 room(s)' in pm
def test_watchrepo_updating_roomlist(self, margebot):
- with HTTMock(mock_projects_hooks_list_already_watching,
+ with HTTMock(mock_projects_mergerequests_list_unreviewed_review,
+ mock_projects_hooks_list_already_watching,
mock_projects_hooks_get_already_watching,
mock_projects_get):
margebot.push_message('!watchrepo group/new_repo room4,room5,room6')
def test_crontab_hook(self, margebot_one_review, monkeypatch, mocker):
plugin = margebot_one_review._bot.plugin_manager.get_plugin_obj_by_name('Marge')
+ # See comments from https://bradmontgomery.net/blog/how-world-do-you-mock-name-attribute/
def mock_rooms():
- return [mocker.MagicMock(node='room1'), mocker.MagicMock(node='room2')]
+ m1 = mocker.MagicMock()
+ m2 = mocker.MagicMock()
+ m1.name = 'room1'
+ m2.name = 'room2'
+ return [m1, m2]
monkeypatch.setattr(plugin, 'rooms', mock_rooms)
with HTTMock(mock_projects_get,