Getting the unit tests passing again / fixing requirements.txt
[margebot.git] / plugins / marge.py
index 0dbbffe..7be6ea6 100755 (executable)
@@ -186,7 +186,7 @@ class Marge(BotPlugin, CrontabMixin):
 
         # 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)
+        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:
@@ -431,33 +431,31 @@ class Marge(BotPlugin, CrontabMixin):
             msg = "Couldn't find {} hooks".format(repo)
             self.log.error("watchrepo: {}".format(msg))
             return msg
-        else:
-            for a_hook in hooks:
-                self.log.info('a_hook: {}'.format(a_hook))
-                hook_attributes = a_hook.attributes
-                if hook_attributes['merge_requests_events'] and hook_attributes['url'].startswith(self.webhook_url):
-                    marge_hook = a_hook
-                    break
+
+        for a_hook in hooks:
+            self.log.info('a_hook: {}'.format(a_hook))
+            hook_attributes = a_hook.attributes
+            if hook_attributes['merge_requests_events'] and hook_attributes['url'].startswith(self.webhook_url):
+                marge_hook = a_hook
+                break
 
         # If so replace it (or error out ?)
         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)
                 self.log.info('watchrepo: {}'.format(msg))
                 return msg
-            else:
-                try:
-                    s_action = "update"
-                    marge_hook.attributes['url'] = url
-                    marge_hook.save()
-                    s_watch_msg = "Updating room list for {} MRs from {} to {}".format(repo, old_rooms, rooms)
-                except Exception as exp:
-                    hook_updated = False
-                    self.log.error("watchrepo; update hook {}  raised exception {}".format(repo, exp))
+            try:
+                s_action = "update"
+                marge_hook.attributes['url'] = url
+                marge_hook.save()
+                s_watch_msg = "Updating room list for {} MRs from {} to {}".format(repo, old_rooms, rooms)
+            except Exception as exp:
+                hook_updated = False
+                self.log.error("watchrepo; update hook {}  raised exception {}".format(repo, exp))
         else:
             try:
                 s_action = "add"