##// END OF EJS Templates
pull-requests: add information about changes in source repositories in pull-request show page....
dan -
r4317:b8d0e5ed default
parent child Browse files
Show More
@@ -400,6 +400,8 b' class RepoPullRequestsView(RepoAppView, '
400 c.pr_merge_errors = _merge_check.error_details
400 c.pr_merge_errors = _merge_check.error_details
401 c.pr_merge_possible = not _merge_check.failed
401 c.pr_merge_possible = not _merge_check.failed
402 c.pr_merge_message = _merge_check.merge_msg
402 c.pr_merge_message = _merge_check.merge_msg
403 c.pr_merge_source_commit = _merge_check.source_commit
404 c.pr_merge_target_commit = _merge_check.target_commit
403
405
404 c.pr_merge_info = MergeCheck.get_merge_conditions(
406 c.pr_merge_info = MergeCheck.get_merge_conditions(
405 pull_request_latest, translator=self.request.translate)
407 pull_request_latest, translator=self.request.translate)
@@ -231,6 +231,14 b' class MergeResponse(object):'
231 return data
231 return data
232
232
233
233
234 class TargetRefMissing(ValueError):
235 pass
236
237
238 class SourceRefMissing(ValueError):
239 pass
240
241
234 class BaseRepository(object):
242 class BaseRepository(object):
235 """
243 """
236 Base Repository for final backends
244 Base Repository for final backends
@@ -35,7 +35,6 b' import collections'
35 from pyramid import compat
35 from pyramid import compat
36 from pyramid.threadlocal import get_current_request
36 from pyramid.threadlocal import get_current_request
37
37
38 from rhodecode import events
39 from rhodecode.translation import lazy_ugettext
38 from rhodecode.translation import lazy_ugettext
40 from rhodecode.lib import helpers as h, hooks_utils, diffs
39 from rhodecode.lib import helpers as h, hooks_utils, diffs
41 from rhodecode.lib import audit_logger
40 from rhodecode.lib import audit_logger
@@ -43,9 +42,10 b' from rhodecode.lib.compat import Ordered'
43 from rhodecode.lib.hooks_daemon import prepare_callback_daemon
42 from rhodecode.lib.hooks_daemon import prepare_callback_daemon
44 from rhodecode.lib.markup_renderer import (
43 from rhodecode.lib.markup_renderer import (
45 DEFAULT_COMMENTS_RENDERER, RstTemplateRenderer)
44 DEFAULT_COMMENTS_RENDERER, RstTemplateRenderer)
46 from rhodecode.lib.utils2 import safe_unicode, safe_str, md5_safe
45 from rhodecode.lib.utils2 import safe_unicode, safe_str, md5_safe, AttributeDict, safe_int
47 from rhodecode.lib.vcs.backends.base import (
46 from rhodecode.lib.vcs.backends.base import (
48 Reference, MergeResponse, MergeFailureReason, UpdateFailureReason)
47 Reference, MergeResponse, MergeFailureReason, UpdateFailureReason,
48 TargetRefMissing, SourceRefMissing)
49 from rhodecode.lib.vcs.conf import settings as vcs_settings
49 from rhodecode.lib.vcs.conf import settings as vcs_settings
50 from rhodecode.lib.vcs.exceptions import (
50 from rhodecode.lib.vcs.exceptions import (
51 CommitDoesNotExistError, EmptyRepositoryError)
51 CommitDoesNotExistError, EmptyRepositoryError)
@@ -681,6 +681,38 b' class PullRequestModel(BaseModel):'
681 source_ref_type = pull_request.source_ref_parts.type
681 source_ref_type = pull_request.source_ref_parts.type
682 return source_ref_type in self.REF_TYPES
682 return source_ref_type in self.REF_TYPES
683
683
684 def get_flow_commits(self, pull_request):
685
686 # source repo
687 source_ref_name = pull_request.source_ref_parts.name
688 source_ref_type = pull_request.source_ref_parts.type
689 source_ref_id = pull_request.source_ref_parts.commit_id
690 source_repo = pull_request.source_repo.scm_instance()
691
692 try:
693 if source_ref_type in self.REF_TYPES:
694 source_commit = source_repo.get_commit(source_ref_name)
695 else:
696 source_commit = source_repo.get_commit(source_ref_id)
697 except CommitDoesNotExistError:
698 raise SourceRefMissing()
699
700 # target repo
701 target_ref_name = pull_request.target_ref_parts.name
702 target_ref_type = pull_request.target_ref_parts.type
703 target_ref_id = pull_request.target_ref_parts.commit_id
704 target_repo = pull_request.target_repo.scm_instance()
705
706 try:
707 if target_ref_type in self.REF_TYPES:
708 target_commit = target_repo.get_commit(target_ref_name)
709 else:
710 target_commit = target_repo.get_commit(target_ref_id)
711 except CommitDoesNotExistError:
712 raise TargetRefMissing()
713
714 return source_commit, target_commit
715
684 def update_commits(self, pull_request, updating_user):
716 def update_commits(self, pull_request, updating_user):
685 """
717 """
686 Get the updated list of commits for the pull request
718 Get the updated list of commits for the pull request
@@ -707,31 +739,22 b' class PullRequestModel(BaseModel):'
707 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
739 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
708 source_changed=False, target_changed=False)
740 source_changed=False, target_changed=False)
709
741
710 # source repo
711 source_repo = pull_request.source_repo.scm_instance()
712
713 try:
742 try:
714 source_commit = source_repo.get_commit(commit_id=source_ref_name)
743 source_commit, target_commit = self.get_flow_commits(pull_request)
715 except CommitDoesNotExistError:
744 except SourceRefMissing:
716 return UpdateResponse(
745 return UpdateResponse(
717 executed=False,
746 executed=False,
718 reason=UpdateFailureReason.MISSING_SOURCE_REF,
747 reason=UpdateFailureReason.MISSING_SOURCE_REF,
719 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
748 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
720 source_changed=False, target_changed=False)
749 source_changed=False, target_changed=False)
721
750 except TargetRefMissing:
722 source_changed = source_ref_id != source_commit.raw_id
723
724 # target repo
725 target_repo = pull_request.target_repo.scm_instance()
726
727 try:
728 target_commit = target_repo.get_commit(commit_id=target_ref_name)
729 except CommitDoesNotExistError:
730 return UpdateResponse(
751 return UpdateResponse(
731 executed=False,
752 executed=False,
732 reason=UpdateFailureReason.MISSING_TARGET_REF,
753 reason=UpdateFailureReason.MISSING_TARGET_REF,
733 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
754 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
734 source_changed=False, target_changed=False)
755 source_changed=False, target_changed=False)
756
757 source_changed = source_ref_id != source_commit.raw_id
735 target_changed = target_ref_id != target_commit.raw_id
758 target_changed = target_ref_id != target_commit.raw_id
736
759
737 if not (source_changed or target_changed):
760 if not (source_changed or target_changed):
@@ -761,17 +784,8 b' class PullRequestModel(BaseModel):'
761 ver.pull_request_version_id if ver else None
784 ver.pull_request_version_id if ver else None
762 pull_request_version = pull_request
785 pull_request_version = pull_request
763
786
764 try:
787 source_repo = pull_request.source_repo.scm_instance()
765 if target_ref_type in self.REF_TYPES:
788 target_repo = pull_request.target_repo.scm_instance()
766 target_commit = target_repo.get_commit(target_ref_name)
767 else:
768 target_commit = target_repo.get_commit(target_ref_id)
769 except CommitDoesNotExistError:
770 return UpdateResponse(
771 executed=False,
772 reason=UpdateFailureReason.MISSING_TARGET_REF,
773 old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
774 source_changed=source_changed, target_changed=target_changed)
775
789
776 # re-compute commit ids
790 # re-compute commit ids
777 old_commit_ids = pull_request.revisions
791 old_commit_ids = pull_request.revisions
@@ -1736,6 +1750,8 b' class MergeCheck(object):'
1736 self.failed = None
1750 self.failed = None
1737 self.errors = []
1751 self.errors = []
1738 self.error_details = OrderedDict()
1752 self.error_details = OrderedDict()
1753 self.source_commit = AttributeDict()
1754 self.target_commit = AttributeDict()
1739
1755
1740 def __repr__(self):
1756 def __repr__(self):
1741 return '<MergeCheck(possible:{}, failed:{}, errors:{})>'.format(
1757 return '<MergeCheck(possible:{}, failed:{}, errors:{})>'.format(
@@ -1766,8 +1782,7 b' class MergeCheck(object):'
1766 return merge_check
1782 return merge_check
1767
1783
1768 # permissions to merge
1784 # permissions to merge
1769 user_allowed_to_merge = PullRequestModel().check_user_merge(
1785 user_allowed_to_merge = PullRequestModel().check_user_merge(pull_request, auth_user)
1770 pull_request, auth_user)
1771 if not user_allowed_to_merge:
1786 if not user_allowed_to_merge:
1772 log.debug("MergeCheck: cannot merge, approval is pending.")
1787 log.debug("MergeCheck: cannot merge, approval is pending.")
1773
1788
@@ -1837,6 +1852,23 b' class MergeCheck(object):'
1837 merge_check.merge_msg = msg
1852 merge_check.merge_msg = msg
1838 merge_check.merge_response = merge_response
1853 merge_check.merge_response = merge_response
1839
1854
1855 source_ref_id = pull_request.source_ref_parts.commit_id
1856 target_ref_id = pull_request.target_ref_parts.commit_id
1857
1858 try:
1859 source_commit, target_commit = PullRequestModel().get_flow_commits(pull_request)
1860 merge_check.source_commit.changed = source_ref_id != source_commit.raw_id
1861 merge_check.source_commit.ref_spec = pull_request.source_ref_parts
1862 merge_check.source_commit.current_raw_id = source_commit.raw_id
1863 merge_check.source_commit.previous_raw_id = source_ref_id
1864
1865 merge_check.target_commit.changed = target_ref_id != target_commit.raw_id
1866 merge_check.target_commit.ref_spec = pull_request.target_ref_parts
1867 merge_check.target_commit.current_raw_id = target_commit.raw_id
1868 merge_check.target_commit.previous_raw_id = target_ref_id
1869 except (SourceRefMissing, TargetRefMissing):
1870 pass
1871
1840 if not merge_status:
1872 if not merge_status:
1841 log.debug("MergeCheck: cannot merge, pull request merge not possible.")
1873 log.debug("MergeCheck: cannot merge, pull request merge not possible.")
1842 merge_check.push_error('warning', msg, cls.MERGE_CHECK, None)
1874 merge_check.push_error('warning', msg, cls.MERGE_CHECK, None)
@@ -471,6 +471,16 b''
471 </div>
471 </div>
472 </div>
472 </div>
473 </div>
473 </div>
474 % elif c.pr_merge_source_commit.changed:
475 <div class="box">
476 <div class="alert alert-info">
477 <div>
478 % if c.pr_merge_source_commit.changed:
479 <strong>${_('There are new changes for {}:{} in source repository, please consider updating this pull request.').format(c.pr_merge_source_commit.ref_spec.type, c.pr_merge_source_commit.ref_spec.name)}</strong>
480 % endif
481 </div>
482 </div>
483 </div>
474 % endif
484 % endif
475
485
476 <div class="compare_view_commits_title">
486 <div class="compare_view_commits_title">
General Comments 0
You need to be logged in to leave comments. Login now