mozreview: remove reviewers from bugzilla attachment name (bug 1244263); r?smacleod draft
authorbyron jones <glob@mozilla.com>
Thu, 26 May 2016 13:14:49 +0800 (2016-05-26)
changeset 8184 9140674dd3af22bdda0fa65912de049477b20990
parent 8183 ce92e503ff308ce1c7476ec19d105b9a2cbdc8d3
push id861
push userbjones@mozilla.com
push dateThu, 26 May 2016 05:17:02 +0000 (2016-05-26)
reviewerssmacleod
bugs1244263
mozreview: remove reviewers from bugzilla attachment name (bug 1244263); r?smacleod When an attachment is created in Bugzilla ensure any review request markers (eg. r?nick) are removed from the description. In addition to removing unncessary clutter, it avoids confusion when a reviewer is changed in MozReview, which will result in a description with one reviewer, but flags with another. MozReview-Commit-ID: Dwtp3XCGD5P
hgext/reviewboard/tests/test-bugzilla.t
pylib/mozautomation/mozautomation/commitparser.py
pylib/mozreview/mozreview/bugzilla/client.py
--- a/hgext/reviewboard/tests/test-bugzilla.t
+++ b/hgext/reviewboard/tests/test-bugzilla.t
@@ -249,42 +249,42 @@ Ensure r? in the commit description sets
   (published review request 3)
 
   $ bugzilla dump-bug 2
   Bug 2:
     attachments:
     - attacher: default@example.com
       content_type: text/x-review-board-request
       data: http://$DOCKER_HOSTNAME:$HGPORT1/r/4/diff/#index_header
-      description: Bug 2 - Foo 1 r?reviewer
+      description: Bug 2 - Foo 1
       file_name: reviewboard-4-url.txt
       flags:
       - id: 2
         name: review
         requestee: reviewer@example.com
         setter: default@example.com
         status: '?'
       id: 2
       is_obsolete: false
       is_patch: false
-      summary: Bug 2 - Foo 1 r?reviewer
+      summary: Bug 2 - Foo 1
     blocks: []
     cc:
     - reviewer@example.com
     comments:
     - author: default@example.com
       id: 2
       tags: []
       text: ''
     - author: default@example.com
       id: 5
       tags: []
       text:
       - Created attachment 2
-      - Bug 2 - Foo 1 r?reviewer
+      - Bug 2 - Foo 1
       - ''
       - 'Review commit: http://$DOCKER_HOSTNAME:$HGPORT1/r/4/diff/#index_header'
       - 'See other reviews: http://$DOCKER_HOSTNAME:$HGPORT1/r/4/'
     component: TestComponent
     depends_on: []
     platform: All
     product: TestProduct
     resolution: ''
--- a/pylib/mozautomation/mozautomation/commitparser.py
+++ b/pylib/mozautomation/mozautomation/commitparser.py
@@ -114,36 +114,37 @@ def parse_requal_reviewers(commit_descri
 def parse_rquestion_reviewers(commit_description):
     for reviewer in parse_reviewers(commit_description,
                                     flag_re=RQUESTION_SPECIFIER_RE):
         yield reviewer
 
 
 def replace_reviewers(commit_description, reviewers):
     if not reviewers:
-        return commit_description
-    reviewers = 'r=' + ','.join(reviewers)
+        reviewers_str = ''
+    else:
+        reviewers_str = 'r=' + ','.join(reviewers)
 
     commit_description = commit_description.splitlines()
     commit_summary = commit_description.pop(0)
     commit_description = '\n'.join(commit_description)
 
     if not R_SPECIFIER_RE.search(commit_summary):
-        commit_summary += ' ' + reviewers
+        commit_summary += ' ' + reviewers_str
     else:
         # replace the first r? with the reviewer list, and all subsequent
         # occurences with a marker to mark the blocks we need to remove
         # later
         d = {'first': True}
 
         def replace_first_reviewer(matchobj):
             if R_SPECIFIER_RE.match(matchobj.group(2)):
                 if d['first']:
                     d['first'] = False
-                    return matchobj.group(1) + reviewers
+                    return matchobj.group(1) + reviewers_str
                 else:
                     return '\0'
             else:
                 return matchobj.group(0)
 
         commit_summary = re.sub(REVIEWERS_RE, replace_first_reviewer,
                                 commit_summary)
 
--- a/pylib/mozreview/mozreview/bugzilla/client.py
+++ b/pylib/mozreview/mozreview/bugzilla/client.py
@@ -9,16 +9,18 @@ import xmlrpclib
 from urlparse import urlparse, urlunparse
 
 from djblets.siteconfig.models import SiteConfiguration
 from djblets.util.decorators import simple_decorator
 
 from mozreview.bugzilla.errors import BugzillaError, BugzillaUrlError
 from mozreview.bugzilla.transports import bugzilla_transport
 
+from mozautomation.commitparser import replace_reviewers
+
 
 logger = logging.getLogger(__name__)
 
 
 @simple_decorator
 def xmlrpc_to_bugzilla_errors(func):
     def _transform_errors(*args, **kwargs):
         try:
@@ -153,17 +155,17 @@ class BugzillaAttachmentUpdates(object):
 
             if rb_attachment['is_obsolete']:
                 params['is_obsolete'] = False
         else:
             params['data'] = url
             params['content_type'] = 'text/x-review-board-request'
 
         params['file_name'] = 'reviewboard-%d-url.txt' % review_request_id
-        params['summary'] = summary
+        params['summary'] = replace_reviewers(summary, None)
         params['comment'] = comment
         if flags:
             params['flags'] = flags
 
         if rb_attachment:
             self.updates.append(params)
         else:
             self.creates.append(params)