MozReview: Move 'on_reply_publishing' signal to mozreview (
Bug 1262548). r?smacleod
MozReview-Commit-ID: 4GMQ5qXPuF1
--- a/pylib/mozreview/mozreview/signal_handlers.py
+++ b/pylib/mozreview/mozreview/signal_handlers.py
@@ -23,16 +23,17 @@ from reviewboard.extensions.hooks import
SignalHook,
)
from reviewboard.reviews.models import (
Review,
ReviewRequest,
ReviewRequestDraft,
)
from reviewboard.reviews.signals import (
+ reply_publishing,
review_publishing,
review_request_closed,
review_request_publishing,
review_request_reopened,
)
from mozreview.bugzilla.attachments import (
update_bugzilla_attachments,
@@ -145,16 +146,22 @@ def initialize_signal_handlers(extension
sender=Review)
SignalHook(
extension,
review_publishing,
on_review_publishing,
sandbox_errors=False)
+ SignalHook(
+ extension,
+ reply_publishing,
+ on_reply_publishing,
+ sandbox_errors=False)
+
def post_save_review_request_draft(sender, **kwargs):
"""Handle post_save for a ReviewRequestDraft."""
draft = kwargs["instance"]
if kwargs["created"] and not kwargs["raw"]:
copy_commit_data(draft)
@@ -656,8 +663,35 @@ def on_review_publishing(user, review, *
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)
+
+
+def get_reply_url(reply, site=None, siteconfig=None):
+ """ Get the URL for a reply to a review.
+
+ Since replies can have multiple comments, we can't link to a specific
+ comment, so we link to the parent review which the reply is targeted at.
+ """
+ return get_obj_url(reply.base_reply_to, site=site, siteconfig=siteconfig)
+
+
+@bugzilla_to_publish_errors
+def on_reply_publishing(user, reply, **kwargs):
+ review_request = reply.review_request
+ logger.info('Posting bugzilla reply for review request %s' % (
+ review_request.id))
+
+ # skip review requests that were not pushed
+ if not is_pushed(review_request):
+ return
+
+ bug_id = int(review_request.get_bug_list()[0])
+ b = Bugzilla(get_bugzilla_api_key(user))
+
+ url = get_reply_url(reply)
+ comment = build_plaintext_review(reply, url, {"user": user})
+ b.post_comment(bug_id, comment)
--- a/pylib/rbbz/rbbz/extension.py
+++ b/pylib/rbbz/rbbz/extension.py
@@ -1,65 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import logging
-
from reviewboard.extensions.base import Extension
-from reviewboard.extensions.hooks import SignalHook
-from reviewboard.reviews.signals import (
- reply_publishing,
-)
-
-from mozreview.bugzilla.client import Bugzilla
-from mozreview.bugzilla.errors import (
- bugzilla_to_publish_errors,
-)
-from mozreview.diffs import build_plaintext_review
-from mozreview.extra_data import (
- is_pushed,
-)
-from mozreview.models import (
- get_bugzilla_api_key,
-)
-from mozreview.rb_utils import (
- get_obj_url,
-)
-
-logger = logging.getLogger(__name__)
class BugzillaExtension(Extension):
def initialize(self):
- # Any abortable signal hooks that talk to Bugzilla should have
- # sandbox_errors=False, since we don't want to complete the action if
- # updating Bugzilla failed for any reason.
- SignalHook(self, reply_publishing, on_reply_publishing,
- sandbox_errors=False)
-
-
-def get_reply_url(reply, site=None, siteconfig=None):
- """ Get the URL for a reply to a review.
-
- Since replies can have multiple comments, we can't link to a specific
- comment, so we link to the parent review which the reply is targeted at.
- """
- return get_obj_url(reply.base_reply_to, site=site, siteconfig=siteconfig)
-
-
-@bugzilla_to_publish_errors
-def on_reply_publishing(user, reply, **kwargs):
- review_request = reply.review_request
- logger.info('Posting bugzilla reply for review request %s' % (
- review_request.id))
-
- # skip review requests that were not pushed
- if not is_pushed(review_request):
- return
-
- bug_id = int(review_request.get_bug_list()[0])
- b = Bugzilla(get_bugzilla_api_key(user))
-
- url = get_reply_url(reply)
- comment = build_plaintext_review(reply, url, {"user": user})
- b.post_comment(bug_id, comment)
+ pass