##// END OF EJS Templates
helpers: use a small compilation cache to not re-compile same patterns over and over.
helpers: use a small compilation cache to not re-compile same patterns over and over.

File last commit:

r4519:ea50ffa9 stable
r4791:ad737339 default
Show More
pull_request_api.py
1118 lines | 42.3 KiB | text/x-python | PythonLexer
/ rhodecode / api / views / pull_request_api.py
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2011-2020 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
pull-request: extended default reviewers functionality....
r1769 from rhodecode.api import jsonrpc_method, JSONRPCError, JSONRPCValidationError
project: added all source files and assets
r1 from rhodecode.api.utils import (
has_superadmin_permission, Optional, OAttr, get_repo_or_error,
get_pull_request_or_error, get_commit_or_error, get_user_or_error,
api: expose owner to create_pull_request API. Fixes #5537
r3474 validate_repo_permissions, resolve_ref_or_error, validate_set_owner_permissions)
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 from rhodecode.lib import channelstream
project: added all source files and assets
r1 from rhodecode.lib.auth import (HasRepoPermissionAnyApi)
from rhodecode.lib.base import vcs_operation_context
from rhodecode.lib.utils2 import str2bool
observers: code cleanups and fixed tests.
r4519 from rhodecode.lib.vcs.backends.base import unicode_to_reference
project: added all source files and assets
r1 from rhodecode.model.changeset_status import ChangesetStatusModel
comments: renamed ChangesetCommentsModel to CommentsModel to reflect what it actually does....
r1323 from rhodecode.model.comment import CommentsModel
observers: code cleanups and fixed tests.
r4519 from rhodecode.model.db import (
Session, ChangesetStatus, ChangesetComment, PullRequest, PullRequestReviewers)
pull-requests: unified merge checks....
r1335 from rhodecode.model.pull_request import PullRequestModel, MergeCheck
project: added all source files and assets
r1 from rhodecode.model.settings import SettingsModel
pull-request: extended default reviewers functionality....
r1769 from rhodecode.model.validation_schema import Invalid
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 from rhodecode.model.validation_schema.schemas.reviewer_schema import ReviewerListSchema
project: added all source files and assets
r1
log = logging.getLogger(__name__)
@jsonrpc_method()
pull-requests: make merge state default as False. This causes a lot of performance problems and should default to faster way
r3818 def get_pull_request(request, apiuser, pullrequestid, repoid=Optional(None),
merge_state=Optional(False)):
project: added all source files and assets
r1 """
Get a pull request based on the given ID.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 :param repoid: Optional, repository name or repository ID from where
the pull request was opened.
project: added all source files and assets
r1 :type repoid: str or int
:param pullrequestid: ID of the requested pull request.
:type pullrequestid: int
pull-requests: make merge state default as False. This causes a lot of performance problems and should default to faster way
r3818 :param merge_state: Optional calculate merge state for each repository.
This could result in longer time to fetch the data
:type merge_state: bool
project: added all source files and assets
r1
Example output:
.. code-block:: bash
"id": <id_given_in_input>,
"result":
{
"pull_request_id": "<pull_request_id>",
"url": "<url>",
"title": "<title>",
"description": "<description>",
"status" : "<status>",
"created_on": "<date_time_created>",
"updated_on": "<date_time_updated>",
dan
API: added pull-requests versions into returned API data...
r4197 "versions": "<number_or_versions_of_pr>",
project: added all source files and assets
r1 "commit_ids": [
...
"<commit_id>",
"<commit_id>",
...
],
"review_status": "<review_status>",
"mergeable": {
"status": "<bool>",
"message": "<message>",
},
"source": {
"clone_url": "<clone_url>",
"repository": "<repository_name>",
"reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
},
"target": {
"clone_url": "<clone_url>",
"repository": "<repository_name>",
"reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
},
Martin Bornhold
api: Include merge reference into API data of a PR.
r1054 "merge": {
Martin Bornhold
api: Add an entry for pr shadow repositories to api functions.
r893 "clone_url": "<clone_url>",
Martin Bornhold
api: Include merge reference into API data of a PR.
r1054 "reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
Martin Bornhold
api: Add an entry for pr shadow repositories to api functions.
r893 },
project: added all source files and assets
r1 "author": <user_obj>,
"reviewers": [
...
{
"user": "<user_obj>",
"review_status": "<review_status>",
}
...
]
},
"error": null
"""
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395
project: added all source files and assets
r1 pull_request = get_pull_request_or_error(pullrequestid)
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
pull-requests: introduce operation state for pull requests to prevent from...
r3371 if not PullRequestModel().check_user_read(pull_request, apiuser, api=True):
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 raise JSONRPCError('repository `%s` or pull request `%s` '
'does not exist' % (repoid, pullrequestid))
pull-requests: introduce operation state for pull requests to prevent from...
r3371
# NOTE(marcink): only calculate and return merge state if the pr state is 'created'
# otherwise we can lock the repo on calculation of merge state while update/merge
# is happening.
pull-requests: make merge state default as False. This causes a lot of performance problems and should default to faster way
r3818 pr_created = pull_request.pull_request_state == pull_request.STATE_CREATED
merge_state = Optional.extract(merge_state, binary=True) and pr_created
pull-requests: introduce operation state for pull requests to prevent from...
r3371 data = pull_request.get_api_data(with_merge_state=merge_state)
project: added all source files and assets
r1 return data
@jsonrpc_method()
api: pull-requests get_all now sortes the results and have a flag to show/hide merge result state
r3445 def get_pull_requests(request, apiuser, repoid, status=Optional('new'),
pull-requests: make merge state default as False. This causes a lot of performance problems and should default to faster way
r3818 merge_state=Optional(False)):
project: added all source files and assets
r1 """
Get all pull requests from the repository specified in `repoid`.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 :param repoid: Optional repository name or repository ID.
project: added all source files and assets
r1 :type repoid: str or int
:param status: Only return pull requests with the specified status.
Valid options are.
* ``new`` (default)
* ``open``
* ``closed``
:type status: str
api: pull-requests get_all now sortes the results and have a flag to show/hide merge result state
r3445 :param merge_state: Optional calculate merge state for each repository.
This could result in longer time to fetch the data
:type merge_state: bool
project: added all source files and assets
r1
Example output:
.. code-block:: bash
"id": <id_given_in_input>,
"result":
[
...
{
"pull_request_id": "<pull_request_id>",
"url": "<url>",
"title" : "<title>",
"description": "<description>",
"status": "<status>",
"created_on": "<date_time_created>",
"updated_on": "<date_time_updated>",
"commit_ids": [
...
"<commit_id>",
"<commit_id>",
...
],
"review_status": "<review_status>",
"mergeable": {
"status": "<bool>",
"message: "<message>",
},
"source": {
"clone_url": "<clone_url>",
"reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
},
"target": {
"clone_url": "<clone_url>",
"reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
},
Martin Bornhold
api: Include merge reference into API data of a PR.
r1054 "merge": {
Martin Bornhold
api: Add an entry for pr shadow repositories to api functions.
r893 "clone_url": "<clone_url>",
Martin Bornhold
api: Include merge reference into API data of a PR.
r1054 "reference":
{
"name": "<name>",
"type": "<type>",
"commit_id": "<commit_id>",
}
Martin Bornhold
api: Add an entry for pr shadow repositories to api functions.
r893 },
project: added all source files and assets
r1 "author": <user_obj>,
"reviewers": [
...
{
"user": "<user_obj>",
"review_status": "<review_status>",
}
...
]
}
...
],
"error": null
"""
repo = get_repo_or_error(repoid)
if not has_superadmin_permission(apiuser):
_perms = (
'repository.admin', 'repository.write', 'repository.read',)
api: refactor auth helpers to reflect the action they do....
r1150 validate_repo_permissions(apiuser, repoid, repo, _perms)
project: added all source files and assets
r1
status = Optional.extract(status)
api: pull-requests get_all now sortes the results and have a flag to show/hide merge result state
r3445 merge_state = Optional.extract(merge_state, binary=True)
pull_requests = PullRequestModel().get_all(repo, statuses=[status],
order_by='id', order_dir='desc')
data = [pr.get_api_data(with_merge_state=merge_state) for pr in pull_requests]
project: added all source files and assets
r1 return data
@jsonrpc_method()
pull-request-api: updated logic of closing a PR via API call....
r1792 def merge_pull_request(
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 request, apiuser, pullrequestid, repoid=Optional(None),
pull-request-api: updated logic of closing a PR via API call....
r1792 userid=Optional(OAttr('apiuser'))):
project: added all source files and assets
r1 """
Merge the pull request specified by `pullrequestid` into its target
repository.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 :param repoid: Optional, repository name or repository ID of the
project: added all source files and assets
r1 target repository to which the |pr| is to be merged.
:type repoid: str or int
:param pullrequestid: ID of the pull request which shall be merged.
:type pullrequestid: int
:param userid: Merge the pull request as this user.
:type userid: Optional(str or int)
Example output:
.. code-block:: bash
docs: update API documentation.
r1603 "id": <id_given_in_input>,
"result": {
api: expose merge message in the merge operation
r3458 "executed": "<bool>",
"failure_reason": "<int>",
"merge_status_message": "<str>",
"merge_commit_id": "<merge_commit_id>",
"possible": "<bool>",
Martin Bornhold
api: Add merge reference to merge_pull_request api call.
r1055 "merge_ref": {
"commit_id": "<commit_id>",
"type": "<type>",
"name": "<name>"
}
project: added all source files and assets
r1 },
docs: update API documentation.
r1603 "error": null
project: added all source files and assets
r1 """
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 pull_request = get_pull_request_or_error(pullrequestid)
if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
api: pull-requests, fixed invocation of merge as another user.
r3481 auth_user = apiuser
api: added edit comment api
r4429
project: added all source files and assets
r1 if not isinstance(userid, Optional):
api: added edit comment api
r4429 is_repo_admin = HasRepoPermissionAnyApi('repository.admin')(
user=apiuser, repo_name=repo.repo_name)
if has_superadmin_permission(apiuser) or is_repo_admin:
project: added all source files and assets
r1 apiuser = get_user_or_error(userid)
api: pull-requests, fixed invocation of merge as another user.
r3481 auth_user = apiuser.AuthUser()
project: added all source files and assets
r1 else:
raise JSONRPCError('userid is not the same as your user')
pull-requests: introduce operation state for pull requests to prevent from...
r3371 if pull_request.pull_request_state != PullRequest.STATE_CREATED:
raise JSONRPCError(
'Operation forbidden because pull request is in state {}, '
'only state {} is allowed.'.format(
pull_request.pull_request_state, PullRequest.STATE_CREATED))
with pull_request.set_state(PullRequest.STATE_UPDATING):
api: pull-requests, fixed invocation of merge as another user.
r3481 check = MergeCheck.validate(pull_request, auth_user=auth_user,
translator=request.translate)
pull-requests: unified merge checks....
r1335 merge_possible = not check.failed
if not merge_possible:
pull-requests: fixed translation of error messages via merge-api....
r1759 error_messages = []
for err_type, error_msg in check.errors:
error_msg = request.translate(error_msg)
error_messages.append(error_msg)
reasons = ','.join(error_messages)
project: added all source files and assets
r1 raise JSONRPCError(
pull-requests: unified merge checks....
r1335 'merge not possible for following reasons: {}'.format(reasons))
project: added all source files and assets
r1
target_repo = pull_request.target_repo
extras = vcs_operation_context(
request.environ, repo_name=target_repo.repo_name,
api: pull-requests, fixed invocation of merge as another user.
r3481 username=auth_user.username, action='push',
project: added all source files and assets
r1 scm=target_repo.repo_type)
pull-requests: introduce operation state for pull requests to prevent from...
r3371 with pull_request.set_state(PullRequest.STATE_UPDATING):
merge_response = PullRequestModel().merge_repo(
pull_request, apiuser, extras=extras)
Martin Bornhold
api: Add merge reference to merge_pull_request api call.
r1055 if merge_response.executed:
api: pull-requests, fixed invocation of merge as another user.
r3481 PullRequestModel().close_pull_request(pull_request.pull_request_id, auth_user)
project: added all source files and assets
r1
db: always use Session() for compatibility, Using Session is actually the...
r506 Session().commit()
Martin Bornhold
api: Add merge reference to merge_pull_request api call.
r1055
# In previous versions the merge response directly contained the merge
# commit id. It is now contained in the merge reference object. To be
# backwards compatible we have to extract it again.
dan
pull-requests: ensure merge response provide more details...
r3339 merge_response = merge_response.asdict()
Martin Bornhold
api: Add merge reference to merge_pull_request api call.
r1055 merge_response['merge_commit_id'] = merge_response['merge_ref'].commit_id
return merge_response
project: added all source files and assets
r1
@jsonrpc_method()
api: pull-requests added option to fetch comments from a pull requests....
r2394 def get_pull_request_comments(
request, apiuser, pullrequestid, repoid=Optional(None)):
"""
Get all comments of pull request specified with the `pullrequestid`
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
:param repoid: Optional repository name or repository ID.
:type repoid: str or int
:param pullrequestid: The pull request ID.
:type pullrequestid: int
Example output:
.. code-block:: bash
id : <id_given_in_input>
result : [
{
"comment_author": {
"active": true,
"full_name_or_username": "Tom Gore",
"username": "admin"
},
"comment_created_on": "2017-01-02T18:43:45.533",
"comment_f_path": null,
"comment_id": 25,
"comment_lineno": null,
"comment_status": {
"status": "under_review",
"status_lbl": "Under Review"
},
"comment_text": "Example text",
"comment_type": null,
api: added get_comment method, and return versions for comments to allow simple edits via API.
r4440 "comment_last_version: 0,
comments: extend API data with references to commit_id or pull_request_id for audit-logs.
r4304 "pull_request_version": null,
"comment_commit_id": None,
"comment_pull_request_id": <pull_request_id>
api: pull-requests added option to fetch comments from a pull requests....
r2394 }
],
error : null
"""
pull_request = get_pull_request_or_error(pullrequestid)
if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
if not PullRequestModel().check_user_read(
pull_request, apiuser, api=True):
raise JSONRPCError('repository `%s` or pull request `%s` '
'does not exist' % (repoid, pullrequestid))
(pull_request_latest,
pull_request_at_ver,
pull_request_display_obj,
at_version) = PullRequestModel().get_pr_version(
pull_request.pull_request_id, version=None)
versions = pull_request_display_obj.versions()
ver_map = {
ver.pull_request_version_id: cnt
for cnt, ver in enumerate(versions, 1)
}
# GENERAL COMMENTS with versions #
q = CommentsModel()._all_general_comments_of_pull_request(pull_request)
q = q.order_by(ChangesetComment.comment_id.asc())
general_comments = q.all()
# INLINE COMMENTS with versions #
q = CommentsModel()._all_inline_comments_of_pull_request(pull_request)
q = q.order_by(ChangesetComment.comment_id.asc())
inline_comments = q.all()
data = []
for comment in inline_comments + general_comments:
full_data = comment.get_api_data()
pr_version_id = None
if comment.pull_request_version_id:
pr_version_id = 'v{}'.format(
ver_map[comment.pull_request_version_id])
# sanitize some entries
full_data['pull_request_version'] = pr_version_id
full_data['comment_author'] = {
'username': full_data['comment_author'].username,
'full_name_or_username': full_data['comment_author'].full_name_or_username,
'active': full_data['comment_author'].active,
}
if full_data['comment_status']:
full_data['comment_status'] = {
'status': full_data['comment_status'][0].status,
'status_lbl': full_data['comment_status'][0].status_lbl,
}
else:
full_data['comment_status'] = {}
data.append(full_data)
return data
@jsonrpc_method()
api: added possibility to specify comment_type for comment API.
r1337 def comment_pull_request(
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 request, apiuser, pullrequestid, repoid=Optional(None),
message=Optional(None), commit_id=Optional(None), status=Optional(None),
api: added possibility to specify comment_type for comment API.
r1337 comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE),
api: allow extra recipients for pr/commit comments api methods...
r4049 resolves_comment_id=Optional(None), extra_recipients=Optional([]),
api: add send_email flag for comments api to allow commenting without email notification....
r4196 userid=Optional(OAttr('apiuser')), send_email=Optional(True)):
project: added all source files and assets
r1 """
Comment on the pull request specified with the `pullrequestid`,
in the |repo| specified by the `repoid`, and optionally change the
review status.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 :param repoid: Optional repository name or repository ID.
project: added all source files and assets
r1 :type repoid: str or int
:param pullrequestid: The pull request ID.
:type pullrequestid: int
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 :param commit_id: Specify the commit_id for which to set a comment. If
given commit_id is different than latest in the PR status
change won't be performed.
:type commit_id: str
api: added possibility to specify comment_type for comment API.
r1337 :param message: The text content of the comment.
:type message: str
:param status: (**Optional**) Set the approval status of the pull
request. One of: 'not_reviewed', 'approved', 'rejected',
'under_review'
:type status: str
:param comment_type: Comment type, one of: 'note', 'todo'
:type comment_type: Optional(str), default: 'note'
api: allow extra recipients for pr/commit comments api methods...
r4049 :param resolves_comment_id: id of comment which this one will resolve
:type resolves_comment_id: Optional(int)
:param extra_recipients: list of user ids or usernames to add
notifications for this comment. Acts like a CC for notification
:type extra_recipients: Optional(list)
project: added all source files and assets
r1 :param userid: Comment on the pull request as this user
:type userid: Optional(str or int)
api: add send_email flag for comments api to allow commenting without email notification....
r4196 :param send_email: Define if this comment should also send email notification
:type send_email: Optional(bool)
project: added all source files and assets
r1
Example output:
.. code-block:: bash
docs: update API documentation.
r1603 id : <id_given_in_input>
result : {
project: added all source files and assets
r1 "pull_request_id": "<Integer>",
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 "comment_id": "<Integer>",
"status": {"given": <given_status>,
"was_changed": <bool status_was_actually_changed> },
docs: update API documentation.
r1603 },
error : null
project: added all source files and assets
r1 """
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 _ = request.translate
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 pull_request = get_pull_request_or_error(pullrequestid)
if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 db_repo_name = repo.repo_name
api: pull-requests, fixed invocation of merge as another user.
r3481 auth_user = apiuser
project: added all source files and assets
r1 if not isinstance(userid, Optional):
api: added edit comment api
r4429 is_repo_admin = HasRepoPermissionAnyApi('repository.admin')(
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 user=apiuser, repo_name=db_repo_name)
api: added edit comment api
r4429 if has_superadmin_permission(apiuser) or is_repo_admin:
project: added all source files and assets
r1 apiuser = get_user_or_error(userid)
api: pull-requests, fixed invocation of merge as another user.
r3481 auth_user = apiuser.AuthUser()
project: added all source files and assets
r1 else:
raise JSONRPCError('userid is not the same as your user')
api: forbid commenting on closed PR
r3463 if pull_request.is_closed():
raise JSONRPCError(
'pull request `%s` comment failed, pull request is closed' % (
pullrequestid,))
project: added all source files and assets
r1 if not PullRequestModel().check_user_read(
pull_request, apiuser, api=True):
raise JSONRPCError('repository `%s` does not exist' % (repoid,))
message = Optional.extract(message)
status = Optional.extract(status)
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 commit_id = Optional.extract(commit_id)
api: added possibility to specify comment_type for comment API.
r1337 comment_type = Optional.extract(comment_type)
api: added comment_resolved_id into aprameters to resolve TODO notes via API.
r1338 resolves_comment_id = Optional.extract(resolves_comment_id)
api: allow extra recipients for pr/commit comments api methods...
r4049 extra_recipients = Optional.extract(extra_recipients)
api: add send_email flag for comments api to allow commenting without email notification....
r4196 send_email = Optional.extract(send_email, binary=True)
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269
project: added all source files and assets
r1 if not message and not status:
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 raise JSONRPCError(
'Both message and status parameters are missing. '
'At least one is required.')
project: added all source files and assets
r1
if (status not in (st[0] for st in ChangesetStatus.STATUSES) and
status is not None):
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 raise JSONRPCError('Unknown comment status: `%s`' % status)
if commit_id and commit_id not in pull_request.revisions:
raise JSONRPCError(
'Invalid commit_id `%s` for this pull request.' % commit_id)
project: added all source files and assets
r1
allowed_to_change_status = PullRequestModel().check_user_change_status(
pull_request, apiuser)
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269
# if commit_id is passed re-validated if user is allowed to change status
# based on latest commit_id from the PR
if commit_id:
commit_idx = pull_request.revisions.index(commit_id)
if commit_idx != 0:
allowed_to_change_status = False
api: added comment_resolved_id into aprameters to resolve TODO notes via API.
r1338 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)
project: added all source files and assets
r1 text = message
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 status_label = ChangesetStatus.get_status_lbl(status)
project: added all source files and assets
r1 if status and allowed_to_change_status:
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 st_message = ('Status change %(transition_icon)s %(status)s'
% {'transition_icon': '>', 'status': status_label})
project: added all source files and assets
r1 text = message or st_message
rc_config = SettingsModel().get_all_settings()
renderer = rc_config.get('rhodecode_markup_renderer', 'rst')
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269
status_change = status and allowed_to_change_status
comments: renamed ChangesetCommentsModel to CommentsModel to reflect what it actually does....
r1323 comment = CommentsModel().create(
project: added all source files and assets
r1 text=text,
repo=pull_request.target_repo.repo_id,
user=apiuser.user_id,
pull_request=pull_request.pull_request_id,
f_path=None,
line_no=None,
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 status_change=(status_label if status_change else None),
status_change_type=(status if status_change else None),
project: added all source files and assets
r1 closing_pr=False,
api: added possibility to specify comment_type for comment API.
r1337 renderer=renderer,
api: added comment_resolved_id into aprameters to resolve TODO notes via API.
r1338 comment_type=comment_type,
audit-logs: store properly IP and user for certain comments types....
r2728 resolves_comment_id=resolves_comment_id,
api: allow extra recipients for pr/commit comments api methods...
r4049 auth_user=auth_user,
api: add send_email flag for comments api to allow commenting without email notification....
r4196 extra_recipients=extra_recipients,
send_email=send_email
project: added all source files and assets
r1 )
observers: code cleanups and fixed tests.
r4519 is_inline = comment.is_inline
project: added all source files and assets
r1
if allowed_to_change_status and status:
api/pull-requests: trigger events for comments/review status changes.
r3416 old_calculated_status = pull_request.calculated_review_status()
project: added all source files and assets
r1 ChangesetStatusModel().set_status(
pull_request.target_repo.repo_id,
status,
apiuser.user_id,
comment,
pull_request=pull_request.pull_request_id
)
Session().flush()
Session().commit()
api/pull-requests: trigger events for comments/review status changes.
r3416
PullRequestModel().trigger_pull_request_hook(
pull_request, apiuser, 'comment',
data={'comment': comment})
if allowed_to_change_status and status:
# we now calculate the status of pull request, and based on that
# calculation we set the commits status
calculated_status = pull_request.calculated_review_status()
if old_calculated_status != calculated_status:
PullRequestModel().trigger_pull_request_hook(
pull_request, apiuser, 'review_status_change',
data={'status': calculated_status})
project: added all source files and assets
r1 data = {
'pull_request_id': pull_request.pull_request_id,
api: comment_pull_request, added commit_id parameter to validate status changed on particular commit....
r1269 'comment_id': comment.comment_id if comment else None,
'status': {'given': status, 'was_changed': status_change},
project: added all source files and assets
r1 }
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505
comment_broadcast_channel = channelstream.comment_channel(
db_repo_name, pull_request_obj=pull_request)
comment_data = data
comment_type = 'inline' if is_inline else 'general'
channelstream.comment_channelstream_push(
request, comment_broadcast_channel, apiuser,
_('posted a new {} comment').format(comment_type),
comment_data=comment_data)
project: added all source files and assets
r1 return data
observers: code cleanups and fixed tests.
r4519 def _reviewers_validation(obj_list):
schema = ReviewerListSchema()
try:
reviewer_objects = schema.deserialize(obj_list)
except Invalid as err:
raise JSONRPCValidationError(colander_exc=err)
# validate users
for reviewer_object in reviewer_objects:
user = get_user_or_error(reviewer_object['username'])
reviewer_object['user_id'] = user.user_id
return reviewer_objects
project: added all source files and assets
r1
@jsonrpc_method()
def create_pull_request(
request, apiuser, source_repo, target_repo, source_ref, target_ref,
api: expose owner to create_pull_request API. Fixes #5537
r3474 owner=Optional(OAttr('apiuser')), title=Optional(''), description=Optional(''),
observers: code cleanups and fixed tests.
r4519 description_renderer=Optional(''),
reviewers=Optional(None), observers=Optional(None)):
project: added all source files and assets
r1 """
Creates a new pull request.
Accepts refs in the following formats:
* branch:<branch_name>:<sha>
* branch:<branch_name>
* bookmark:<bookmark_name>:<sha> (Mercurial only)
* bookmark:<bookmark_name> (Mercurial only)
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
:param source_repo: Set the source repository name.
:type source_repo: str
:param target_repo: Set the target repository name.
:type target_repo: str
:param source_ref: Set the source ref name.
:type source_ref: str
:param target_ref: Set the target ref name.
:type target_ref: str
api: expose owner to create_pull_request API. Fixes #5537
r3474 :param owner: user_id or username
:type owner: Optional(str)
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 :param title: Optionally Set the pull request title, it's generated otherwise
project: added all source files and assets
r1 :type title: str
:param description: Set the pull request description.
:type description: Optional(str)
api: allow updates and setting description renderer for pull requests via the API.
r2904 :type description_renderer: Optional(str)
:param description_renderer: Set pull request renderer for the description.
It should be 'rst', 'markdown' or 'plain'. If not give default
system renderer will be used
project: added all source files and assets
r1 :param reviewers: Set the new pull request reviewers list.
dan
reviewers: added validation and default review rules via API calls....
r1795 Reviewer defined by review rules will be added automatically to the
defined list.
project: added all source files and assets
r1 :type reviewers: Optional(list)
dan
reviewers: store reviewer reasons to database, fixes #4238
r873 Accepts username strings or objects of the format:
docs: update API documentation.
r1603
dan
reviewers: added validation and default review rules via API calls....
r1795 [{'username': 'nick', 'reasons': ['original author'], 'mandatory': <bool>}]
observers: code cleanups and fixed tests.
r4519 :param observers: Set the new pull request observers list.
Reviewer defined by review rules will be added automatically to the
defined list. This feature is only available in RhodeCode EE
:type observers: Optional(list)
Accepts username strings or objects of the format:
[{'username': 'nick', 'reasons': ['original author']}]
project: added all source files and assets
r1 """
dan
reviewers: store reviewer reasons to database, fixes #4238
r873
api: pull-requests fixed logic of ancestor calculation and target ref calculation based on the web view.
r2873 source_db_repo = get_repo_or_error(source_repo)
dan
reviewers: added validation and default review rules via API calls....
r1795 target_db_repo = get_repo_or_error(target_repo)
project: added all source files and assets
r1 if not has_superadmin_permission(apiuser):
_perms = ('repository.admin', 'repository.write', 'repository.read',)
dan
reviewers: added validation and default review rules via API calls....
r1795 validate_repo_permissions(apiuser, source_repo, source_db_repo, _perms)
project: added all source files and assets
r1
api: expose owner to create_pull_request API. Fixes #5537
r3474 owner = validate_set_owner_permissions(apiuser, owner)
dan
reviewers: added validation and default review rules via API calls....
r1795 full_source_ref = resolve_ref_or_error(source_ref, source_db_repo)
full_target_ref = resolve_ref_or_error(target_ref, target_db_repo)
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859
observers: code cleanups and fixed tests.
r4519 get_commit_or_error(full_source_ref, source_db_repo)
get_commit_or_error(full_target_ref, target_db_repo)
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859
dan
reviewers: store reviewer reasons to database, fixes #4238
r873 reviewer_objects = Optional.extract(reviewers) or []
observers: code cleanups and fixed tests.
r4519 observer_objects = Optional.extract(observers) or []
dan
reviewers: added validation and default review rules via API calls....
r1795
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 # serialize and validate passed in given reviewers
pull-request: extended default reviewers functionality....
r1769 if reviewer_objects:
observers: code cleanups and fixed tests.
r4519 reviewer_objects = _reviewers_validation(reviewer_objects)
project: added all source files and assets
r1
observers: code cleanups and fixed tests.
r4519 if observer_objects:
observer_objects = _reviewers_validation(reviewer_objects)
dan
reviewers: added validation and default review rules via API calls....
r1795
reviewers: added observers as another way to define reviewers....
r4500 get_default_reviewers_data, validate_default_reviewers, validate_observers = \
dan
reviewers: added validation and default review rules via API calls....
r1795 PullRequestModel().get_reviewer_functions()
observers: code cleanups and fixed tests.
r4519 source_ref_obj = unicode_to_reference(full_source_ref)
target_ref_obj = unicode_to_reference(full_target_ref)
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 # recalculate reviewers logic, to make sure we can validate this
pull-requests: fix way how pull-request calculates common ancestors....
r4346 default_reviewers_data = get_default_reviewers_data(
reviewers: optimize diff data, and creation of PR with advanced default reviewers
r4510 owner,
observers: code cleanups and fixed tests.
r4519 source_db_repo,
source_ref_obj,
target_db_repo,
target_ref_obj,
reviewers: optimize diff data, and creation of PR with advanced default reviewers
r4510 )
dan
reviewers: added validation and default review rules via API calls....
r1795
observers: code cleanups and fixed tests.
r4519 # now MERGE our given with the calculated from the default rules
just_reviewers = [
x for x in default_reviewers_data['reviewers']
if x['role'] == PullRequestReviewers.ROLE_REVIEWER]
reviewer_objects = just_reviewers + reviewer_objects
dan
reviewers: added validation and default review rules via API calls....
r1795
try:
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 reviewers = validate_default_reviewers(
pull-requests: fix way how pull-request calculates common ancestors....
r4346 reviewer_objects, default_reviewers_data)
dan
reviewers: added validation and default review rules via API calls....
r1795 except ValueError as e:
raise JSONRPCError('Reviewers Validation: {}'.format(e))
project: added all source files and assets
r1
observers: code cleanups and fixed tests.
r4519 # now MERGE our given with the calculated from the default rules
just_observers = [
x for x in default_reviewers_data['reviewers']
if x['role'] == PullRequestReviewers.ROLE_OBSERVER]
observer_objects = just_observers + observer_objects
try:
observers = validate_observers(
observer_objects, default_reviewers_data)
except ValueError as e:
raise JSONRPCError('Observer Validation: {}'.format(e))
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 title = Optional.extract(title)
if not title:
observers: code cleanups and fixed tests.
r4519 title_source_ref = source_ref_obj.name
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 title = PullRequestModel().generate_pullrequest_title(
source=source_repo,
source_ref=title_source_ref,
target=target_repo
)
pull-requests: fix way how pull-request calculates common ancestors....
r4346
diff_info = default_reviewers_data['diff_info']
common_ancestor_id = diff_info['ancestor']
observers: code cleanups and fixed tests.
r4519 # NOTE(marcink): reversed is consistent with how we open it in the WEB interface
commits = [commit['commit_id'] for commit in reversed(diff_info['commits'])]
pull-requests: fix way how pull-request calculates common ancestors....
r4346
if not common_ancestor_id:
observers: code cleanups and fixed tests.
r4519 raise JSONRPCError('no common ancestor found between specified references')
pull-requests: fix way how pull-request calculates common ancestors....
r4346
if not commits:
observers: code cleanups and fixed tests.
r4519 raise JSONRPCError('no commits found for merge between specified references')
pull-requests: fix way how pull-request calculates common ancestors....
r4346
# recalculate target ref based on ancestor
observers: code cleanups and fixed tests.
r4519 full_target_ref = ':'.join((target_ref_obj.type, target_ref_obj.name, common_ancestor_id))
pull-requests: fix way how pull-request calculates common ancestors....
r4346
api: allow updates and setting description renderer for pull requests via the API.
r2904 # fetch renderer, if set fallback to plain in case of PR
rc_config = SettingsModel().get_all_settings()
default_system_renderer = rc_config.get('rhodecode_markup_renderer', 'plain')
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 description = Optional.extract(description)
api: allow updates and setting description renderer for pull requests via the API.
r2904 description_renderer = Optional.extract(description_renderer) or default_system_renderer
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859
pull_request = PullRequestModel().create(
api: expose owner to create_pull_request API. Fixes #5537
r3474 created_by=owner.user_id,
project: added all source files and assets
r1 source_repo=source_repo,
source_ref=full_source_ref,
target_repo=target_repo,
target_ref=full_target_ref,
pull-requests: fix way how pull-request calculates common ancestors....
r4346 common_ancestor_id=common_ancestor_id,
observers: code cleanups and fixed tests.
r4519 revisions=commits,
pull-request: extended default reviewers functionality....
r1769 reviewers=reviewers,
observers: code cleanups and fixed tests.
r4519 observers=observers,
project: added all source files and assets
r1 title=title,
api: fixed creation of pull request with custom rules of reviewers + proper diff creation.
r2859 description=description,
api: allow updates and setting description renderer for pull requests via the API.
r2904 description_renderer=description_renderer,
pull-requests: fix way how pull-request calculates common ancestors....
r4346 reviewer_data=default_reviewers_data,
audit-logs: use auth_user in few places to track action IP.
r2788 auth_user=apiuser
project: added all source files and assets
r1 )
Session().commit()
data = {
'msg': 'Created new pull request `{}`'.format(title),
'pull_request_id': pull_request.pull_request_id,
}
return data
@jsonrpc_method()
def update_pull_request(
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 request, apiuser, pullrequestid, repoid=Optional(None),
api: allow updates and setting description renderer for pull requests via the API.
r2904 title=Optional(''), description=Optional(''), description_renderer=Optional(''),
observers: code cleanups and fixed tests.
r4519 reviewers=Optional(None), observers=Optional(None), update_commits=Optional(None)):
project: added all source files and assets
r1 """
Updates a pull request.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 :param repoid: Optional repository name or repository ID.
project: added all source files and assets
r1 :type repoid: str or int
:param pullrequestid: The pull request ID.
:type pullrequestid: int
:param title: Set the pull request title.
:type title: str
:param description: Update pull request description.
:type description: Optional(str)
api: allow updates and setting description renderer for pull requests via the API.
r2904 :type description_renderer: Optional(str)
:param description_renderer: Update pull request renderer for the description.
It should be 'rst', 'markdown' or 'plain'
project: added all source files and assets
r1 :param reviewers: Update pull request reviewers list with new value.
:type reviewers: Optional(list)
pull-request: extended default reviewers functionality....
r1769 Accepts username strings or objects of the format:
dan
reviewers: added validation and default review rules via API calls....
r1795 [{'username': 'nick', 'reasons': ['original author'], 'mandatory': <bool>}]
observers: code cleanups and fixed tests.
r4519 :param observers: Update pull request observers list with new value.
:type observers: Optional(list)
Accepts username strings or objects of the format:
pull-request: extended default reviewers functionality....
r1769
observers: code cleanups and fixed tests.
r4519 [{'username': 'nick', 'reasons': ['should be aware about this PR']}]
project: added all source files and assets
r1 :param update_commits: Trigger update of commits for this pull request
:type: update_commits: Optional(bool)
Example output:
.. code-block:: bash
docs: update API documentation.
r1603 id : <id_given_in_input>
result : {
project: added all source files and assets
r1 "msg": "Updated pull request `63`",
"pull_request": <pull_request_object>,
"updated_reviewers": {
"added": [
"username"
],
"removed": []
},
observers: code cleanups and fixed tests.
r4519 "updated_observers": {
"added": [
"username"
],
"removed": []
},
project: added all source files and assets
r1 "updated_commits": {
"added": [
"<sha1_hash>"
],
"common": [
"<sha1_hash>",
"<sha1_hash>",
],
"removed": []
}
}
docs: update API documentation.
r1603 error : null
project: added all source files and assets
r1 """
pull_request = get_pull_request_or_error(pullrequestid)
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
project: added all source files and assets
r1 if not PullRequestModel().check_user_update(
pull_request, apiuser, api=True):
raise JSONRPCError(
'pull request `%s` update failed, no permission to update.' % (
pullrequestid,))
if pull_request.is_closed():
raise JSONRPCError(
'pull request `%s` update failed, pull request is closed' % (
pullrequestid,))
dan
reviewers: store reviewer reasons to database, fixes #4238
r873 reviewer_objects = Optional.extract(reviewers) or []
observers: code cleanups and fixed tests.
r4519 observer_objects = Optional.extract(observers) or []
project: added all source files and assets
r1
title = Optional.extract(title)
description = Optional.extract(description)
api: allow updates and setting description renderer for pull requests via the API.
r2904 description_renderer = Optional.extract(description_renderer)
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 # Update title/description
title_changed = False
project: added all source files and assets
r1 if title or description:
PullRequestModel().edit(
api: allow updates and setting description renderer for pull requests via the API.
r2904 pull_request,
title or pull_request.title,
description or pull_request.description,
description_renderer or pull_request.description_renderer,
apiuser)
project: added all source files and assets
r1 Session().commit()
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 title_changed = True
project: added all source files and assets
r1
commit_changes = {"added": [], "common": [], "removed": []}
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505
# Update commits
commits_changed = False
project: added all source files and assets
r1 if str2bool(Optional.extract(update_commits)):
pull-requests: introduce operation state for pull requests to prevent from...
r3371
if pull_request.pull_request_state != PullRequest.STATE_CREATED:
raise JSONRPCError(
'Operation forbidden because pull request is in state {}, '
'only state {} is allowed.'.format(
pull_request.pull_request_state, PullRequest.STATE_CREATED))
with pull_request.set_state(PullRequest.STATE_UPDATING):
if PullRequestModel().has_valid_update_type(pull_request):
pull-requests: added update pull-requests email+notifications...
r4120 db_user = apiuser.get_instance()
update_response = PullRequestModel().update_commits(
pull_request, db_user)
pull-requests: introduce operation state for pull requests to prevent from...
r3371 commit_changes = update_response.changes or commit_changes
Session().commit()
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 commits_changed = True
project: added all source files and assets
r1
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 # Update reviewers
observers: code cleanups and fixed tests.
r4519 # serialize and validate passed in given reviewers
if reviewer_objects:
reviewer_objects = _reviewers_validation(reviewer_objects)
if observer_objects:
observer_objects = _reviewers_validation(reviewer_objects)
# re-use stored rules
default_reviewers_data = pull_request.reviewer_data
__, validate_default_reviewers, validate_observers = \
PullRequestModel().get_reviewer_functions()
if reviewer_objects:
try:
reviewers = validate_default_reviewers(reviewer_objects, default_reviewers_data)
except ValueError as e:
raise JSONRPCError('Reviewers Validation: {}'.format(e))
else:
reviewers = []
if observer_objects:
try:
observers = validate_default_reviewers(reviewer_objects, default_reviewers_data)
except ValueError as e:
raise JSONRPCError('Observer Validation: {}'.format(e))
else:
observers = []
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 reviewers_changed = False
project: added all source files and assets
r1 reviewers_changes = {"added": [], "removed": []}
pull-request: extended default reviewers functionality....
r1769 if reviewers:
api/pull-requests: trigger events for comments/review status changes.
r3416 old_calculated_status = pull_request.calculated_review_status()
project: added all source files and assets
r1 added_reviewers, removed_reviewers = \
observers: code cleanups and fixed tests.
r4519 PullRequestModel().update_reviewers(pull_request, reviewers, apiuser.get_instance())
project: added all source files and assets
r1
reviewers_changes['added'] = sorted(
[get_user_or_error(n).username for n in added_reviewers])
reviewers_changes['removed'] = sorted(
[get_user_or_error(n).username for n in removed_reviewers])
Session().commit()
api/pull-requests: trigger events for comments/review status changes.
r3416 # trigger status changed if change in reviewers changes the status
calculated_status = pull_request.calculated_review_status()
if old_calculated_status != calculated_status:
PullRequestModel().trigger_pull_request_hook(
pull_request, apiuser, 'review_status_change',
data={'status': calculated_status})
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505 reviewers_changed = True
observers_changed = False
observers: code cleanups and fixed tests.
r4519 observers_changes = {"added": [], "removed": []}
if observers:
added_observers, removed_observers = \
PullRequestModel().update_observers(pull_request, observers, apiuser.get_instance())
observers_changes['added'] = sorted(
[get_user_or_error(n).username for n in added_observers])
observers_changes['removed'] = sorted(
[get_user_or_error(n).username for n in removed_observers])
Session().commit()
reviewers_changed = True
channelstream: cleanup, and re-organize code for posting comments/pr updated messages....
r4505
# push changed to channelstream
if commits_changed or reviewers_changed or observers_changed:
pr_broadcast_channel = channelstream.pr_channel(pull_request)
msg = 'Pull request was updated.'
channelstream.pr_update_channelstream_push(
request, pr_broadcast_channel, apiuser, msg)
api/pull-requests: trigger events for comments/review status changes.
r3416
project: added all source files and assets
r1 data = {
observers: code cleanups and fixed tests.
r4519 'msg': 'Updated pull request `{}`'.format(pull_request.pull_request_id),
project: added all source files and assets
r1 'pull_request': pull_request.get_api_data(),
'updated_commits': commit_changes,
observers: code cleanups and fixed tests.
r4519 'updated_reviewers': reviewers_changes,
'updated_observers': observers_changes,
project: added all source files and assets
r1 }
Martin Bornhold
tests: Adapt tests to return value change.
r1077
project: added all source files and assets
r1 return data
pull-request-api: updated logic of closing a PR via API call....
r1792
@jsonrpc_method()
def close_pull_request(
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 request, apiuser, pullrequestid, repoid=Optional(None),
pull-request-api: updated logic of closing a PR via API call....
r1792 userid=Optional(OAttr('apiuser')), message=Optional('')):
"""
Close the pull request specified by `pullrequestid`.
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
:param repoid: Repository name or repository ID to which the pull
request belongs.
:type repoid: str or int
:param pullrequestid: ID of the pull request to be closed.
:type pullrequestid: int
:param userid: Close the pull request as this user.
:type userid: Optional(str or int)
:param message: Optional message to close the Pull Request with. If not
specified it will be generated automatically.
:type message: Optional(str)
Example output:
.. code-block:: bash
"id": <id_given_in_input>,
"result": {
"pull_request_id": "<int>",
"close_status": "<str:status_lbl>,
"closed": "<bool>"
},
"error": null
"""
_ = request.translate
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 pull_request = get_pull_request_or_error(pullrequestid)
if Optional.extract(repoid):
repo = get_repo_or_error(repoid)
else:
repo = pull_request.target_repo
api: added edit comment api
r4429 is_repo_admin = HasRepoPermissionAnyApi('repository.admin')(
user=apiuser, repo_name=repo.repo_name)
pull-request-api: updated logic of closing a PR via API call....
r1792 if not isinstance(userid, Optional):
api: added edit comment api
r4429 if has_superadmin_permission(apiuser) or is_repo_admin:
pull-request-api: updated logic of closing a PR via API call....
r1792 apiuser = get_user_or_error(userid)
else:
raise JSONRPCError('userid is not the same as your user')
if pull_request.is_closed():
raise JSONRPCError(
'pull request `%s` is already closed' % (pullrequestid,))
# only owner or admin or person with write permissions
allowed_to_close = PullRequestModel().check_user_update(
pull_request, apiuser, api=True)
if not allowed_to_close:
raise JSONRPCError(
'pull request `%s` close failed, no permission to close.' % (
pullrequestid,))
# message we're using to close the PR, else it's automatically generated
message = Optional.extract(message)
# finally close the PR, with proper message comment
comment, status = PullRequestModel().close_pull_request_with_comment(
comments: use proper auth user for close PR action.
r3027 pull_request, apiuser, repo, message=message, auth_user=apiuser)
pull-request-api: updated logic of closing a PR via API call....
r1792 status_lbl = ChangesetStatus.get_status_lbl(status)
Session().commit()
data = {
'pull_request_id': pull_request.pull_request_id,
'close_status': status_lbl,
'closed': True,
}
return data