mozreview: only include ship-it reviews in rewritten commit messages (Bug 1236725). r?dminor draft
authorSteven MacLeod <smacleod@mozilla.com>
Mon, 04 Jan 2016 19:05:46 -0500
changeset 6523 46761a9c3ef97e3cc73b862b565173226b72edd9
parent 6521 daaf1305f641dab34099e98cef38cb4a0bf01fa3
push id483
push usersmacleod@mozilla.com
push dateTue, 05 Jan 2016 00:14:18 +0000
reviewersdminor
bugs1236725
mozreview: only include ship-it reviews in rewritten commit messages (Bug 1236725). r?dminor Currently our commit rewriting will include users who did not give a ship-it and users who gave a ship-it in the past but overrode it with a non ship-it review. This does not match up with how the approval hook functions and also adds reviewers who did not sign off on the code. We should only include users who their most recent review has a ship-it. While we're at it we should filter out the author as well. In the event that the author is the only user to have given a ship-it, we will now include an r=me to show they approved their own commit.
pylib/mozreview/mozreview/resources/commit_rewrite.py
--- a/pylib/mozreview/mozreview/resources/commit_rewrite.py
+++ b/pylib/mozreview/mozreview/resources/commit_rewrite.py
@@ -49,18 +49,30 @@ class CommitRewriteResource(WebAPIResour
         for child in children:
             try:
                 child_request = ReviewRequest.objects.get(id=child[1])
             except ReviewRequest.DoesNotExist:
                 return DOES_NOT_EXIST
             if not child_request.approved:
                 return AUTOLAND_REVIEW_NOT_APPROVED
 
-            reviewers = map(lambda review: review.user.username,
-                            gen_latest_reviews(child_request))
+            reviewers = [
+                r.user.username for r in gen_latest_reviews(child_request) if
+                r.ship_it and
+                r.user != child_request.submitter
+            ]
+
+            if not reviewers and child_request.approved:
+                # This review request is approved (the repeated check is
+                # to ensure this is guaranteed if other parts of the code
+                # change) but we have an empty list of reviewers. We'll
+                # assume the author has just approved this themself and
+                # set r=me
+                reviewers.append('me')
+
             result.append({
                 'commit': child[0],
                 'id': child[1],
                 'reviewers': reviewers,
                 'summary': replace_reviewers(child_request.description,
                                              reviewers)
             })