# HG changeset patch # User Marcin Kuzminski # Date 2017-01-09 16:52:00 # Node ID 41333240544f95a40fb967cec5851824b5932939 # Parent 50f14062091fb4e24fd6299088bd41741eecfae0 comments: renamed ChangesetCommentsModel to CommentsModel to reflect what it actually does. It's not limited to Changesets/Commits. diff --git a/rhodecode/api/tests/test_comment_pull_request.py b/rhodecode/api/tests/test_comment_pull_request.py --- a/rhodecode/api/tests/test_comment_pull_request.py +++ b/rhodecode/api/tests/test_comment_pull_request.py @@ -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, diff --git a/rhodecode/api/views/pull_request_api.py b/rhodecode/api/views/pull_request_api.py --- a/rhodecode/api/views/pull_request_api.py +++ b/rhodecode/api/views/pull_request_api.py @@ -30,7 +30,7 @@ from rhodecode.lib.auth import (HasRepoP 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, apiuse 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, diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -34,7 +34,7 @@ from rhodecode.lib.exceptions import Sta 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, diff --git a/rhodecode/controllers/admin/my_account.py b/rhodecode/controllers/admin/my_account.py --- a/rhodecode/controllers/admin/my_account.py +++ b/rhodecode/controllers/admin/my_account.py @@ -57,7 +57,7 @@ from rhodecode.model.repo import RepoMod 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() diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -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(BaseRepoContro 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(BaseRepoContro 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(BaseRepoContro 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(BaseRepoContro 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: diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -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(BaseRepoCon _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(BaseRepoCon 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(BaseRepoCon # 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(BaseRepoCon 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(BaseRepoCon 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: diff --git a/rhodecode/events/pullrequest.py b/rhodecode/events/pullrequest.py --- a/rhodecode/events/pullrequest.py +++ b/rhodecode/events/pullrequest.py @@ -114,7 +114,7 @@ class PullRequestCommentEvent(PullReques 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(PullReques 'comment': { 'status': status, 'text': self.comment.text, - 'url': ChangesetCommentsModel().get_url(self.comment) + 'url': CommentsModel().get_url(self.comment) } }) return data diff --git a/rhodecode/model/changeset_status.py b/rhodecode/model/changeset_status.py --- a/rhodecode/model/changeset_status.py +++ b/rhodecode/model/changeset_status.py @@ -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, diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -48,7 +48,7 @@ from rhodecode.model.notification import 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) diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -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, diff --git a/rhodecode/tests/events/test_pullrequest.py b/rhodecode/tests/events/test_pullrequest.py --- a/rhodecode/tests/events/test_pullrequest.py +++ b/rhodecode/tests/events/test_pullrequest.py @@ -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_u @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() diff --git a/rhodecode/tests/models/test_comment.py b/rhodecode/tests/models/test_comment.py --- a/rhodecode/tests/models/test_comment.py +++ b/rhodecode/tests/models/test_comment.py @@ -72,7 +72,7 @@ def test_diff_to_comment_line_number(old (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 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 diff --git a/rhodecode/tests/models/test_pullrequest.py b/rhodecode/tests/models/test_pullrequest.py --- a/rhodecode/tests/models/test_pullrequest.py +++ b/rhodecode/tests/models/test_pullrequest.py @@ -29,7 +29,7 @@ from rhodecode.lib.vcs.backends.base imp 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) diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -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,