From 72a8e708176131342f7924b6d1b958b488298593 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 18 2015 11:04:26 +0000 Subject: When adding a comment to an issue, notify redis if asked With this change, when a comment is made on an issue, if there is a redis connection available, it will queue a message information about the change to the channel of this specific issue. --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 94d47cd..e921de3 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -8,6 +8,10 @@ """ +try: + import simplejson as json +except ImportError: + import json import datetime import markdown @@ -147,7 +151,7 @@ def search_user(session, username=None, email=None, token=None, pattern=None): def add_issue_comment(session, issue, comment, user, ticketfolder, - notify=True): + notify=True, redis=None): ''' Add a comment to an issue. ''' user_obj = __get_user(session, user) @@ -177,6 +181,15 @@ def add_issue_comment(session, issue, comment, user, ticketfolder, ) ) + if redis: + redis.publish(issue.uid, json.dumps({ + 'comment_id': len(issue.comments), + 'comment_added': text2markdown(issue_comment.comment), + 'comment_user': issue_comment.user.user, + 'avatar_url': avatar_url(issue_comment.user.user, size=16), + 'comment_date': issue_comment.date_created.strftime('%Y-%m-%d %H:%M'), + })) + return 'Comment added'