api: pull-requests fixed logic of ancestor calculation and target ref calculation based on the web view.
This commit is contained in:
parent
f7081008c5
commit
239874ceca
2 changed files with 31 additions and 10 deletions
|
|
@ -93,6 +93,20 @@ class TestCreatePullRequestApi(object):
|
|||
pull_request = PullRequestModel().get(pull_request_id)
|
||||
assert pull_request.description == ''
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_create_with_empty_title(self, backend):
|
||||
data = self._prepare_data(backend)
|
||||
data.pop('title')
|
||||
id_, params = build_data(
|
||||
self.apikey_regular, 'create_pull_request', **data)
|
||||
response = api_call(self.app, params)
|
||||
result = response.json
|
||||
pull_request_id = result['result']['pull_request_id']
|
||||
pull_request = PullRequestModel().get(pull_request_id)
|
||||
data['ref'] = backend.default_branch_name
|
||||
title = '{source_repo}#{ref} to {target_repo}'.format(**data)
|
||||
assert pull_request.title == title
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_create_with_reviewers_specified_by_names(
|
||||
self, backend, no_notifications):
|
||||
|
|
@ -277,6 +291,7 @@ class TestCreatePullRequestApi(object):
|
|||
self.commit_ids = backend.create_master_repo(commits)
|
||||
self.source = backend.create_repo(heads=[source_head])
|
||||
self.target = backend.create_repo(heads=[target_head])
|
||||
|
||||
data = {
|
||||
'source_repo': self.source.repo_name,
|
||||
'target_repo': self.target.repo_name,
|
||||
|
|
|
|||
|
|
@ -608,7 +608,7 @@ def create_pull_request(
|
|||
[{'username': 'nick', 'reasons': ['original author'], 'mandatory': <bool>}]
|
||||
"""
|
||||
|
||||
source_db_repo = get_repo_or_error(source_repo)
|
||||
source_db_repo = get_repo_or_error(source_repo)
|
||||
target_db_repo = get_repo_or_error(target_repo)
|
||||
if not has_superadmin_permission(apiuser):
|
||||
_perms = ('repository.admin', 'repository.write', 'repository.read',)
|
||||
|
|
@ -616,24 +616,29 @@ def create_pull_request(
|
|||
|
||||
full_source_ref = resolve_ref_or_error(source_ref, source_db_repo)
|
||||
full_target_ref = resolve_ref_or_error(target_ref, target_db_repo)
|
||||
source_commit = get_commit_or_error(full_source_ref, source_db_repo)
|
||||
target_commit = get_commit_or_error(full_target_ref, target_db_repo)
|
||||
|
||||
source_scm = source_db_repo.scm_instance()
|
||||
target_scm = target_db_repo.scm_instance()
|
||||
|
||||
source_commit = get_commit_or_error(full_source_ref, source_db_repo)
|
||||
target_commit = get_commit_or_error(full_target_ref, target_db_repo)
|
||||
|
||||
ancestor = source_scm.get_common_ancestor(
|
||||
source_commit.raw_id, target_commit.raw_id, target_scm)
|
||||
if not ancestor:
|
||||
raise JSONRPCError('no common ancestor found')
|
||||
|
||||
# recalculate target ref based on ancestor
|
||||
target_ref_type, target_ref_name, __ = full_target_ref.split(':')
|
||||
full_target_ref = ':'.join((target_ref_type, target_ref_name, ancestor))
|
||||
|
||||
commit_ranges = target_scm.compare(
|
||||
target_commit.raw_id, source_commit.raw_id, source_scm,
|
||||
merge=True, pre_load=[])
|
||||
|
||||
ancestor = target_scm.get_common_ancestor(
|
||||
target_commit.raw_id, source_commit.raw_id, source_scm)
|
||||
|
||||
if not commit_ranges:
|
||||
raise JSONRPCError('no commits found')
|
||||
|
||||
if not ancestor:
|
||||
raise JSONRPCError('no common ancestor found')
|
||||
|
||||
reviewer_objects = Optional.extract(reviewers) or []
|
||||
|
||||
if reviewer_objects:
|
||||
|
|
@ -674,6 +679,7 @@ def create_pull_request(
|
|||
source_ref=title_source_ref,
|
||||
target=target_repo
|
||||
)
|
||||
description = Optional.extract(description)
|
||||
|
||||
pull_request = PullRequestModel().create(
|
||||
created_by=apiuser.user_id,
|
||||
|
|
@ -684,7 +690,7 @@ def create_pull_request(
|
|||
revisions=[commit.raw_id for commit in reversed(commit_ranges)],
|
||||
reviewers=reviewers,
|
||||
title=title,
|
||||
description=Optional.extract(description),
|
||||
description=description,
|
||||
reviewer_data=reviewer_rules,
|
||||
auth_user=apiuser
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue