inline-comments: added helper to properly count inline comments.

This commit is contained in:
Marcin Kuzminski 2016-12-06 00:18:07 +01:00
parent 05841262aa
commit 1d37334326
4 changed files with 18 additions and 4 deletions

View file

@ -200,7 +200,6 @@ class ChangesetController(BaseRepoController):
c.commit_statuses = ChangesetStatus.STATUSES
c.inline_comments = []
c.inline_cnt = 0
c.files = []
c.statuses = []
@ -254,7 +253,8 @@ class ChangesetController(BaseRepoController):
inline_comments = ChangesetCommentsModel().get_inline_comments(
c.rhodecode_db_repo.repo_id, revision=commit.raw_id)
c.inline_cnt += len(inline_comments)
c.inline_cnt = ChangesetCommentsModel().get_inline_comments_count(
inline_comments)
diffset = codeblocks.DiffSet(
repo_name=c.repo_name,

View file

@ -720,7 +720,9 @@ class PullrequestsController(BaseRepoController):
c.inline_comments = cc_model.get_inline_comments(
c.rhodecode_db_repo.repo_id,
pull_request=pull_request_id)
c.inline_cnt = len(c.inline_comments)
c.inline_cnt = cc_model.get_inline_comments_count(
c.inline_comments, version=at_version)
self._load_compare_data(
c.pull_request, c.inline_comments, enable_comments=enable_comments)

View file

@ -354,6 +354,16 @@ class ChangesetCommentsModel(BaseModel):
q = self._get_inline_comments_query(repo_id, revision, pull_request)
return self._group_comments_by_path_and_line_number(q)
def get_inline_comments_count(self, inline_comments, skip_outdated=True,
version=None):
inline_cnt = 0
for fname, per_line_comments in inline_comments.iteritems():
for lno, comments in per_line_comments.iteritems():
inline_cnt += len(
[comm for comm in comments
if (not comm.outdated_at_version(version) and skip_outdated)])
return inline_cnt
def get_outdated_comments(self, repo_id, pull_request):
# TODO: johbo: Remove `repo_id`, it is not needed to find the comments
# of a pull request.

View file

@ -810,7 +810,9 @@ def assert_inline_comments(pull_request, visible=None, outdated=None):
if visible is not None:
inline_comments = ChangesetCommentsModel().get_inline_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
assert len(inline_comments) == visible
inline_cnt = ChangesetCommentsModel().get_inline_comments_count(
inline_comments)
assert inline_cnt == visible
if outdated is not None:
outdated_comments = ChangesetCommentsModel().get_outdated_comments(
pull_request.target_repo.repo_id, pull_request)