mozreview: Fix erroneous assumption that an r- will always be in the carry_forward dict (bug 1281273); r=glob
authorMark Cote <mcote@mozilla.com>
Tue, 21 Jun 2016 21:13:09 -0400
changeset 8553 83c138d64dd9c5e0051dd691527dee77a7eca006
parent 8550 49016c4d2d487896856b42d86e29e7666435782c
child 8554 b44a3ae985e9bc6ade8efbcd9be29807d0da0d8f
child 8555 d0f1b3b0f08db1161605dbae9ec1f104bf20d341
child 8556 4e5a9f48647bae886a21faa6b443d0bb340c00d8
child 8567 b7d62b373addd3847cab168cb34fddca2edebc76
push id928
push usermcote@mozilla.com
push dateThu, 23 Jun 2016 00:34:06 +0000
reviewersglob
bugs1281273
mozreview: Fix erroneous assumption that an r- will always be in the carry_forward dict (bug 1281273); r=glob BugzillaAttachmentUpdates.create_or_update_attachment() presumed that a reviewer who left an r- will always be in the carry_forward dict, which is not the case if they have not been requested for re-review. In general this logic is more confusing than it needs to be, so I also added a big FIXME. MozReview-Commit-ID: D5aUI940EhQ
pylib/mozreview/mozreview/bugzilla/client.py
--- a/pylib/mozreview/mozreview/bugzilla/client.py
+++ b/pylib/mozreview/mozreview/bugzilla/client.py
@@ -91,45 +91,60 @@ class BugzillaAttachmentUpdates(object):
         for a in self.attachments:
 
             # Make sure we check for old-style URLs as well.
             if not self.bugzilla._rb_attach_url_matches(a['data'], url):
                 continue
 
             rb_attachment = a
 
+            # FIXME: There's some redundancy between here and
+            # attachments.update_bugzilla_attachment().  The latter decides
+            # which flags to carry forward based on their type and value, but
+            # we also check flag types and variables here to decide, in turn,
+            # if we should even check the carry_forward dict.  This should be
+            # unified and clarified somehow.
+
             for f in a.get('flags', []):
                 if f['name'] not in ['review', 'feedback']:
                     # We only care about review and feedback flags.
                     continue
                 elif f['name'] == 'feedback':
                     # We always clear feedback flags.
                     flags.append({'id': f['id'], 'status': 'X'})
-                elif f['status'] == '+' and f['setter'] not in carry_forward:
-                    # This r+ flag was set manually on bugzilla rather
-                    # then through a review on Review Board. Always
-                    # clear these flags.
-                    flags.append({'id': f['id'], 'status': 'X'})
                 elif f['status'] == '+' or f['status'] == '-':
-                    if not carry_forward[f['setter']]:
-                        # We should not carry this r+/r- forward so
-                        # re-request review.
-                        flags.append({
-                            'id': f['id'],
-                            'name': 'review',
-                            'status': '?',
-                            'requestee': f['setter']
-                        })
+                    # A reviewer has left a review, either in Review Board or
+                    # in Bugzilla.
+                    if f['setter'] not in carry_forward:
+                        # This flag was set manually in Bugzilla rather
+                        # then through a review on Review Board. Always
+                        # clear these flags.
+                        flags.append({'id': f['id'], 'status': 'X'})
+                    else:
+                        # This flag was set through Review Board; see if
+                        # we should carry it forward.
+                        if not carry_forward[f['setter']]:
+                            # We should not carry this r+/r- forward so
+                            # re-request review.
+                            flags.append({
+                                'id': f['id'],
+                                'name': 'review',
+                                'status': '?',
+                                'requestee': f['setter']
+                            })
+                        # else we leave the flag alone, carrying it forward.
 
-                    carry_forward.pop(f['setter'])
+                        # In either case, we've dealt with this reviewer, so
+                        # remove it from the carry_forward dict.
+                        carry_forward.pop(f['setter'])
                 elif ('requestee' not in f or
                       f['requestee'] not in carry_forward):
                     # We clear review flags where the requestee is not
-                    # a reviewer or someone has manually set r- on the
-                    # attachment.
+                    # a reviewer, or if there is some (possibly future) flag
+                    # other than + or - that does not have a 'requestee' field.
                     flags.append({'id': f['id'], 'status': 'X'})
                 elif f['requestee'] in carry_forward:
                     # We're already waiting for a review from this user
                     # so don't touch the flag.
                     carry_forward.pop(f['requestee'])
 
             break