From cb9dd71bf6af0ff4c9789b0a4346c28f87875910 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2015 16:08:53 +0000 Subject: Rename pagure.lib.edit_pull_request_comment into pagure.lib.edit_comment This makes it more flexible to any type of comment we may want to edit --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index b6c1fc4..ff3522c 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -834,9 +834,9 @@ def add_pull_request_comment(session, request, commit, filename, row, return 'Comment added' -def edit_pull_request_comment(session, request, comment, user, - updated_comment, requestfolder, redis): - '''Edit a comment in the pull request''' +def edit_comment(session, parent, comment, user, + updated_comment, folder, redis): + ''' Edit a comment. ''' user_obj = __get_user(session, user) comment.comment = updated_comment comment.edited_on = datetime.datetime.utcnow() @@ -847,20 +847,28 @@ def edit_pull_request_comment(session, request, comment, user, session.flush() pagure.lib.git.update_git( - request, repo=request.project, repofolder=requestfolder) + parent, repo=parent.project, repofolder=folder) + + topic = 'issue.comment.edited' + key = 'issue' + id_ = 'issue_id' + if parent.isa == 'pull-request': + topic = 'pull-request.comment.edited' + key = 'pullrequest' + id_ = 'request_id' pagure.lib.notify.log( - request.project, - topic='pull-request.comment.edited', - msg=dict( - pullrequest=request.to_json(public=True), - agent=user_obj.username, - ) + parent.project, + topic=topic, + msg={ + key: parent.to_json(public=True), + 'agent': user_obj.username, + } ) if redis: redis.publish(request.uid, json.dumps({ - 'request_id': len(request.comments), + id_: len(request.comments), 'comment_updated': text2markdown(comment.comment), 'comment_id': comment.id, 'comment_editor': user_obj.user, @@ -1817,7 +1825,7 @@ def get_issue_comment(session, issue_uid, comment_id): def get_request_comment(session, request_uid, comment_id): - ''' Return a specific comment of a specified issue. + ''' Return a specific comment of a specified request. ''' query = session.query( model.PullRequestComment diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index ddb3e6d..d827572 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -572,7 +572,7 @@ def pull_request_edit_comment(repo, requestid, commentid, username=None): updated_comment = form.update_comment.data try: - message = pagure.lib.edit_pull_request_comment( + message = pagure.lib.edit_comment( SESSION, request=request, comment=comment,