##// 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 source_ref_name = pull_request.source_ref_parts.name
584 source_ref_name = pull_request.source_ref_parts.name
585 source_ref_id = pull_request.source_ref_parts.commit_id
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 if not self.has_valid_update_type(pull_request):
591 if not self.has_valid_update_type(pull_request):
588 log.debug(
592 log.debug(
589 "Skipping update of pull request %s due to ref type: %s",
593 "Skipping update of pull request %s due to ref type: %s",
@@ -593,6 +597,7 b' class PullRequestModel(BaseModel):'
593 reason=UpdateFailureReason.WRONG_REF_TPYE,
597 reason=UpdateFailureReason.WRONG_REF_TPYE,
594 old=pull_request, new=None, changes=None)
598 old=pull_request, new=None, changes=None)
595
599
600 # source repo
596 source_repo = pull_request.source_repo.scm_instance()
601 source_repo = pull_request.source_repo.scm_instance()
597 try:
602 try:
598 source_commit = source_repo.get_commit(commit_id=source_ref_name)
603 source_commit = source_repo.get_commit(commit_id=source_ref_name)
@@ -602,21 +607,40 b' class PullRequestModel(BaseModel):'
602 reason=UpdateFailureReason.MISSING_SOURCE_REF,
607 reason=UpdateFailureReason.MISSING_SOURCE_REF,
603 old=pull_request, new=None, changes=None)
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 log.debug("Nothing changed in pull request %s", pull_request)
624 log.debug("Nothing changed in pull request %s", pull_request)
607 return UpdateResponse(
625 return UpdateResponse(
608 executed=False,
626 executed=False,
609 reason=UpdateFailureReason.NO_CHANGE,
627 reason=UpdateFailureReason.NO_CHANGE,
610 old=pull_request, new=None, changes=None)
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 pull_request_version = self._create_version_from_snapshot(pull_request)
637 pull_request_version = self._create_version_from_snapshot(pull_request)
614 self._link_comments_to_version(pull_request_version)
638 self._link_comments_to_version(pull_request_version)
615
639 else:
616 target_ref_type = pull_request.target_ref_parts.type
640 ver = pull_request.versions[-1]
617 target_ref_name = pull_request.target_ref_parts.name
641 pull_request.pull_request_version_id = \
618 target_ref_id = pull_request.target_ref_parts.commit_id
642 ver.pull_request_version_id if ver else None
619 target_repo = pull_request.target_repo.scm_instance()
643 pull_request_version = pull_request
620
644
621 try:
645 try:
622 if target_ref_type in ('tag', 'branch', 'book'):
646 if target_ref_type in ('tag', 'branch', 'book'):
@@ -643,6 +667,7 b' class PullRequestModel(BaseModel):'
643 source_ref_type, source_ref_name, source_commit.raw_id)
667 source_ref_type, source_ref_name, source_commit.raw_id)
644 pull_request.target_ref = '%s:%s:%s' % (
668 pull_request.target_ref = '%s:%s:%s' % (
645 target_ref_type, target_ref_name, ancestor)
669 target_ref_type, target_ref_name, ancestor)
670
646 pull_request.revisions = [
671 pull_request.revisions = [
647 commit.raw_id for commit in reversed(commit_ranges)]
672 commit.raw_id for commit in reversed(commit_ranges)]
648 pull_request.updated_on = datetime.datetime.now()
673 pull_request.updated_on = datetime.datetime.now()
@@ -773,18 +773,19 b''
773 $('#update_pull_request').on('click', function(e){
773 $('#update_pull_request').on('click', function(e){
774 $(this).attr('disabled', 'disabled');
774 $(this).attr('disabled', 'disabled');
775 $(this).addClass('disabled');
775 $(this).addClass('disabled');
776 $(this).html(_gettext('saving...'));
776 $(this).html(_gettext('Saving...'));
777 updateReviewers(undefined, "${c.repo_name}", "${c.pull_request.pull_request_id}");
777 updateReviewers(undefined, "${c.repo_name}", "${c.pull_request.pull_request_id}");
778 });
778 });
779
779
780 $('#update_commits').on('click', function(e){
780 $('#update_commits').on('click', function(e){
781 var isDisabled = !$(e.currentTarget).attr('disabled');
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 $(e.currentTarget).text(_gettext('Updating...'));
785 $(e.currentTarget).text(_gettext('Updating...'));
783 $(e.currentTarget).attr('disabled', 'disabled');
784 if(isDisabled){
786 if(isDisabled){
785 updateCommits("${c.repo_name}", "${c.pull_request.pull_request_id}");
787 updateCommits("${c.repo_name}", "${c.pull_request.pull_request_id}");
786 }
788 }
787
788 });
789 });
789 // fixing issue with caches on firefox
790 // fixing issue with caches on firefox
790 $('#update_commits').removeAttr("disabled");
791 $('#update_commits').removeAttr("disabled");
General Comments 0
You need to be logged in to leave comments. Login now