|
@@
-35,7
+35,6
b' import collections'
|
|
35
|
35
|
from pyramid import compat
|
|
36
|
36
|
from pyramid.threadlocal import get_current_request
|
|
37
|
37
|
|
|
38
|
|
from rhodecode import events
|
|
39
|
38
|
from rhodecode.translation import lazy_ugettext
|
|
40
|
39
|
from rhodecode.lib import helpers as h, hooks_utils, diffs
|
|
41
|
40
|
from rhodecode.lib import audit_logger
|
|
@@
-43,9
+42,10
b' from rhodecode.lib.compat import Ordered'
|
|
43
|
42
|
from rhodecode.lib.hooks_daemon import prepare_callback_daemon
|
|
44
|
43
|
from rhodecode.lib.markup_renderer import (
|
|
45
|
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
|
46
|
from rhodecode.lib.vcs.backends.base import (
|
|
48
|
|
Reference, MergeResponse, MergeFailureReason, UpdateFailureReason)
|
|
|
47
|
Reference, MergeResponse, MergeFailureReason, UpdateFailureReason,
|
|
|
48
|
TargetRefMissing, SourceRefMissing)
|
|
49
|
49
|
from rhodecode.lib.vcs.conf import settings as vcs_settings
|
|
50
|
50
|
from rhodecode.lib.vcs.exceptions import (
|
|
51
|
51
|
CommitDoesNotExistError, EmptyRepositoryError)
|
|
@@
-681,6
+681,38
b' class PullRequestModel(BaseModel):'
|
|
681
|
681
|
source_ref_type = pull_request.source_ref_parts.type
|
|
682
|
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
|
716
|
def update_commits(self, pull_request, updating_user):
|
|
685
|
717
|
"""
|
|
686
|
718
|
Get the updated list of commits for the pull request
|
|
@@
-707,31
+739,22
b' class PullRequestModel(BaseModel):'
|
|
707
|
739
|
old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
|
|
708
|
740
|
source_changed=False, target_changed=False)
|
|
709
|
741
|
|
|
710
|
|
# source repo
|
|
711
|
|
source_repo = pull_request.source_repo.scm_instance()
|
|
712
|
|
|
|
713
|
742
|
try:
|
|
714
|
|
source_commit = source_repo.get_commit(commit_id=source_ref_name)
|
|
715
|
|
except CommitDoesNotExistError:
|
|
|
743
|
source_commit, target_commit = self.get_flow_commits(pull_request)
|
|
|
744
|
except SourceRefMissing:
|
|
716
|
745
|
return UpdateResponse(
|
|
717
|
746
|
executed=False,
|
|
718
|
747
|
reason=UpdateFailureReason.MISSING_SOURCE_REF,
|
|
719
|
748
|
old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
|
|
720
|
749
|
source_changed=False, target_changed=False)
|
|
721
|
|
|
|
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:
|
|
|
750
|
except TargetRefMissing:
|
|
730
|
751
|
return UpdateResponse(
|
|
731
|
752
|
executed=False,
|
|
732
|
753
|
reason=UpdateFailureReason.MISSING_TARGET_REF,
|
|
733
|
754
|
old=pull_request, new=None, common_ancestor_id=None, commit_changes=None,
|
|
734
|
755
|
source_changed=False, target_changed=False)
|
|
|
756
|
|
|
|
757
|
source_changed = source_ref_id != source_commit.raw_id
|
|
735
|
758
|
target_changed = target_ref_id != target_commit.raw_id
|
|
736
|
759
|
|
|
737
|
760
|
if not (source_changed or target_changed):
|
|
@@
-761,17
+784,8
b' class PullRequestModel(BaseModel):'
|
|
761
|
784
|
ver.pull_request_version_id if ver else None
|
|
762
|
785
|
pull_request_version = pull_request
|
|
763
|
786
|
|
|
764
|
|
try:
|
|
765
|
|
if target_ref_type in self.REF_TYPES:
|
|
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)
|
|
|
787
|
source_repo = pull_request.source_repo.scm_instance()
|
|
|
788
|
target_repo = pull_request.target_repo.scm_instance()
|
|
775
|
789
|
|
|
776
|
790
|
# re-compute commit ids
|
|
777
|
791
|
old_commit_ids = pull_request.revisions
|
|
@@
-1736,6
+1750,8
b' class MergeCheck(object):'
|
|
1736
|
1750
|
self.failed = None
|
|
1737
|
1751
|
self.errors = []
|
|
1738
|
1752
|
self.error_details = OrderedDict()
|
|
|
1753
|
self.source_commit = AttributeDict()
|
|
|
1754
|
self.target_commit = AttributeDict()
|
|
1739
|
1755
|
|
|
1740
|
1756
|
def __repr__(self):
|
|
1741
|
1757
|
return '<MergeCheck(possible:{}, failed:{}, errors:{})>'.format(
|
|
@@
-1766,8
+1782,7
b' class MergeCheck(object):'
|
|
1766
|
1782
|
return merge_check
|
|
1767
|
1783
|
|
|
1768
|
1784
|
# permissions to merge
|
|
1769
|
|
user_allowed_to_merge = PullRequestModel().check_user_merge(
|
|
1770
|
|
pull_request, auth_user)
|
|
|
1785
|
user_allowed_to_merge = PullRequestModel().check_user_merge(pull_request, auth_user)
|
|
1771
|
1786
|
if not user_allowed_to_merge:
|
|
1772
|
1787
|
log.debug("MergeCheck: cannot merge, approval is pending.")
|
|
1773
|
1788
|
|
|
@@
-1837,6
+1852,23
b' class MergeCheck(object):'
|
|
1837
|
1852
|
merge_check.merge_msg = msg
|
|
1838
|
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
|
1872
|
if not merge_status:
|
|
1841
|
1873
|
log.debug("MergeCheck: cannot merge, pull request merge not possible.")
|
|
1842
|
1874
|
merge_check.push_error('warning', msg, cls.MERGE_CHECK, None)
|