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.
--- 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)
})