##// END OF EJS Templates
pull-requests: change the update commits logic to handle target changes better....
marcink -
r1601:a639657c default
parent child Browse files
Show More
@@ -442,13 +442,25 b' class PullrequestsController(BaseRepoCon'
442 442 resp = PullRequestModel().update_commits(pull_request)
443 443
444 444 if resp.executed:
445
446 if resp.target_changed and resp.source_changed:
447 changed = 'target and source repositories'
448 elif resp.target_changed and not resp.source_changed:
449 changed = 'target repository'
450 elif not resp.target_changed and resp.source_changed:
451 changed = 'source repository'
452 else:
453 changed = 'nothing'
454
445 455 msg = _(
446 456 u'Pull request updated to "{source_commit_id}" with '
447 u'{count_added} added, {count_removed} removed commits.')
457 u'{count_added} added, {count_removed} removed commits. '
458 u'Source of changes: {change_source}')
448 459 msg = msg.format(
449 460 source_commit_id=pull_request.source_ref_parts.commit_id,
450 461 count_added=len(resp.changes.added),
451 count_removed=len(resp.changes.removed))
462 count_removed=len(resp.changes.removed),
463 change_source=changed)
452 464 h.flash(msg, category='success')
453 465
454 466 registry = get_current_registry()
@@ -63,8 +63,9 b' log = logging.getLogger(__name__)'
63 63
64 64 # Data structure to hold the response data when updating commits during a pull
65 65 # request update.
66 UpdateResponse = namedtuple(
67 'UpdateResponse', 'executed, reason, new, old, changes')
66 UpdateResponse = namedtuple('UpdateResponse', [
67 'executed', 'reason', 'new', 'old', 'changes',
68 'source_changed', 'target_changed'])
68 69
69 70
70 71 class PullRequestModel(BaseModel):
@@ -116,8 +117,7 b' class PullRequestModel(BaseModel):'
116 117 UpdateFailureReason.UNKNOWN: lazy_ugettext(
117 118 'Pull request update failed because of an unknown error.'),
118 119 UpdateFailureReason.NO_CHANGE: lazy_ugettext(
119 'No update needed because the source reference is already '
120 'up to date.'),
120 'No update needed because the source and target have not changed.'),
121 121 UpdateFailureReason.WRONG_REF_TPYE: lazy_ugettext(
122 122 'Pull request cannot be updated because the reference type is '
123 123 'not supported for an update.'),
@@ -595,7 +595,8 b' class PullRequestModel(BaseModel):'
595 595 return UpdateResponse(
596 596 executed=False,
597 597 reason=UpdateFailureReason.WRONG_REF_TPYE,
598 old=pull_request, new=None, changes=None)
598 old=pull_request, new=None, changes=None,
599 source_changed=False, target_changed=False)
599 600
600 601 # source repo
601 602 source_repo = pull_request.source_repo.scm_instance()
@@ -605,7 +606,8 b' class PullRequestModel(BaseModel):'
605 606 return UpdateResponse(
606 607 executed=False,
607 608 reason=UpdateFailureReason.MISSING_SOURCE_REF,
608 old=pull_request, new=None, changes=None)
609 old=pull_request, new=None, changes=None,
610 source_changed=False, target_changed=False)
609 611
610 612 source_changed = source_ref_id != source_commit.raw_id
611 613
@@ -617,7 +619,8 b' class PullRequestModel(BaseModel):'
617 619 return UpdateResponse(
618 620 executed=False,
619 621 reason=UpdateFailureReason.MISSING_TARGET_REF,
620 old=pull_request, new=None, changes=None)
622 old=pull_request, new=None, changes=None,
623 source_changed=False, target_changed=False)
621 624 target_changed = target_ref_id != target_commit.raw_id
622 625
623 626 if not (source_changed or target_changed):
@@ -625,7 +628,8 b' class PullRequestModel(BaseModel):'
625 628 return UpdateResponse(
626 629 executed=False,
627 630 reason=UpdateFailureReason.NO_CHANGE,
628 old=pull_request, new=None, changes=None)
631 old=pull_request, new=None, changes=None,
632 source_changed=target_changed, target_changed=source_changed)
629 633
630 634 change_in_found = 'target repo' if target_changed else 'source repo'
631 635 log.debug('Updating pull request because of change in %s detected',
@@ -655,7 +659,8 b' class PullRequestModel(BaseModel):'
655 659 return UpdateResponse(
656 660 executed=False,
657 661 reason=UpdateFailureReason.MISSING_TARGET_REF,
658 old=pull_request, new=None, changes=None)
662 old=pull_request, new=None, changes=None,
663 source_changed=source_changed, target_changed=target_changed)
659 664
660 665 # re-compute commit ids
661 666 old_commit_ids = pull_request.revisions
@@ -678,20 +683,28 b' class PullRequestModel(BaseModel):'
678 683 Session().add(pull_request)
679 684 new_commit_ids = pull_request.revisions
680 685
681 changes = self._calculate_commit_id_changes(
682 old_commit_ids, new_commit_ids)
683
684 686 old_diff_data, new_diff_data = self._generate_update_diffs(
685 687 pull_request, pull_request_version)
686 688
689 # calculate commit and file changes
690 changes = self._calculate_commit_id_changes(
691 old_commit_ids, new_commit_ids)
692 file_changes = self._calculate_file_changes(
693 old_diff_data, new_diff_data)
694
695 # set comments as outdated if DIFFS changed
687 696 CommentsModel().outdate_comments(
688 697 pull_request, old_diff_data=old_diff_data,
689 698 new_diff_data=new_diff_data)
690 699
691 file_changes = self._calculate_file_changes(
692 old_diff_data, new_diff_data)
700 commit_changes = (changes.added or changes.removed)
701 file_node_changes = (
702 file_changes.added or file_changes.modified or file_changes.removed)
703 pr_has_changes = commit_changes or file_node_changes
693 704
694 # Add an automatic comment to the pull request
705 # Add an automatic comment to the pull request, in case
706 # anything has changed
707 if pr_has_changes:
695 708 update_comment = CommentsModel().create(
696 709 text=self._render_update_message(changes, file_changes),
697 710 repo=pull_request.target_repo,
@@ -713,7 +726,8 b' class PullRequestModel(BaseModel):'
713 726 'Updated pull request %s, added_ids: %s, common_ids: %s, '
714 727 'removed_ids: %s', pull_request.pull_request_id,
715 728 changes.added, changes.common, changes.removed)
716 log.debug('Updated pull request with the following file changes: %s',
729 log.debug(
730 'Updated pull request with the following file changes: %s',
717 731 file_changes)
718 732
719 733 log.info(
@@ -723,12 +737,13 b' class PullRequestModel(BaseModel):'
723 737 pull_request.source_ref_parts.commit_id,
724 738 pull_request_version.pull_request_version_id)
725 739 Session().commit()
726 self._trigger_pull_request_hook(pull_request, pull_request.author,
727 'update')
740 self._trigger_pull_request_hook(
741 pull_request, pull_request.author, 'update')
728 742
729 743 return UpdateResponse(
730 744 executed=True, reason=UpdateFailureReason.NONE,
731 old=pull_request, new=pull_request_version, changes=changes)
745 old=pull_request, new=pull_request_version, changes=changes,
746 source_changed=source_changed, target_changed=target_changed)
732 747
733 748 def _create_version_from_snapshot(self, pull_request):
734 749 version = PullRequestVersion()
General Comments 0
You need to be logged in to leave comments. Login now