Show More
@@ -573,7 +573,7 b' def comment_pull_request(' | |||
|
573 | 573 | @jsonrpc_method() |
|
574 | 574 | def create_pull_request( |
|
575 | 575 | request, apiuser, source_repo, target_repo, source_ref, target_ref, |
|
576 | title, description=Optional(''), reviewers=Optional(None)): | |
|
576 | title=Optional(''), description=Optional(''), reviewers=Optional(None)): | |
|
577 | 577 | """ |
|
578 | 578 | Creates a new pull request. |
|
579 | 579 | |
@@ -594,7 +594,7 b' def create_pull_request(' | |||
|
594 | 594 | :type source_ref: str |
|
595 | 595 | :param target_ref: Set the target ref name. |
|
596 | 596 | :type target_ref: str |
|
597 |
:param title: Set the pull request title |
|
|
597 | :param title: Optionally Set the pull request title, it's generated otherwise | |
|
598 | 598 | :type title: str |
|
599 | 599 | :param description: Set the pull request description. |
|
600 | 600 | :type description: Optional(str) |
@@ -615,26 +615,32 b' def create_pull_request(' | |||
|
615 | 615 | |
|
616 | 616 | full_source_ref = resolve_ref_or_error(source_ref, source_db_repo) |
|
617 | 617 | full_target_ref = resolve_ref_or_error(target_ref, target_db_repo) |
|
618 | ||
|
619 | source_scm = source_db_repo.scm_instance() | |
|
620 | target_scm = target_db_repo.scm_instance() | |
|
621 | ||
|
618 | 622 | source_commit = get_commit_or_error(full_source_ref, source_db_repo) |
|
619 | 623 | target_commit = get_commit_or_error(full_target_ref, target_db_repo) |
|
620 | source_scm = source_db_repo.scm_instance() | |
|
621 | target_scm = target_db_repo.scm_instance() | |
|
624 | ||
|
625 | ancestor = source_scm.get_common_ancestor( | |
|
626 | source_commit.raw_id, target_commit.raw_id, target_scm) | |
|
627 | if not ancestor: | |
|
628 | raise JSONRPCError('no common ancestor found') | |
|
629 | ||
|
630 | # recalculate target ref based on ancestor | |
|
631 | target_ref_type, target_ref_name, __ = full_target_ref.split(':') | |
|
632 | full_target_ref = ':'.join((target_ref_type, target_ref_name, ancestor)) | |
|
622 | 633 | |
|
623 | 634 | commit_ranges = target_scm.compare( |
|
624 | 635 | target_commit.raw_id, source_commit.raw_id, source_scm, |
|
625 | 636 | merge=True, pre_load=[]) |
|
626 | 637 | |
|
627 | ancestor = target_scm.get_common_ancestor( | |
|
628 | target_commit.raw_id, source_commit.raw_id, source_scm) | |
|
629 | ||
|
630 | 638 | if not commit_ranges: |
|
631 | 639 | raise JSONRPCError('no commits found') |
|
632 | 640 | |
|
633 | if not ancestor: | |
|
634 | raise JSONRPCError('no common ancestor found') | |
|
635 | ||
|
636 | 641 | reviewer_objects = Optional.extract(reviewers) or [] |
|
637 | 642 | |
|
643 | # serialize and validate passed in given reviewers | |
|
638 | 644 | if reviewer_objects: |
|
639 | 645 | schema = ReviewerListSchema() |
|
640 | 646 | try: |
@@ -647,36 +653,44 b' def create_pull_request(' | |||
|
647 | 653 | user = get_user_or_error(reviewer_object['username']) |
|
648 | 654 | reviewer_object['user_id'] = user.user_id |
|
649 | 655 | |
|
650 |
get_default_reviewers_data, |
|
|
656 | get_default_reviewers_data, validate_default_reviewers = \ | |
|
651 | 657 | PullRequestModel().get_reviewer_functions() |
|
652 | 658 | |
|
659 | # recalculate reviewers logic, to make sure we can validate this | |
|
653 | 660 | reviewer_rules = get_default_reviewers_data( |
|
654 | 661 | apiuser.get_instance(), source_db_repo, |
|
655 | 662 | source_commit, target_db_repo, target_commit) |
|
656 | 663 | |
|
657 | # specified rules are later re-validated, thus we can assume users will | |
|
658 | # eventually provide those that meet the reviewer criteria. | |
|
659 | if not reviewer_objects: | |
|
660 | reviewer_objects = reviewer_rules['reviewers'] | |
|
664 | # now MERGE our given with the calculated | |
|
665 | reviewer_objects = reviewer_rules['reviewers'] + reviewer_objects | |
|
661 | 666 | |
|
662 | 667 | try: |
|
663 |
reviewers = |
|
|
668 | reviewers = validate_default_reviewers( | |
|
664 | 669 | reviewer_objects, reviewer_rules) |
|
665 | 670 | except ValueError as e: |
|
666 | 671 | raise JSONRPCError('Reviewers Validation: {}'.format(e)) |
|
667 | 672 | |
|
668 | pull_request_model = PullRequestModel() | |
|
669 | pull_request = pull_request_model.create( | |
|
673 | title = Optional.extract(title) | |
|
674 | if not title: | |
|
675 | title_source_ref = source_ref.split(':', 2)[1] | |
|
676 | title = PullRequestModel().generate_pullrequest_title( | |
|
677 | source=source_repo, | |
|
678 | source_ref=title_source_ref, | |
|
679 | target=target_repo | |
|
680 | ) | |
|
681 | description = Optional.extract(description) | |
|
682 | ||
|
683 | pull_request = PullRequestModel().create( | |
|
670 | 684 | created_by=apiuser.user_id, |
|
671 | 685 | source_repo=source_repo, |
|
672 | 686 | source_ref=full_source_ref, |
|
673 | 687 | target_repo=target_repo, |
|
674 | 688 | target_ref=full_target_ref, |
|
675 | revisions=reversed( | |
|
676 | [commit.raw_id for commit in reversed(commit_ranges)]), | |
|
689 | revisions=[commit.raw_id for commit in reversed(commit_ranges)], | |
|
677 | 690 | reviewers=reviewers, |
|
678 | 691 | title=title, |
|
679 |
description= |
|
|
692 | description=description, | |
|
693 | reviewer_data=reviewer_rules, | |
|
680 | 694 | ) |
|
681 | 695 | |
|
682 | 696 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now