##// END OF EJS Templates
pull-request: force update pull-request in case of the target repo reference changes....
marcink -
r1595:c00c09dd default
parent child Browse files
Show More
@@ -584,6 +584,10 b' class PullRequestModel(BaseModel):'
584 584 source_ref_name = pull_request.source_ref_parts.name
585 585 source_ref_id = pull_request.source_ref_parts.commit_id
586 586
587 target_ref_type = pull_request.target_ref_parts.type
588 target_ref_name = pull_request.target_ref_parts.name
589 target_ref_id = pull_request.target_ref_parts.commit_id
590
587 591 if not self.has_valid_update_type(pull_request):
588 592 log.debug(
589 593 "Skipping update of pull request %s due to ref type: %s",
@@ -593,6 +597,7 b' class PullRequestModel(BaseModel):'
593 597 reason=UpdateFailureReason.WRONG_REF_TPYE,
594 598 old=pull_request, new=None, changes=None)
595 599
600 # source repo
596 601 source_repo = pull_request.source_repo.scm_instance()
597 602 try:
598 603 source_commit = source_repo.get_commit(commit_id=source_ref_name)
@@ -602,21 +607,40 b' class PullRequestModel(BaseModel):'
602 607 reason=UpdateFailureReason.MISSING_SOURCE_REF,
603 608 old=pull_request, new=None, changes=None)
604 609
605 if source_ref_id == source_commit.raw_id:
610 source_changed = source_ref_id != source_commit.raw_id
611
612 # target repo
613 target_repo = pull_request.target_repo.scm_instance()
614 try:
615 target_commit = target_repo.get_commit(commit_id=target_ref_name)
616 except CommitDoesNotExistError:
617 return UpdateResponse(
618 executed=False,
619 reason=UpdateFailureReason.MISSING_TARGET_REF,
620 old=pull_request, new=None, changes=None)
621 target_changed = target_ref_id != target_commit.raw_id
622
623 if not (source_changed or target_changed):
606 624 log.debug("Nothing changed in pull request %s", pull_request)
607 625 return UpdateResponse(
608 626 executed=False,
609 627 reason=UpdateFailureReason.NO_CHANGE,
610 628 old=pull_request, new=None, changes=None)
611 629
612 # Finally there is a need for an update
630 change_in_found = 'target repo' if target_changed else 'source repo'
631 log.debug('Updating pull request because of change in %s detected',
632 change_in_found)
633
634 # Finally there is a need for an update, in case of source change
635 # we create a new version, else just an update
636 if source_changed:
613 637 pull_request_version = self._create_version_from_snapshot(pull_request)
614 638 self._link_comments_to_version(pull_request_version)
615
616 target_ref_type = pull_request.target_ref_parts.type
617 target_ref_name = pull_request.target_ref_parts.name
618 target_ref_id = pull_request.target_ref_parts.commit_id
619 target_repo = pull_request.target_repo.scm_instance()
639 else:
640 ver = pull_request.versions[-1]
641 pull_request.pull_request_version_id = \
642 ver.pull_request_version_id if ver else None
643 pull_request_version = pull_request
620 644
621 645 try:
622 646 if target_ref_type in ('tag', 'branch', 'book'):
@@ -643,6 +667,7 b' class PullRequestModel(BaseModel):'
643 667 source_ref_type, source_ref_name, source_commit.raw_id)
644 668 pull_request.target_ref = '%s:%s:%s' % (
645 669 target_ref_type, target_ref_name, ancestor)
670
646 671 pull_request.revisions = [
647 672 commit.raw_id for commit in reversed(commit_ranges)]
648 673 pull_request.updated_on = datetime.datetime.now()
@@ -773,18 +773,19 b''
773 773 $('#update_pull_request').on('click', function(e){
774 774 $(this).attr('disabled', 'disabled');
775 775 $(this).addClass('disabled');
776 $(this).html(_gettext('saving...'));
776 $(this).html(_gettext('Saving...'));
777 777 updateReviewers(undefined, "${c.repo_name}", "${c.pull_request.pull_request_id}");
778 778 });
779 779
780 780 $('#update_commits').on('click', function(e){
781 781 var isDisabled = !$(e.currentTarget).attr('disabled');
782 $(e.currentTarget).attr('disabled', 'disabled');
783 $(e.currentTarget).addClass('disabled');
784 $(e.currentTarget).removeClass('btn-primary');
782 785 $(e.currentTarget).text(_gettext('Updating...'));
783 $(e.currentTarget).attr('disabled', 'disabled');
784 786 if(isDisabled){
785 787 updateCommits("${c.repo_name}", "${c.pull_request.pull_request_id}");
786 788 }
787
788 789 });
789 790 // fixing issue with caches on firefox
790 791 $('#update_commits').removeAttr("disabled");
General Comments 0
You need to be logged in to leave comments. Login now