From aeb0d4526df36730bcbdd8270bbedd0a69e10a4b Mon Sep 17 00:00:00 2001 From: Marcin Lulek Date: Mon, 19 Sep 2016 15:15:23 +0200 Subject: [PATCH] pull request: send live notification when PR update happens --- rhodecode/controllers/pullrequests.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py index 097638b5..2b8a5f73 100644 --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -29,6 +29,7 @@ from webob.exc import HTTPNotFound, HTTPForbidden, HTTPBadRequest from pylons import request, tmpl_context as c, url from pylons.controllers.util import redirect from pylons.i18n.translation import _ +from pyramid.threadlocal import get_current_registry from sqlalchemy.sql import func from sqlalchemy.sql.expression import or_ @@ -40,6 +41,7 @@ from rhodecode.lib.base import ( from rhodecode.lib.auth import ( LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous, HasAcceptedRepoType, XHRRequired) +from rhodecode.lib.channelstream import channelstream_request from rhodecode.lib.utils import jsonify from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode from rhodecode.lib.vcs.backends.base import EmptyCommit @@ -520,6 +522,34 @@ class PullrequestsController(BaseRepoController): count_added=len(changes.added), count_removed=len(changes.removed)) h.flash(msg, category='success') + registry = get_current_registry() + rhodecode_plugins = getattr(registry, + 'rhodecode_plugins', {}) + channelstream_config = rhodecode_plugins.get( + 'channelstream', {}) + if channelstream_config.get('enabled'): + message = msg + ' - ' \ + '{}'.format( + _('Reload page') + ) + channel = '/repo${}$/pr/{}'.format( + pull_request.target_repo.repo_name, + pull_request.pull_request_id + ) + payload = { + 'type': 'message', + 'user': 'system', + 'exclude_users': [request.user.username], + 'channel': channel, + 'message': { + 'message': message, + 'level': 'success', + 'topic': '/notifications' + } + } + channelstream_request(channelstream_config, [payload], + '/message', raise_exc=False) else: h.flash(_("Nothing changed in pull request."), category='warning')