From 032826bcc9dacd09b1667154090ad267743704e9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 01 2015 12:55:26 +0000 Subject: Adjust add_pull_request_flag in the internal library to support update This way one can either create or update (edit) a flag attached to a PullRequest --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 44f901a..3526e00 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -684,15 +684,23 @@ def add_pull_request_flag(session, request, username, percent, comment, url, ''' Add a flag to a pull-request. ''' user_obj = __get_user(session, user) - pr_flag = model.PullRequestFlag( - pull_request_uid=request.uid, - uid=uid or uuid.uuid4().hex, - username=username, - percent=percent, - comment=comment, - url=url, - user_id=user_obj.id, - ) + action = 'added' + pr_flag = get_pull_request_flag_by_uid(session, uid) + if pr_flag: + action = 'updated' + pr_flag.comment = comment + pr_flag.percent = percent + pr_flag.url = url + else: + pr_flag = model.PullRequestFlag( + pull_request_uid=request.uid, + uid=uid or uuid.uuid4().hex, + username=username, + percent=percent, + comment=comment, + url=url, + user_id=user_obj.id, + ) session.add(pr_flag) # Make sure we won't have SQLAlchemy error before we create the repo session.flush() @@ -702,14 +710,14 @@ def add_pull_request_flag(session, request, username, percent, comment, url, pagure.lib.notify.log( request.project, - topic='pull-request.flag.added', + topic='pull-request.flag.%s' % action, msg=dict( pullrequest=request.to_json(), agent=user_obj.username, ) ) - return 'Flag added' + return 'Flag %s' % action def new_project(session, user, name, blacklist,