##// END OF EJS Templates
api: pull-requests fixed logic of ancestor calculation and target ref calculation based on the web view.
marcink -
r2873:d22eab3d default
parent child Browse files
Show More
@@ -94,6 +94,20 b' class TestCreatePullRequestApi(object):'
94 94 assert pull_request.description == ''
95 95
96 96 @pytest.mark.backends("git", "hg")
97 def test_create_with_empty_title(self, backend):
98 data = self._prepare_data(backend)
99 data.pop('title')
100 id_, params = build_data(
101 self.apikey_regular, 'create_pull_request', **data)
102 response = api_call(self.app, params)
103 result = response.json
104 pull_request_id = result['result']['pull_request_id']
105 pull_request = PullRequestModel().get(pull_request_id)
106 data['ref'] = backend.default_branch_name
107 title = '{source_repo}#{ref} to {target_repo}'.format(**data)
108 assert pull_request.title == title
109
110 @pytest.mark.backends("git", "hg")
97 111 def test_create_with_reviewers_specified_by_names(
98 112 self, backend, no_notifications):
99 113 data = self._prepare_data(backend)
@@ -277,6 +291,7 b' class TestCreatePullRequestApi(object):'
277 291 self.commit_ids = backend.create_master_repo(commits)
278 292 self.source = backend.create_repo(heads=[source_head])
279 293 self.target = backend.create_repo(heads=[target_head])
294
280 295 data = {
281 296 'source_repo': self.source.repo_name,
282 297 'target_repo': self.target.repo_name,
@@ -616,24 +616,29 b' def create_pull_request('
616 616
617 617 full_source_ref = resolve_ref_or_error(source_ref, source_db_repo)
618 618 full_target_ref = resolve_ref_or_error(target_ref, target_db_repo)
619
620 source_scm = source_db_repo.scm_instance()
621 target_scm = target_db_repo.scm_instance()
622
619 623 source_commit = get_commit_or_error(full_source_ref, source_db_repo)
620 624 target_commit = get_commit_or_error(full_target_ref, target_db_repo)
621 source_scm = source_db_repo.scm_instance()
622 target_scm = target_db_repo.scm_instance()
625
626 ancestor = source_scm.get_common_ancestor(
627 source_commit.raw_id, target_commit.raw_id, target_scm)
628 if not ancestor:
629 raise JSONRPCError('no common ancestor found')
630
631 # recalculate target ref based on ancestor
632 target_ref_type, target_ref_name, __ = full_target_ref.split(':')
633 full_target_ref = ':'.join((target_ref_type, target_ref_name, ancestor))
623 634
624 635 commit_ranges = target_scm.compare(
625 636 target_commit.raw_id, source_commit.raw_id, source_scm,
626 637 merge=True, pre_load=[])
627 638
628 ancestor = target_scm.get_common_ancestor(
629 target_commit.raw_id, source_commit.raw_id, source_scm)
630
631 639 if not commit_ranges:
632 640 raise JSONRPCError('no commits found')
633 641
634 if not ancestor:
635 raise JSONRPCError('no common ancestor found')
636
637 642 reviewer_objects = Optional.extract(reviewers) or []
638 643
639 644 if reviewer_objects:
@@ -674,6 +679,7 b' def create_pull_request('
674 679 source_ref=title_source_ref,
675 680 target=target_repo
676 681 )
682 description = Optional.extract(description)
677 683
678 684 pull_request = PullRequestModel().create(
679 685 created_by=apiuser.user_id,
@@ -684,7 +690,7 b' def create_pull_request('
684 690 revisions=[commit.raw_id for commit in reversed(commit_ranges)],
685 691 reviewers=reviewers,
686 692 title=title,
687 description=Optional.extract(description),
693 description=description,
688 694 reviewer_data=reviewer_rules,
689 695 auth_user=apiuser
690 696 )
General Comments 0
You need to be logged in to leave comments. Login now