# HG changeset patch # User Marcin Kuzminski # Date 2017-01-18 18:15:46 # Node ID d0b1d315b00ba9ebd22b8f9c112ff76eabdf2aa6 # Parent e83852afdcce7b19ee9953b2f6e7d6144fd5264c api: added comment_resolved_id into aprameters to resolve TODO notes via API. diff --git a/rhodecode/api/views/pull_request_api.py b/rhodecode/api/views/pull_request_api.py --- a/rhodecode/api/views/pull_request_api.py +++ b/rhodecode/api/views/pull_request_api.py @@ -364,6 +364,7 @@ def comment_pull_request( request, apiuser, repoid, pullrequestid, message=Optional(None), commit_id=Optional(None), status=Optional(None), comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), + resolves_comment_id=Optional(None), userid=Optional(OAttr('apiuser'))): """ Comment on the pull request specified with the `pullrequestid`, @@ -422,6 +423,7 @@ def comment_pull_request( status = Optional.extract(status) commit_id = Optional.extract(commit_id) comment_type = Optional.extract(comment_type) + resolves_comment_id = Optional.extract(resolves_comment_id) if not message and not status: raise JSONRPCError( @@ -446,6 +448,17 @@ def comment_pull_request( if commit_idx != 0: allowed_to_change_status = False + if resolves_comment_id: + comment = ChangesetComment.get(resolves_comment_id) + if not comment: + raise JSONRPCError( + 'Invalid resolves_comment_id `%s` for this pull request.' + % resolves_comment_id) + if comment.comment_type != ChangesetComment.COMMENT_TYPE_TODO: + raise JSONRPCError( + 'Comment `%s` is wrong type for setting status to resolved.' + % resolves_comment_id) + text = message status_label = ChangesetStatus.get_status_lbl(status) if status and allowed_to_change_status: @@ -468,7 +481,8 @@ def comment_pull_request( status_change_type=(status if status_change else None), closing_pr=False, renderer=renderer, - comment_type=comment_type + comment_type=comment_type, + resolves_comment_id=resolves_comment_id ) if allowed_to_change_status and status: diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -1385,6 +1385,7 @@ def lock(request, apiuser, repoid, locke def comment_commit( request, apiuser, repoid, commit_id, message, status=Optional(None), comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), + resolves_comment_id=Optional(None), userid=Optional(OAttr('apiuser'))): """ Set a commit comment, and optionally change the status of the commit. @@ -1431,12 +1432,24 @@ def comment_commit( user = get_user_or_error(userid) status = Optional.extract(status) comment_type = Optional.extract(comment_type) + resolves_comment_id = Optional.extract(resolves_comment_id) allowed_statuses = [x[0] for x in ChangesetStatus.STATUSES] if status and status not in allowed_statuses: raise JSONRPCError('Bad status, must be on ' 'of %s got %s' % (allowed_statuses, status,)) + if resolves_comment_id: + comment = ChangesetComment.get(resolves_comment_id) + if not comment: + raise JSONRPCError( + 'Invalid resolves_comment_id `%s` for this commit.' + % resolves_comment_id) + if comment.comment_type != ChangesetComment.COMMENT_TYPE_TODO: + raise JSONRPCError( + 'Comment `%s` is wrong type for setting status to resolved.' + % resolves_comment_id) + try: rc_config = SettingsModel().get_all_settings() renderer = rc_config.get('rhodecode_markup_renderer', 'rst') @@ -1446,7 +1459,8 @@ def comment_commit( status_change=status_change_label, status_change_type=status, renderer=renderer, - comment_type=comment_type + comment_type=comment_type, + resolves_comment_id=resolves_comment_id ) if status: # also do a status change