def on_review_publishing(user, review, **kwargs): """Comment in the bug and potentially r+ or clear a review flag. Note that a reviewer *must* have editbugs to set an attachment flag on someone else's attachment (i.e. the standard BMO review process). TODO: Report lack-of-editbugs properly; see bug 1119065. """ review_request = review.review_request logger.info('Publishing review for user: %s review id: %s ' 'review request id: %s' % (user, review.id, review_request.id)) # skip review requests that were not pushed if not is_pushed(review_request): logger.info('Did not publish review: %s: for user: %d: review not ' 'pushed.' % (user, review.id)) return site = Site.objects.get_current() siteconfig = SiteConfiguration.objects.get_current() comment = build_plaintext_review(review, get_obj_url(review, site, siteconfig), {"user": user}) b = Bugzilla(get_bugzilla_api_key(user)) if is_parent(review_request): # We only support raw comments on parent review requests to prevent # confusion. If the ship-it flag or the review flag was set, throw # an error. # Otherwise, mirror the comment over, associating it with the first # commit. if review.ship_it or review.extra_data.get(REVIEW_FLAG_KEY): raise ParentShipItError # TODO: If we ever allow multiple bugs in a single series, and we want # to continue to allow comments on parents, we'll have to pick one # child for each unique bug. first_child = list(gen_child_rrs(review_request))[0] b.post_comment(int(first_child.get_bug_list()[0]), comment, get_diff_url(first_child), False) else: diff_url = get_diff_url(review_request) bug_id = int(review_request.get_bug_list()[0]) commented = False flag = review.extra_data.get(REVIEW_FLAG_KEY) if flag is not None: commented = b.set_review_flag(bug_id, flag, review.user.email, diff_url, comment) else: # If for some reasons we don't have the flag set in extra_data, # fall back to ship_it logger.warning('Review flag not set on review %s, ' 'updating attachment based on ship_it' % review.id) if review.ship_it: commented = b.r_plus_attachment(bug_id, review.user.email, diff_url, comment) else: commented = b.cancel_review_request(bug_id, review.user.email, diff_url, comment) if comment and not commented: b.post_comment(bug_id, comment, diff_url, False)