From 7910a61b1e5bbc1468a78947c8af54367d158be3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2016 13:22:16 +0000 Subject: [PATCH 1/4] Ensure we only add a notification when it makes sense --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 7b55ea4..0d957ac 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1152,17 +1152,18 @@ def diff_pull_request( if request.status and diff_commits: first_commit = repo_obj[diff_commits[-1].oid.hex] # Check if we can still rely on the merge_status - verb = 'updated' + verb = None if request.commit_start != first_commit.oid.hex or\ request.commit_stop != diff_commits[0].oid.hex: request.merge_status = None + verb = 'updated' if request.commit_start != first_commit.oid.hex: verb = 'rebased' request.commit_start = first_commit.oid.hex request.commit_stop = diff_commits[0].oid.hex session.add(request) session.commit() - if request.merge_status is None: + if verb: pagure.lib.add_pull_request_comment( session, request, commit=None, tree_id=None, filename=None, row=None, From 50f9a36cbde8bda06e9afd74217f6c35a8ec7e80 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2016 13:33:41 +0000 Subject: [PATCH 2/4] Specify if the comment was a notification in the redis message And only convert to markdown if it is not a notification --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 592fbec..af2cdff 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -817,9 +817,13 @@ def add_pull_request_comment(session, request, commit, tree_id, filename, # Send notification for the event-source server if REDIS: + comment_text = pr_comment.comment + if not notification: + comment_text = text2markdown(pr_comment.comment) + REDIS.publish('pagure.%s' % request.uid, json.dumps({ 'request_id': request.id, - 'comment_added': text2markdown(pr_comment.comment), + 'comment_added': comment_text, 'comment_user': pr_comment.user.user, 'comment_id': pr_comment.id, 'avatar_url': avatar_url_from_openid( @@ -828,6 +832,7 @@ def add_pull_request_comment(session, request, commit, tree_id, filename, 'commit_id': commit, 'filename': filename, 'line': row, + 'notification': notification, })) pagure.lib.notify.log( From 25eb489079c2f2ace6212082b1e83cbb1a7a9c95 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2016 13:34:09 +0000 Subject: [PATCH 3/4] Commit the comment added --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 0d957ac..a2ea757 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1172,6 +1172,7 @@ def diff_pull_request( requestfolder=requestfolder, notify=False, notification=True ) + session.commit() pagure.lib.git.update_git( request, repo=request.project, repofolder=requestfolder) From 414f78bedddb4388a892dd08bef979b8c6d9ccca Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 24 2016 13:34:17 +0000 Subject: [PATCH 4/4] Display the notification comments on the PR page if one is detected --- diff --git a/pagure/static/request_ev.js b/pagure/static/request_ev.js index ada210d..cb05b27 100644 --- a/pagure/static/request_ev.js +++ b/pagure/static/request_ev.js @@ -13,7 +13,19 @@ add_comment = function(data, username) { edit_btn = ''; } - if (inline) { + if (data.notification){ + var _data = '
\ +
\ +
\ + ' + data.comment_added + '\ +
\ + \ + Just now
\ +
\ +
\ +
'; + + } else if (inline) { var _data = ' \ \
\