From 2c11b401b3f4051018a88ea8eee2af5b52a8e9e3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 31 2014 11:20:38 +0000 Subject: Add the add_pull_request_comment method to the internal API This method is used to add a comment to a pull-request to the database --- diff --git a/progit/lib.py b/progit/lib.py index a16ad0d..467ba53 100644 --- a/progit/lib.py +++ b/progit/lib.py @@ -100,6 +100,31 @@ def add_issue_comment(session, issue, comment, user, ticketfolder): return 'Comment added' +def add_pull_request_comment(session, request, commit, row, comment, user): + ''' Add a comment to a pull-request. ''' + user_obj = get_user(session, user) + if not user_obj: + user_obj = get_user_by_email(session, user) + + if not user_obj: + raise progit.exceptions.ProgitException( + 'No user "%s" found' % user + ) + + pr_comment = model.PullRequestComment( + pull_request_id=request.id, + commit_id=commit, + line=row, + comment=comment, + user_id=user_obj.id, + ) + session.add(pr_comment) + # Make sure we won't have SQLAlchemy error before we create the repo + session.flush() + + return 'Comment added' + + def get_user_project(session, username): ''' Retrieve the list of projects managed by a user.