##// 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 357 pr_closed = pull_request_latest.is_closed()
358 358
359 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 361 raise HTTPFound(h.route_path(
362 362 'pullrequest_show', repo_name=self.db_repo_name,
363 363 pull_request_id=pull_request_id))
@@ -394,7 +394,7 b' class RepoPullRequestsView(RepoAppView, '
394 394 compare = at_version != prev_at_version
395 395
396 396 # pull_requests repo_name we opened it against
397 # ie. target_repo must match
397 # i.e., target_repo must match
398 398 if self.db_repo_name != pull_request_at_ver.target_repo.repo_name:
399 399 log.warning('Mismatch between the current repo: %s, and target %s',
400 400 self.db_repo_name, pull_request_at_ver.target_repo.repo_name)
@@ -470,6 +470,7 b' class RepoPullRequestsView(RepoAppView, '
470 470 c.pull_request_set_reviewers_data_json = collections.OrderedDict({'reviewers': []})
471 471 c.pull_request_set_observers_data_json = collections.OrderedDict({'observers': []})
472 472
473 # reviewers
473 474 for review_obj, member, reasons, mandatory, status in pull_request_at_ver.reviewers_statuses():
474 475 member_reviewer = h.reviewer_as_json(
475 476 member, reasons=reasons, mandatory=mandatory,
@@ -485,6 +486,7 b' class RepoPullRequestsView(RepoAppView, '
485 486
486 487 c.pull_request_set_reviewers_data_json = ext_json.str_json(c.pull_request_set_reviewers_data_json)
487 488
489 # observers
488 490 for observer_obj, member in pull_request_at_ver.observers():
489 491 member_observer = h.reviewer_as_json(
490 492 member, reasons=[], mandatory=False,
@@ -620,7 +622,7 b' class RepoPullRequestsView(RepoAppView, '
620 622 target_commit,
621 623 target_ref_id,
622 624 target_scm,
623 maybe_unreachable=maybe_unreachable)
625 maybe_unreachable=maybe_unreachable)
624 626
625 627 # register our commit range
626 628 for comm in commit_cache.values():
@@ -763,7 +765,7 b' class RepoPullRequestsView(RepoAppView, '
763 765 try:
764 766 commit = commits_source_repo.get_commit(raw_id)
765 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 769 # for display in commit diff
768 770 commit = h.AttributeDict(
769 771 {'raw_id': raw_id,
@@ -1722,6 +1724,7 b' class RepoPullRequestsView(RepoAppView, '
1722 1724 'f_path': self.request.POST.get('f_path'),
1723 1725 'line': self.request.POST.get('line'),
1724 1726 }
1727
1725 1728 data = self._pull_request_comments_create(pull_request, [comment_data])
1726 1729
1727 1730 return data
@@ -65,7 +65,7 b' from rhodecode.lib.jsonalchemy import ('
65 65 from rhodecode.lib.hash_utils import sha1
66 66 from rhodecode.lib import ext_json
67 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 69 from rhodecode.lib.caching_query import FromCache
70 70 from rhodecode.lib.exceptions import (
71 71 ArtifactMetadataDuplicate, ArtifactMetadataBadValueType)
@@ -3845,7 +3845,7 b' class ChangesetComment(Base, BaseModel):'
3845 3845
3846 3846 @property
3847 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 3850 @property
3851 3851 def immutable(self):
@@ -3855,6 +3855,15 b' class ChangesetComment(Base, BaseModel):'
3855 3855 """
3856 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 3867 def version_check():
3859 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 3878 Checks if comment is outdated for given pull request version
3870 3879 """
3871 return json.dumps(self.outdated_at_version(version))
3872
3873 def older_than_version(self, version):
3880 return str_json(self.outdated_at_version(version))
3881
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
3876 """
3887
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 3897 cur_ver = 0
3878 if self.pull_request_version:
3879 cur_ver = self.pull_request_version.pull_request_version_id or cur_ver
3880
3881 if version is None:
3882 return cur_ver != version
3883
3898 if self.pull_request_version and self.pull_request_version.pull_request_version_id is not None:
3899 cur_ver = self.pull_request_version.pull_request_version_id
3900
3901 # Return True if the current version is less than the given version
3884 3902 return cur_ver < version
3885 3903
3886 3904 def older_than_version_js(self, version):
3887 3905 """
3888 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 3910 @property
3893 3911 def commit_id(self):
@@ -4217,7 +4235,7 b' class _PullRequestBase(BaseModel):'
4217 4235
4218 4236 @property
4219 4237 def reviewer_data_json(self):
4220 return json.dumps(self.reviewer_data)
4238 return str_json(self.reviewer_data)
4221 4239
4222 4240 @property
4223 4241 def last_merge_metadata_parsed(self):
@@ -225,12 +225,12 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
225 225 ## file was renamed, or copied
226 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 229 final_path = filediff.target_file_path
230 230 %>
231 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 234 final_path = filediff.target_file_path
235 235 %>
236 236 %endif
@@ -272,7 +272,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
272 272 >
273 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 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 278 <div class="filediff-collapse-indicator icon-"></div>
@@ -302,7 +302,6 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
302 302 <span class="pull-right icon-clipboard clipboard-action" data-clipboard-text="${permalink}" title="Copy permalink"></span>
303 303 </div>
304 304
305
306 305 </details-menu>
307 306 </details>
308 307
@@ -667,8 +666,8 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
667 666 <%!
668 667
669 668 def get_inline_comments(comments, filename):
670 if hasattr(filename, 'unicode_path'):
671 filename = filename.unicode_path
669 if hasattr(filename, 'str_path'):
670 filename = filename.str_path
672 671
673 672 if not isinstance(filename, str):
674 673 return None
@@ -679,8 +678,8 b' def get_inline_comments(comments, filena'
679 678 return None
680 679
681 680 def get_comments_for(diff_type, comments, filename, line_version, line_number):
682 if hasattr(filename, 'unicode_path'):
683 filename = filename.unicode_path
681 if hasattr(filename, 'str_path'):
682 filename = filename.str_path
684 683
685 684 if not isinstance(filename, str):
686 685 return None
@@ -689,7 +688,7 b' def get_comments_for(diff_type, comments'
689 688 if file_comments is None:
690 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 692 if line_key in file_comments:
694 693 data = file_comments.pop(line_key)
695 694 return data
General Comments 0
You need to be logged in to leave comments. Login now