Mercurial > kallithea
changeset 5666:b3ddd87f214f
comments: extract common comment creation functionality for changesets and pullrequests
So far not big but it will grow later ...
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 20 Jan 2016 01:47:11 +0100 |
parents | 12e7421e0469 |
children | 7834f845505a |
files | kallithea/controllers/changeset.py kallithea/controllers/pullrequests.py |
diffstat | 2 files changed, 31 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/controllers/changeset.py Wed Jan 20 01:47:11 2016 +0100 @@ -172,6 +172,24 @@ return h.link_to(icon, h.url.current(**params), title=lbl, class_='tooltip') +# Could perhaps be nice to have in the model but is too high level ... +def create_comment(text, status, f_path, line_no, revision=None, pull_request_id=None, closing_pr=None): + """Comment functionality shared between changesets and pullrequests""" + comment = ChangesetCommentsModel().create( + text=text, + repo=c.db_repo.repo_id, + user=c.authuser.user_id, + revision=revision, + pull_request=pull_request_id, + f_path=f_path, + line_no=line_no, + status_change=ChangesetStatus.get_status_lbl(status) if status else None, + closing_pr=closing_pr, + ) + + return comment + + class ChangesetController(BaseRepoController): def __before__(self): @@ -350,15 +368,12 @@ status = request.POST.get('changeset_status') text = request.POST.get('text', '').strip() - c.comment = comment = ChangesetCommentsModel().create( - text=text, - repo=c.db_repo.repo_id, - user=c.authuser.user_id, + c.comment = create_comment( + text, + status, revision=revision, f_path=request.POST.get('f_path'), line_no=request.POST.get('line'), - status_change=(ChangesetStatus.get_status_lbl(status) - if status else None) ) # get status if set ! @@ -372,7 +387,7 @@ c.db_repo.repo_id, status, c.authuser.user_id, - comment, + c.comment, revision=revision, dont_allow_on_closed_pull_request=True ) @@ -396,8 +411,8 @@ data = { 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))), } - if comment is not None: - data.update(comment.get_dict()) + if c.comment is not None: + data.update(c.comment.get_dict()) data.update({'rendered_text': render('changeset/changeset_comment_block.html')})
--- a/kallithea/controllers/pullrequests.py Wed Jan 20 01:47:11 2016 +0100 +++ b/kallithea/controllers/pullrequests.py Wed Jan 20 01:47:11 2016 +0100 @@ -56,7 +56,8 @@ from kallithea.model.changeset_status import ChangesetStatusModel from kallithea.model.forms import PullRequestForm, PullRequestPostForm from kallithea.lib.utils2 import safe_int -from kallithea.controllers.changeset import _ignorews_url, _context_url +from kallithea.controllers.changeset import _ignorews_url, _context_url, \ + create_comment from kallithea.controllers.compare import CompareController from kallithea.lib.graphmod import graph_data @@ -726,16 +727,13 @@ if close_pr: text = _('Closing.') + '\n' + text - comment = ChangesetCommentsModel().create( - text=text, - repo=c.db_repo.repo_id, - user=c.authuser.user_id, - pull_request=pull_request_id, + comment = create_comment( + text, + status, + pull_request_id=pull_request_id, f_path=f_path, line_no=line_no, - status_change=(ChangesetStatus.get_status_lbl(status) - if status and allowed_to_change_status else None), - closing_pr=close_pr + closing_pr=close_pr, ) action_logger(self.authuser,