Show More
@@ -442,13 +442,25 b' class PullrequestsController(BaseRepoCon' | |||||
442 | resp = PullRequestModel().update_commits(pull_request) |
|
442 | resp = PullRequestModel().update_commits(pull_request) | |
443 |
|
443 | |||
444 | if resp.executed: |
|
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 | msg = _( |
|
455 | msg = _( | |
446 | u'Pull request updated to "{source_commit_id}" with ' |
|
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 | msg = msg.format( |
|
459 | msg = msg.format( | |
449 | source_commit_id=pull_request.source_ref_parts.commit_id, |
|
460 | source_commit_id=pull_request.source_ref_parts.commit_id, | |
450 | count_added=len(resp.changes.added), |
|
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 | h.flash(msg, category='success') |
|
464 | h.flash(msg, category='success') | |
453 |
|
465 | |||
454 | registry = get_current_registry() |
|
466 | registry = get_current_registry() |
@@ -63,8 +63,9 b' log = logging.getLogger(__name__)' | |||||
63 |
|
63 | |||
64 | # Data structure to hold the response data when updating commits during a pull |
|
64 | # Data structure to hold the response data when updating commits during a pull | |
65 | # request update. |
|
65 | # request update. | |
66 | UpdateResponse = namedtuple( |
|
66 | UpdateResponse = namedtuple('UpdateResponse', [ | |
67 |
' |
|
67 | 'executed', 'reason', 'new', 'old', 'changes', | |
|
68 | 'source_changed', 'target_changed']) | |||
68 |
|
69 | |||
69 |
|
70 | |||
70 | class PullRequestModel(BaseModel): |
|
71 | class PullRequestModel(BaseModel): | |
@@ -116,8 +117,7 b' class PullRequestModel(BaseModel):' | |||||
116 | UpdateFailureReason.UNKNOWN: lazy_ugettext( |
|
117 | UpdateFailureReason.UNKNOWN: lazy_ugettext( | |
117 | 'Pull request update failed because of an unknown error.'), |
|
118 | 'Pull request update failed because of an unknown error.'), | |
118 | UpdateFailureReason.NO_CHANGE: lazy_ugettext( |
|
119 | UpdateFailureReason.NO_CHANGE: lazy_ugettext( | |
119 |
'No update needed because the source |
|
120 | 'No update needed because the source and target have not changed.'), | |
120 | 'up to date.'), |
|
|||
121 | UpdateFailureReason.WRONG_REF_TPYE: lazy_ugettext( |
|
121 | UpdateFailureReason.WRONG_REF_TPYE: lazy_ugettext( | |
122 | 'Pull request cannot be updated because the reference type is ' |
|
122 | 'Pull request cannot be updated because the reference type is ' | |
123 | 'not supported for an update.'), |
|
123 | 'not supported for an update.'), | |
@@ -595,7 +595,8 b' class PullRequestModel(BaseModel):' | |||||
595 | return UpdateResponse( |
|
595 | return UpdateResponse( | |
596 | executed=False, |
|
596 | executed=False, | |
597 | reason=UpdateFailureReason.WRONG_REF_TPYE, |
|
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 | # source repo |
|
601 | # source repo | |
601 | source_repo = pull_request.source_repo.scm_instance() |
|
602 | source_repo = pull_request.source_repo.scm_instance() | |
@@ -605,7 +606,8 b' class PullRequestModel(BaseModel):' | |||||
605 | return UpdateResponse( |
|
606 | return UpdateResponse( | |
606 | executed=False, |
|
607 | executed=False, | |
607 | reason=UpdateFailureReason.MISSING_SOURCE_REF, |
|
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 | source_changed = source_ref_id != source_commit.raw_id |
|
612 | source_changed = source_ref_id != source_commit.raw_id | |
611 |
|
613 | |||
@@ -617,7 +619,8 b' class PullRequestModel(BaseModel):' | |||||
617 | return UpdateResponse( |
|
619 | return UpdateResponse( | |
618 | executed=False, |
|
620 | executed=False, | |
619 | reason=UpdateFailureReason.MISSING_TARGET_REF, |
|
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 | target_changed = target_ref_id != target_commit.raw_id |
|
624 | target_changed = target_ref_id != target_commit.raw_id | |
622 |
|
625 | |||
623 | if not (source_changed or target_changed): |
|
626 | if not (source_changed or target_changed): | |
@@ -625,7 +628,8 b' class PullRequestModel(BaseModel):' | |||||
625 | return UpdateResponse( |
|
628 | return UpdateResponse( | |
626 | executed=False, |
|
629 | executed=False, | |
627 | reason=UpdateFailureReason.NO_CHANGE, |
|
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 | change_in_found = 'target repo' if target_changed else 'source repo' |
|
634 | change_in_found = 'target repo' if target_changed else 'source repo' | |
631 | log.debug('Updating pull request because of change in %s detected', |
|
635 | log.debug('Updating pull request because of change in %s detected', | |
@@ -655,7 +659,8 b' class PullRequestModel(BaseModel):' | |||||
655 | return UpdateResponse( |
|
659 | return UpdateResponse( | |
656 | executed=False, |
|
660 | executed=False, | |
657 | reason=UpdateFailureReason.MISSING_TARGET_REF, |
|
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 | # re-compute commit ids |
|
665 | # re-compute commit ids | |
661 | old_commit_ids = pull_request.revisions |
|
666 | old_commit_ids = pull_request.revisions | |
@@ -678,20 +683,28 b' class PullRequestModel(BaseModel):' | |||||
678 | Session().add(pull_request) |
|
683 | Session().add(pull_request) | |
679 | new_commit_ids = pull_request.revisions |
|
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 | old_diff_data, new_diff_data = self._generate_update_diffs( |
|
686 | old_diff_data, new_diff_data = self._generate_update_diffs( | |
685 | pull_request, pull_request_version) |
|
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 | CommentsModel().outdate_comments( |
|
696 | CommentsModel().outdate_comments( | |
688 | pull_request, old_diff_data=old_diff_data, |
|
697 | pull_request, old_diff_data=old_diff_data, | |
689 | new_diff_data=new_diff_data) |
|
698 | new_diff_data=new_diff_data) | |
690 |
|
699 | |||
691 | file_changes = self._calculate_file_changes( |
|
700 | commit_changes = (changes.added or changes.removed) | |
692 | old_diff_data, new_diff_data) |
|
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 | update_comment = CommentsModel().create( |
|
708 | update_comment = CommentsModel().create( | |
696 | text=self._render_update_message(changes, file_changes), |
|
709 | text=self._render_update_message(changes, file_changes), | |
697 | repo=pull_request.target_repo, |
|
710 | repo=pull_request.target_repo, | |
@@ -713,7 +726,8 b' class PullRequestModel(BaseModel):' | |||||
713 | 'Updated pull request %s, added_ids: %s, common_ids: %s, ' |
|
726 | 'Updated pull request %s, added_ids: %s, common_ids: %s, ' | |
714 | 'removed_ids: %s', pull_request.pull_request_id, |
|
727 | 'removed_ids: %s', pull_request.pull_request_id, | |
715 | changes.added, changes.common, changes.removed) |
|
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 | log.info( |
|
733 | log.info( | |
@@ -723,12 +737,13 b' class PullRequestModel(BaseModel):' | |||||
723 | pull_request.source_ref_parts.commit_id, |
|
737 | pull_request.source_ref_parts.commit_id, | |
724 | pull_request_version.pull_request_version_id) |
|
738 | pull_request_version.pull_request_version_id) | |
725 | Session().commit() |
|
739 | Session().commit() | |
726 |
self._trigger_pull_request_hook( |
|
740 | self._trigger_pull_request_hook( | |
727 | 'update') |
|
741 | pull_request, pull_request.author, 'update') | |
728 |
|
742 | |||
729 | return UpdateResponse( |
|
743 | return UpdateResponse( | |
730 | executed=True, reason=UpdateFailureReason.NONE, |
|
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 | def _create_version_from_snapshot(self, pull_request): |
|
748 | def _create_version_from_snapshot(self, pull_request): | |
734 | version = PullRequestVersion() |
|
749 | version = PullRequestVersion() |
General Comments 0
You need to be logged in to leave comments.
Login now