comments: renamed ChangesetCommentsModel to CommentsModel to reflect what it actually does.

It's not limited to Changesets/Commits.
This commit is contained in:
Marcin Kuzminski 2017-01-09 17:52:00 +01:00
parent 828c060bdd
commit b52808ca95
14 changed files with 53 additions and 53 deletions

View file

@ -20,7 +20,7 @@
import pytest
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import UserLog
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.tests import TEST_USER_ADMIN_LOGIN
@ -52,7 +52,7 @@ class TestCommentPullRequest(object):
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request.pull_request_id)
comments = ChangesetCommentsModel().get_comments(
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
expected = {
@ -83,7 +83,7 @@ class TestCommentPullRequest(object):
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request_id)
comments = ChangesetCommentsModel().get_comments(
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
expected = {
'pull_request_id': pull_request.pull_request_id,
@ -132,7 +132,7 @@ class TestCommentPullRequest(object):
response = api_call(self.app, params)
pull_request = PullRequestModel().get(pull_request_id)
comments = ChangesetCommentsModel().get_comments(
comments = CommentsModel().get_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
expected = {
'pull_request_id': pull_request.pull_request_id,

View file

@ -30,7 +30,7 @@ from rhodecode.lib.auth import (HasRepoPermissionAnyApi)
from rhodecode.lib.base import vcs_operation_context
from rhodecode.lib.utils2 import str2bool
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import Session, ChangesetStatus
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.model.settings import SettingsModel
@ -455,7 +455,7 @@ def comment_pull_request(request, apiuser, repoid, pullrequestid,
renderer = rc_config.get('rhodecode_markup_renderer', 'rst')
status_change = status and allowed_to_change_status
comment = ChangesetCommentsModel().create(
comment = CommentsModel().create(
text=text,
repo=pull_request.target_repo.repo_id,
user=apiuser.user_id,

View file

@ -34,7 +34,7 @@ from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
from rhodecode.lib.utils2 import str2bool, time_to_datetime
from rhodecode.lib.ext_json import json
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import (
Session, ChangesetStatus, RepositoryField, Repository, RepoGroup)
from rhodecode.model.repo import RepoModel
@ -1436,7 +1436,7 @@ def comment_commit(
rc_config = SettingsModel().get_all_settings()
renderer = rc_config.get('rhodecode_markup_renderer', 'rst')
status_change_label = ChangesetStatus.get_status_lbl(status)
comm = ChangesetCommentsModel().create(
comm = CommentsModel().create(
message, repo, user, commit_id=commit_id,
status_change=status_change_label,
status_change_type=status,

View file

@ -57,7 +57,7 @@ from rhodecode.model.repo import RepoModel
from rhodecode.model.auth_token import AuthTokenModel
from rhodecode.model.meta import Session
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
log = logging.getLogger(__name__)
@ -322,7 +322,7 @@ class MyAccountController(BaseController):
data = []
for pr in pull_requests:
repo_id = pr.target_repo_id
comments = ChangesetCommentsModel().get_all_comments(
comments = CommentsModel().get_all_comments(
repo_id, pull_request=pr)
owned = pr.user_id == c.rhodecode_user.user_id
status = pr.calculated_review_status()

View file

@ -46,7 +46,7 @@ from rhodecode.lib.vcs.exceptions import (
RepositoryError, CommitDoesNotExistError, NodeDoesNotExistError)
from rhodecode.model.db import ChangesetComment, ChangesetStatus
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
@ -210,7 +210,7 @@ class ChangesetController(BaseRepoController):
c.comments = []
if len(c.commit_ranges) == 1:
commit = c.commit_ranges[0]
c.comments = ChangesetCommentsModel().get_comments(
c.comments = CommentsModel().get_comments(
c.rhodecode_db_repo.repo_id,
revision=commit.raw_id)
c.statuses.append(ChangesetStatusModel().get_status(
@ -255,9 +255,9 @@ class ChangesetController(BaseRepoController):
return None
return get_node
inline_comments = ChangesetCommentsModel().get_inline_comments(
inline_comments = CommentsModel().get_inline_comments(
c.rhodecode_db_repo.repo_id, revision=commit.raw_id)
c.inline_cnt = ChangesetCommentsModel().get_inline_comments_count(
c.inline_cnt = CommentsModel().get_inline_comments_count(
inline_comments)
diffset = codeblocks.DiffSet(
@ -346,7 +346,7 @@ class ChangesetController(BaseRepoController):
commit_ids = multi_commit_ids or [commit_id]
comment = None
for current_id in filter(None, commit_ids):
c.co = comment = ChangesetCommentsModel().create(
c.co = comment = CommentsModel().create(
text=text,
repo=c.rhodecode_db_repo.repo_id,
user=c.rhodecode_user.user_id,
@ -426,7 +426,7 @@ class ChangesetController(BaseRepoController):
owner = (comment.author.user_id == c.rhodecode_user.user_id)
is_repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
if h.HasPermissionAny('hg.admin')() or is_repo_admin or owner:
ChangesetCommentsModel().delete(comment=comment)
CommentsModel().delete(comment=comment)
Session().commit()
return True
else:

View file

@ -55,7 +55,7 @@ from rhodecode.lib.vcs.exceptions import (
NodeDoesNotExistError)
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import (PullRequest, ChangesetStatus, ChangesetComment,
Repository, PullRequestVersion)
from rhodecode.model.forms import PullRequestForm
@ -258,7 +258,7 @@ class PullrequestsController(BaseRepoController):
_render = PartialRenderer('data_table/_dt_elements.mako')
data = []
for pr in pull_requests:
comments = ChangesetCommentsModel().get_all_comments(
comments = CommentsModel().get_all_comments(
c.rhodecode_db_repo.repo_id, pull_request=pr)
data.append({
@ -796,7 +796,7 @@ class PullrequestsController(BaseRepoController):
pull_request_latest, c.rhodecode_user) and not pr_closed
c.allowed_to_comment = not pr_closed
cc_model = ChangesetCommentsModel()
cc_model = CommentsModel()
c.pull_request_reviewers = pull_request_at_ver.reviewers_statuses()
c.pull_request_review_status = pull_request_at_ver.calculated_review_status()
@ -837,7 +837,7 @@ class PullrequestsController(BaseRepoController):
# outdated comments
c.outdated_cnt = 0
if ChangesetCommentsModel.use_outdated_comments(pull_request_latest):
if CommentsModel.use_outdated_comments(pull_request_latest):
outdated_comments = cc_model.get_outdated_comments(
c.rhodecode_db_repo.repo_id,
pull_request=pull_request_at_ver)
@ -923,7 +923,7 @@ class PullrequestsController(BaseRepoController):
if close_pr:
message = _('Closing with') + ' ' + message
text = text or message
comm = ChangesetCommentsModel().create(
comm = CommentsModel().create(
text=text,
repo=c.rhodecode_db_repo.repo_id,
user=c.rhodecode_user.user_id,
@ -1013,7 +1013,7 @@ class PullrequestsController(BaseRepoController):
is_repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
if h.HasPermissionAny('hg.admin')() or is_repo_admin or is_owner:
old_calculated_status = co.pull_request.calculated_review_status()
ChangesetCommentsModel().delete(comment=co)
CommentsModel().delete(comment=co)
Session().commit()
calculated_status = co.pull_request.calculated_review_status()
if old_calculated_status != calculated_status:

View file

@ -114,7 +114,7 @@ class PullRequestCommentEvent(PullRequestEvent):
self.comment = comment
def as_dict(self):
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
data = super(PullRequestCommentEvent, self).as_dict()
status = None
@ -125,7 +125,7 @@ class PullRequestCommentEvent(PullRequestEvent):
'comment': {
'status': status,
'text': self.comment.text,
'url': ChangesetCommentsModel().get_url(self.comment)
'url': CommentsModel().get_url(self.comment)
}
})
return data

View file

@ -201,8 +201,8 @@ class ChangesetStatusModel(BaseModel):
return new_status
if not comment:
from rhodecode.model.comment import ChangesetCommentsModel
comment = ChangesetCommentsModel().create(
from rhodecode.model.comment import CommentsModel
comment = CommentsModel().create(
text=self._render_auto_status_message(
status, commit_id=revision, pull_request=pull_request),
repo=repo,

View file

@ -48,7 +48,7 @@ from rhodecode.model.notification import EmailNotificationModel
log = logging.getLogger(__name__)
class ChangesetCommentsModel(BaseModel):
class CommentsModel(BaseModel):
cls = ChangesetComment
@ -392,7 +392,7 @@ class ChangesetCommentsModel(BaseModel):
elif pull_request:
pull_request = self.__get_pull_request(pull_request)
if not ChangesetCommentsModel.use_outdated_comments(pull_request):
if not CommentsModel.use_outdated_comments(pull_request):
q = self._visible_inline_comments_of_pull_request(pull_request)
else:
q = self._all_inline_comments_of_pull_request(pull_request)
@ -414,7 +414,7 @@ class ChangesetCommentsModel(BaseModel):
return max(cls.DIFF_CONTEXT_BEFORE, cls.DIFF_CONTEXT_AFTER)
def outdate_comments(self, pull_request, old_diff_data, new_diff_data):
if not ChangesetCommentsModel.use_outdated_comments(pull_request):
if not CommentsModel.use_outdated_comments(pull_request):
return
comments = self._visible_inline_comments_of_pull_request(pull_request)

View file

@ -47,7 +47,7 @@ from rhodecode.lib.vcs.exceptions import (
CommitDoesNotExistError, EmptyRepositoryError)
from rhodecode.model import BaseModel
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import (
PullRequest, PullRequestReviewers, ChangesetStatus,
PullRequestVersion, ChangesetComment)
@ -552,7 +552,7 @@ class PullRequestModel(BaseModel):
pull_request.merge_rev = merge_state.merge_ref.commit_id
pull_request.updated_on = datetime.datetime.now()
ChangesetCommentsModel().create(
CommentsModel().create(
text=unicode(_('Pull request merged and closed')),
repo=pull_request.target_repo.repo_id,
user=user.user_id,
@ -655,7 +655,7 @@ class PullRequestModel(BaseModel):
old_diff_data, new_diff_data = self._generate_update_diffs(
pull_request, pull_request_version)
ChangesetCommentsModel().outdate_comments(
CommentsModel().outdate_comments(
pull_request, old_diff_data=old_diff_data,
new_diff_data=new_diff_data)
@ -663,7 +663,7 @@ class PullRequestModel(BaseModel):
old_diff_data, new_diff_data)
# Add an automatic comment to the pull request
update_comment = ChangesetCommentsModel().create(
update_comment = CommentsModel().create(
text=self._render_update_message(changes, file_changes),
repo=pull_request.target_repo,
user=pull_request.author,
@ -730,7 +730,7 @@ class PullRequestModel(BaseModel):
def _generate_update_diffs(self, pull_request, pull_request_version):
diff_context = (
self.DIFF_CONTEXT +
ChangesetCommentsModel.needed_extra_diff_context())
CommentsModel.needed_extra_diff_context())
old_diff = self._get_diff_from_pr_or_version(
pull_request_version, context=diff_context)
new_diff = self._get_diff_from_pr_or_version(
@ -1001,7 +1001,7 @@ class PullRequestModel(BaseModel):
internal_message = _('Closing with') + ' ' + message
comm = ChangesetCommentsModel().create(
comm = CommentsModel().create(
text=internal_message,
repo=repo.repo_id,
user=user.user_id,

View file

@ -22,7 +22,7 @@ import pytest
from rhodecode.tests.events.conftest import EventCatcher
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.events import (
PullRequestCreateEvent,
@ -61,7 +61,7 @@ def test_create_pull_request_events(pr_util):
@pytest.mark.backends("git", "hg")
def test_pullrequest_comment_events_serialized(pr_util):
pr = pr_util.create_pull_request()
comment = ChangesetCommentsModel().get_comments(
comment = CommentsModel().get_comments(
pr.target_repo.repo_id, pull_request=pr)[0]
event = PullRequestCommentEvent(pr, comment)
data = event.as_dict()

View file

@ -72,7 +72,7 @@ def test_diff_to_comment_line_number(old, new, expected):
(DiffLineNumber(old=12, new=None), DiffLineNumber(old=21, new=None)),
])
def test_choose_closest_diff_line_normal(diff_line, expected):
comment_model = comment.ChangesetCommentsModel()
comment_model = comment.CommentsModel()
candidates = [
DiffLineNumber(old=2, new=None),
DiffLineNumber(old=21, new=None),
@ -82,7 +82,7 @@ def test_choose_closest_diff_line_normal(diff_line, expected):
def test_revision_comments_are_sorted():
comment_model = comment.ChangesetCommentsModel()
comment_model = comment.CommentsModel()
query = comment_model._get_inline_comments_query(
repo_id='fake_repo_name',
revision='fake_revision',
@ -92,15 +92,15 @@ def test_revision_comments_are_sorted():
@pytest.mark.parametrize('use_outdated', [True, False])
def test_pull_request_comments_are_sorted(use_outdated):
comment_model = comment.ChangesetCommentsModel()
comment_model = comment.CommentsModel()
pull_request = mock.Mock()
# TODO: johbo: Had to do this since we have an inline call to
# self.__get_pull_request. Should be moved out at some point.
get_instance_patcher = mock.patch.object(
comment.ChangesetCommentsModel, '_get_instance',
comment.CommentsModel, '_get_instance',
return_value=pull_request)
config_patcher = mock.patch.object(
comment.ChangesetCommentsModel, 'use_outdated_comments',
comment.CommentsModel, 'use_outdated_comments',
return_value=use_outdated)
with get_instance_patcher, config_patcher as config_mock:
@ -123,7 +123,7 @@ def assert_inline_comments_order(query):
def test_get_renderer():
model = comment.ChangesetCommentsModel()
model = comment.CommentsModel()
renderer = model._get_renderer()
assert renderer == "rst"
@ -137,7 +137,7 @@ class TestUseOutdatedComments(object):
'rhodecode_use_outdated_comments': use_outdated
}
with self._patch_settings(general_settings) as settings_mock:
result = comment.ChangesetCommentsModel.use_outdated_comments(
result = comment.CommentsModel.use_outdated_comments(
pull_request)
settings_mock.assert_called_once_with(repo=pull_request.target_repo)
assert result == use_outdated
@ -147,7 +147,7 @@ class TestUseOutdatedComments(object):
general_settings = {}
with self._patch_settings(general_settings) as settings_mock:
result = comment.ChangesetCommentsModel.use_outdated_comments(
result = comment.CommentsModel.use_outdated_comments(
pull_request)
settings_mock.assert_called_once_with(repo=pull_request.target_repo)
assert result is False

View file

@ -29,7 +29,7 @@ from rhodecode.lib.vcs.backends.base import (
MergeResponse, MergeFailureReason, Reference)
from rhodecode.lib.vcs.exceptions import RepositoryError
from rhodecode.lib.vcs.nodes import FileNode
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import PullRequest, Session
from rhodecode.model.pull_request import PullRequestModel
from rhodecode.model.user import UserModel
@ -811,13 +811,13 @@ def test_calculate_commits():
def assert_inline_comments(pull_request, visible=None, outdated=None):
if visible is not None:
inline_comments = ChangesetCommentsModel().get_inline_comments(
inline_comments = CommentsModel().get_inline_comments(
pull_request.target_repo.repo_id, pull_request=pull_request)
inline_cnt = ChangesetCommentsModel().get_inline_comments_count(
inline_cnt = CommentsModel().get_inline_comments_count(
inline_comments)
assert inline_cnt == visible
if outdated is not None:
outdated_comments = ChangesetCommentsModel().get_outdated_comments(
outdated_comments = CommentsModel().get_outdated_comments(
pull_request.target_repo.repo_id, pull_request)
assert len(outdated_comments) == outdated
@ -842,5 +842,5 @@ def assert_pr_file_changes(
def outdated_comments_patcher(use_outdated=True):
return mock.patch.object(
ChangesetCommentsModel, 'use_outdated_comments',
CommentsModel, 'use_outdated_comments',
return_value=use_outdated)

View file

@ -39,7 +39,7 @@ import requests
import rhodecode
from rhodecode.lib.utils2 import AttributeDict
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import ChangesetCommentsModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import (
PullRequest, Repository, RhodeCodeSetting, ChangesetStatus, RepoGroup,
UserGroup, RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi)
@ -1038,7 +1038,7 @@ class PRTestUtility(object):
return removed_commit_id
def create_comment(self, linked_to=None):
comment = ChangesetCommentsModel().create(
comment = CommentsModel().create(
text=u"Test comment",
repo=self.target_repository.repo_name,
user=self.author,
@ -1052,7 +1052,7 @@ class PRTestUtility(object):
def create_inline_comment(
self, linked_to=None, line_no=u'n1', file_path='file_1'):
comment = ChangesetCommentsModel().create(
comment = CommentsModel().create(
text=u"Test comment",
repo=self.target_repository.repo_name,
user=self.author,