##// END OF EJS Templates
fix(pull-requests): fixes for rendering comments
super-admin -
r5211:5e903185 default
parent child Browse files
Show More
@@ -357,7 +357,7 b' class RepoPullRequestsView(RepoAppView, '
357 pr_closed = pull_request_latest.is_closed()
357 pr_closed = pull_request_latest.is_closed()
358
358
359 if pr_closed and (version or from_version):
359 if pr_closed and (version or from_version):
360 # not allow to browse versions for closed PR
360 # not allow browsing versions for closed PR
361 raise HTTPFound(h.route_path(
361 raise HTTPFound(h.route_path(
362 'pullrequest_show', repo_name=self.db_repo_name,
362 'pullrequest_show', repo_name=self.db_repo_name,
363 pull_request_id=pull_request_id))
363 pull_request_id=pull_request_id))
@@ -394,7 +394,7 b' class RepoPullRequestsView(RepoAppView, '
394 compare = at_version != prev_at_version
394 compare = at_version != prev_at_version
395
395
396 # pull_requests repo_name we opened it against
396 # pull_requests repo_name we opened it against
397 # ie. target_repo must match
397 # i.e., target_repo must match
398 if self.db_repo_name != pull_request_at_ver.target_repo.repo_name:
398 if self.db_repo_name != pull_request_at_ver.target_repo.repo_name:
399 log.warning('Mismatch between the current repo: %s, and target %s',
399 log.warning('Mismatch between the current repo: %s, and target %s',
400 self.db_repo_name, pull_request_at_ver.target_repo.repo_name)
400 self.db_repo_name, pull_request_at_ver.target_repo.repo_name)
@@ -470,6 +470,7 b' class RepoPullRequestsView(RepoAppView, '
470 c.pull_request_set_reviewers_data_json = collections.OrderedDict({'reviewers': []})
470 c.pull_request_set_reviewers_data_json = collections.OrderedDict({'reviewers': []})
471 c.pull_request_set_observers_data_json = collections.OrderedDict({'observers': []})
471 c.pull_request_set_observers_data_json = collections.OrderedDict({'observers': []})
472
472
473 # reviewers
473 for review_obj, member, reasons, mandatory, status in pull_request_at_ver.reviewers_statuses():
474 for review_obj, member, reasons, mandatory, status in pull_request_at_ver.reviewers_statuses():
474 member_reviewer = h.reviewer_as_json(
475 member_reviewer = h.reviewer_as_json(
475 member, reasons=reasons, mandatory=mandatory,
476 member, reasons=reasons, mandatory=mandatory,
@@ -485,6 +486,7 b' class RepoPullRequestsView(RepoAppView, '
485
486
486 c.pull_request_set_reviewers_data_json = ext_json.str_json(c.pull_request_set_reviewers_data_json)
487 c.pull_request_set_reviewers_data_json = ext_json.str_json(c.pull_request_set_reviewers_data_json)
487
488
489 # observers
488 for observer_obj, member in pull_request_at_ver.observers():
490 for observer_obj, member in pull_request_at_ver.observers():
489 member_observer = h.reviewer_as_json(
491 member_observer = h.reviewer_as_json(
490 member, reasons=[], mandatory=False,
492 member, reasons=[], mandatory=False,
@@ -763,7 +765,7 b' class RepoPullRequestsView(RepoAppView, '
763 try:
765 try:
764 commit = commits_source_repo.get_commit(raw_id)
766 commit = commits_source_repo.get_commit(raw_id)
765 except CommitDoesNotExistError:
767 except CommitDoesNotExistError:
766 # in case we fail extracting still use "dummy" commit
768 # in case we fail getting the commit, still use a dummy commit
767 # for display in commit diff
769 # for display in commit diff
768 commit = h.AttributeDict(
770 commit = h.AttributeDict(
769 {'raw_id': raw_id,
771 {'raw_id': raw_id,
@@ -1722,6 +1724,7 b' class RepoPullRequestsView(RepoAppView, '
1722 'f_path': self.request.POST.get('f_path'),
1724 'f_path': self.request.POST.get('f_path'),
1723 'line': self.request.POST.get('line'),
1725 'line': self.request.POST.get('line'),
1724 }
1726 }
1727
1725 data = self._pull_request_comments_create(pull_request, [comment_data])
1728 data = self._pull_request_comments_create(pull_request, [comment_data])
1726
1729
1727 return data
1730 return data
@@ -65,7 +65,7 b' from rhodecode.lib.jsonalchemy import ('
65 from rhodecode.lib.hash_utils import sha1
65 from rhodecode.lib.hash_utils import sha1
66 from rhodecode.lib import ext_json
66 from rhodecode.lib import ext_json
67 from rhodecode.lib import enc_utils
67 from rhodecode.lib import enc_utils
68 from rhodecode.lib.ext_json import json
68 from rhodecode.lib.ext_json import json, str_json
69 from rhodecode.lib.caching_query import FromCache
69 from rhodecode.lib.caching_query import FromCache
70 from rhodecode.lib.exceptions import (
70 from rhodecode.lib.exceptions import (
71 ArtifactMetadataDuplicate, ArtifactMetadataBadValueType)
71 ArtifactMetadataDuplicate, ArtifactMetadataBadValueType)
@@ -3845,7 +3845,7 b' class ChangesetComment(Base, BaseModel):'
3845
3845
3846 @property
3846 @property
3847 def outdated_js(self):
3847 def outdated_js(self):
3848 return json.dumps(self.display_state == self.COMMENT_OUTDATED)
3848 return str_json(self.display_state == self.COMMENT_OUTDATED)
3849
3849
3850 @property
3850 @property
3851 def immutable(self):
3851 def immutable(self):
@@ -3855,6 +3855,15 b' class ChangesetComment(Base, BaseModel):'
3855 """
3855 """
3856 Checks if comment is outdated for given pull request version
3856 Checks if comment is outdated for given pull request version
3857 """
3857 """
3858
3859 # If version is None, return False as the current version cannot be less than None
3860 if version is None:
3861 return False
3862
3863 # Ensure that the version is an integer to prevent TypeError on comparison
3864 if not isinstance(version, int):
3865 raise ValueError("The provided version must be an integer.")
3866
3858 def version_check():
3867 def version_check():
3859 return self.pull_request_version_id and self.pull_request_version_id != version
3868 return self.pull_request_version_id and self.pull_request_version_id != version
3860
3869
@@ -3868,26 +3877,35 b' class ChangesetComment(Base, BaseModel):'
3868 """
3877 """
3869 Checks if comment is outdated for given pull request version
3878 Checks if comment is outdated for given pull request version
3870 """
3879 """
3871 return json.dumps(self.outdated_at_version(version))
3880 return str_json(self.outdated_at_version(version))
3872
3881
3873 def older_than_version(self, version):
3882 def older_than_version(self, version: int) -> bool:
3883 """
3884 Checks if comment is made from a previous version than given.
3885 Assumes self.pull_request_version.pull_request_version_id is an integer if not None.
3874 """
3886 """
3875 Checks if comment is made from previous version than given
3887
3876 """
3888 # If version is None, return False as the current version cannot be less than None
3889 if version is None:
3890 return False
3891
3892 # Ensure that the version is an integer to prevent TypeError on comparison
3893 if not isinstance(version, int):
3894 raise ValueError("The provided version must be an integer.")
3895
3896 # Initialize current version to 0 or pull_request_version_id if it's available
3877 cur_ver = 0
3897 cur_ver = 0
3878 if self.pull_request_version:
3898 if self.pull_request_version and self.pull_request_version.pull_request_version_id is not None:
3879 cur_ver = self.pull_request_version.pull_request_version_id or cur_ver
3899 cur_ver = self.pull_request_version.pull_request_version_id
3880
3900
3881 if version is None:
3901 # Return True if the current version is less than the given version
3882 return cur_ver != version
3883
3884 return cur_ver < version
3902 return cur_ver < version
3885
3903
3886 def older_than_version_js(self, version):
3904 def older_than_version_js(self, version):
3887 """
3905 """
3888 Checks if comment is made from previous version than given
3906 Checks if comment is made from previous version than given
3889 """
3907 """
3890 return json.dumps(self.older_than_version(version))
3908 return str_json(self.older_than_version(version))
3891
3909
3892 @property
3910 @property
3893 def commit_id(self):
3911 def commit_id(self):
@@ -4217,7 +4235,7 b' class _PullRequestBase(BaseModel):'
4217
4235
4218 @property
4236 @property
4219 def reviewer_data_json(self):
4237 def reviewer_data_json(self):
4220 return json.dumps(self.reviewer_data)
4238 return str_json(self.reviewer_data)
4221
4239
4222 @property
4240 @property
4223 def last_merge_metadata_parsed(self):
4241 def last_merge_metadata_parsed(self):
@@ -225,12 +225,12 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
225 ## file was renamed, or copied
225 ## file was renamed, or copied
226 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
226 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
227 <%
227 <%
228 final_file_name = h.literal(u'{} <i class="icon-angle-left"></i> <del>{}</del>'.format(filediff.target_file_path, filediff.source_file_path))
228 final_file_name = h.literal('{} <i class="icon-angle-left"></i> <del>{}</del>'.format(filediff.target_file_path, filediff.source_file_path))
229 final_path = filediff.target_file_path
229 final_path = filediff.target_file_path
230 %>
230 %>
231 %elif COPIED_FILENODE in filediff.patch['stats']['ops']:
231 %elif COPIED_FILENODE in filediff.patch['stats']['ops']:
232 <%
232 <%
233 final_file_name = h.literal(u'{} <i class="icon-angle-left"></i> {}'.format(filediff.target_file_path, filediff.source_file_path))
233 final_file_name = h.literal('{} <i class="icon-angle-left"></i> {}'.format(filediff.target_file_path, filediff.source_file_path))
234 final_path = filediff.target_file_path
234 final_path = filediff.target_file_path
235 %>
235 %>
236 %endif
236 %endif
@@ -272,7 +272,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
272 >
272 >
273 <label for="filediff-collapse-${id(filediff)}" class="filediff-heading">
273 <label for="filediff-collapse-${id(filediff)}" class="filediff-heading">
274 <%
274 <%
275 file_comments = (get_inline_comments(inline_comments, filediff.patch['filename']) or {}).values()
275 file_comments = list((get_inline_comments(inline_comments, filediff.patch['filename']) or {}).values())
276 total_file_comments = [_c for _c in h.itertools.chain.from_iterable(file_comments) if not (_c.outdated or _c.draft)]
276 total_file_comments = [_c for _c in h.itertools.chain.from_iterable(file_comments) if not (_c.outdated or _c.draft)]
277 %>
277 %>
278 <div class="filediff-collapse-indicator icon-"></div>
278 <div class="filediff-collapse-indicator icon-"></div>
@@ -302,7 +302,6 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
302 <span class="pull-right icon-clipboard clipboard-action" data-clipboard-text="${permalink}" title="Copy permalink"></span>
302 <span class="pull-right icon-clipboard clipboard-action" data-clipboard-text="${permalink}" title="Copy permalink"></span>
303 </div>
303 </div>
304
304
305
306 </details-menu>
305 </details-menu>
307 </details>
306 </details>
308
307
@@ -667,8 +666,8 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
667 <%!
666 <%!
668
667
669 def get_inline_comments(comments, filename):
668 def get_inline_comments(comments, filename):
670 if hasattr(filename, 'unicode_path'):
669 if hasattr(filename, 'str_path'):
671 filename = filename.unicode_path
670 filename = filename.str_path
672
671
673 if not isinstance(filename, str):
672 if not isinstance(filename, str):
674 return None
673 return None
@@ -679,8 +678,8 b' def get_inline_comments(comments, filena'
679 return None
678 return None
680
679
681 def get_comments_for(diff_type, comments, filename, line_version, line_number):
680 def get_comments_for(diff_type, comments, filename, line_version, line_number):
682 if hasattr(filename, 'unicode_path'):
681 if hasattr(filename, 'str_path'):
683 filename = filename.unicode_path
682 filename = filename.str_path
684
683
685 if not isinstance(filename, str):
684 if not isinstance(filename, str):
686 return None
685 return None
@@ -689,7 +688,7 b' def get_comments_for(diff_type, comments'
689 if file_comments is None:
688 if file_comments is None:
690 return None
689 return None
691
690
692 line_key = '{}{}'.format(line_version, line_number) ## e.g o37, n12
691 line_key = f'{line_version}{line_number}' ## e.g o37, n12
693 if line_key in file_comments:
692 if line_key in file_comments:
694 data = file_comments.pop(line_key)
693 data = file_comments.pop(line_key)
695 return data
694 return data
General Comments 0
You need to be logged in to leave comments. Login now