channelstream: push events with comments on single commits.

- use wrapper for posting to simplify the code.
This commit is contained in:
Marcin Kuzminski 2017-07-26 18:04:56 +02:00
parent f1f84b5b64
commit fa5dd62880
3 changed files with 30 additions and 29 deletions

View file

@ -228,6 +228,7 @@ def post_message(channel, message, username, registry=None):
if not registry:
registry = get_current_registry()
log.debug('Channelstream: sending notification to channel %s', channel)
rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
channelstream_config = rhodecode_plugins.get('channelstream', {})
if channelstream_config.get('enabled'):

View file

@ -33,7 +33,7 @@ from pyramid.threadlocal import get_current_registry, get_current_request
from sqlalchemy.sql.expression import null
from sqlalchemy.sql.functions import coalesce
from rhodecode.lib import helpers as h, diffs
from rhodecode.lib import helpers as h, diffs, channelstream
from rhodecode.lib import audit_logger
from rhodecode.lib.channelstream import channelstream_request
from rhodecode.lib.utils2 import extract_mentioned_users, safe_str
@ -354,43 +354,34 @@ class CommentsModel(BaseModel):
self._log_audit_action(
action, {'data': comment_data}, user, comment)
registry = get_current_registry()
rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {})
channelstream_config = rhodecode_plugins.get('channelstream', {})
msg_url = ''
channel = None
if commit_obj:
msg_url = commit_comment_url
repo_name = repo.repo_name
channel = u'/repo${}$/commit/{}'.format(
repo_name,
commit_obj.raw_id
)
elif pull_request_obj:
msg_url = pr_comment_url
repo_name = pr_target_repo.repo_name
if channelstream_config.get('enabled'):
message = '<strong>{}</strong> {} - ' \
'<a onclick="window.location=\'{}\';' \
'window.location.reload()">' \
'<strong>{}</strong></a>'
message = message.format(
user.username, _('made a comment'), msg_url,
_('Show it now'))
channel = '/repo${}$/pr/{}'.format(
channel = u'/repo${}$/pr/{}'.format(
repo_name,
pull_request_id
)
payload = {
'type': 'message',
'timestamp': datetime.utcnow(),
'user': 'system',
'exclude_users': [user.username],
'channel': channel,
'message': {
'message': message,
'level': 'info',
'topic': '/notifications'
}
}
channelstream_request(channelstream_config, [payload],
'/message', raise_exc=False)
message = '<strong>{}</strong> {} - ' \
'<a onclick="window.location=\'{}\';' \
'window.location.reload()">' \
'<strong>{}</strong></a>'
message = message.format(
user.username, _('made a comment'), msg_url,
_('Show it now'))
channelstream.post_message(
channel, message, user.username,
registry=get_current_registry())
return comment

View file

@ -61,13 +61,22 @@ var rhodeCodeApp = Polymer({
},
checkViewChannels: function () {
var channels = []
// subscribe to different channels data is sent.
var channels = [];
// subscribe to PR repo channel for PR's'
if (templateContext.pull_request_data.pull_request_id) {
var channelName = '/repo$' + templateContext.repo_name + '$/pr/' +
String(templateContext.pull_request_data.pull_request_id);
channels.push(channelName);
}
if (templateContext.commit_data.commit_id) {
var channelName = '/repo$' + templateContext.repo_name + '$/commit/' +
String(templateContext.commit_data.commit_id);
channels.push(channelName);
}
return channels;
},