From d48706272952731af4f77cc2b193175c1445ba01 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 29 2017 16:40:28 +0000 Subject: When loading comment from JSON rely on username/comment rather than comment id Instead of relying on comment id which may vary from instance to instance depending on what is in the database, use the combo username/comment to find out if a comment was already made to the ticket (so that if not, it gets created). We are short-coming the case where the same user submits twice the exact same comment, so be it. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 73582ad..307119a 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2586,6 +2586,23 @@ def get_issue_comment(session, issue_uid, comment_id): return query.first() +def get_issue_comment_by_user_and_comment( + session, issue_uid, user_id, content): + ''' Return a specific comment of a specified issue. + ''' + query = session.query( + model.IssueComment + ).filter( + model.IssueComment.issue_uid == issue_uid + ).filter( + model.IssueComment.user_id == user_id + ).filter( + model.IssueComment.comment == content + ) + + return query.first() + + def get_request_comment(session, request_uid, comment_id): ''' Return a specific comment of a specified request. ''' diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 03c3b58..486b76f 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -601,8 +601,8 @@ def update_ticket_from_git( for comment in json_data['comments']: usercomment = get_user_from_json(session, comment) - commentobj = pagure.lib.get_issue_comment( - session, issue_uid, comment['id']) + commentobj = pagure.lib.get_issue_comment_by_user_and_comment( + session, issue_uid, usercomment.id, comment['comment']) if not commentobj: pagure.lib.add_issue_comment( session,