Mercurial > kallithea
comparison rhodecode/model/comment.py @ 2440:1bc579bcd67a codereview
- pull request generates overview based on it's params
- added page to show all pull-requests for a repository
- db schema changes to support comments and inline comments for pull-requests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 10 Jun 2012 18:15:00 +0200 |
parents | ad19dfcdb1cc |
children | fd0a822481ec |
comparison
equal
deleted
inserted
replaced
2439:ad19dfcdb1cc | 2440:1bc579bcd67a |
---|---|
30 from sqlalchemy.util.compat import defaultdict | 30 from sqlalchemy.util.compat import defaultdict |
31 | 31 |
32 from rhodecode.lib.utils2 import extract_mentioned_users, safe_unicode | 32 from rhodecode.lib.utils2 import extract_mentioned_users, safe_unicode |
33 from rhodecode.lib import helpers as h | 33 from rhodecode.lib import helpers as h |
34 from rhodecode.model import BaseModel | 34 from rhodecode.model import BaseModel |
35 from rhodecode.model.db import ChangesetComment, User, Repository, Notification | 35 from rhodecode.model.db import ChangesetComment, User, Repository, \ |
36 Notification, PullRequest | |
36 from rhodecode.model.notification import NotificationModel | 37 from rhodecode.model.notification import NotificationModel |
37 | 38 |
38 log = logging.getLogger(__name__) | 39 log = logging.getLogger(__name__) |
39 | 40 |
40 | 41 |
41 class ChangesetCommentsModel(BaseModel): | 42 class ChangesetCommentsModel(BaseModel): |
42 | 43 |
43 def __get_changeset_comment(self, changeset_comment): | 44 def __get_changeset_comment(self, changeset_comment): |
44 return self._get_instance(ChangesetComment, changeset_comment) | 45 return self._get_instance(ChangesetComment, changeset_comment) |
46 | |
47 def __get_pull_request(self, pull_request): | |
48 return self._get_instance(PullRequest, pull_request) | |
45 | 49 |
46 def _extract_mentions(self, s): | 50 def _extract_mentions(self, s): |
47 user_objects = [] | 51 user_objects = [] |
48 for username in extract_mentioned_users(s): | 52 for username in extract_mentioned_users(s): |
49 user_obj = User.get_by_username(username, case_insensitive=True) | 53 user_obj = User.get_by_username(username, case_insensitive=True) |
133 comment = self.__get_changeset_comment(comment) | 137 comment = self.__get_changeset_comment(comment) |
134 self.sa.delete(comment) | 138 self.sa.delete(comment) |
135 | 139 |
136 return comment | 140 return comment |
137 | 141 |
138 def get_comments(self, repo_id, revision=None, pull_request_id=None): | 142 def get_comments(self, repo_id, revision=None, pull_request=None): |
139 """ | 143 """ |
140 Get's main comments based on revision or pull_request_id | 144 Get's main comments based on revision or pull_request_id |
141 | 145 |
142 :param repo_id: | 146 :param repo_id: |
143 :type repo_id: | 147 :type repo_id: |
144 :param revision: | 148 :param revision: |
145 :type revision: | 149 :type revision: |
146 :param pull_request_id: | 150 :param pull_request: |
147 :type pull_request_id: | 151 :type pull_request: |
148 """ | 152 """ |
153 | |
149 q = ChangesetComment.query()\ | 154 q = ChangesetComment.query()\ |
150 .filter(ChangesetComment.repo_id == repo_id)\ | 155 .filter(ChangesetComment.repo_id == repo_id)\ |
151 .filter(ChangesetComment.line_no == None)\ | 156 .filter(ChangesetComment.line_no == None)\ |
152 .filter(ChangesetComment.f_path == None) | 157 .filter(ChangesetComment.f_path == None) |
153 if revision: | 158 if revision: |
154 q = q.filter(ChangesetComment.revision == revision) | 159 q = q.filter(ChangesetComment.revision == revision) |
155 elif pull_request_id: | 160 elif pull_request: |
156 q = q.filter(ChangesetComment.pull_request_id == pull_request_id) | 161 pull_request = self.__get_pull_request(pull_request) |
162 q = q.filter(ChangesetComment.pull_request == pull_request) | |
157 else: | 163 else: |
158 raise Exception('Please specify revision or pull_request_id') | 164 raise Exception('Please specify revision or pull_request') |
159 return q.all() | 165 return q.all() |
160 | 166 |
161 def get_inline_comments(self, repo_id, revision=None, pull_request_id=None): | 167 def get_inline_comments(self, repo_id, revision=None, pull_request=None): |
162 q = self.sa.query(ChangesetComment)\ | 168 q = self.sa.query(ChangesetComment)\ |
163 .filter(ChangesetComment.repo_id == repo_id)\ | 169 .filter(ChangesetComment.repo_id == repo_id)\ |
164 .filter(ChangesetComment.line_no != None)\ | 170 .filter(ChangesetComment.line_no != None)\ |
165 .filter(ChangesetComment.f_path != None)\ | 171 .filter(ChangesetComment.f_path != None)\ |
166 .order_by(ChangesetComment.comment_id.asc())\ | 172 .order_by(ChangesetComment.comment_id.asc())\ |
167 | 173 |
168 if revision: | 174 if revision: |
169 q = q.filter(ChangesetComment.revision == revision) | 175 q = q.filter(ChangesetComment.revision == revision) |
170 elif pull_request_id: | 176 elif pull_request: |
171 q = q.filter(ChangesetComment.pull_request_id == pull_request_id) | 177 pull_request = self.__get_pull_request(pull_request) |
178 q = q.filter(ChangesetComment.pull_request == pull_request) | |
172 else: | 179 else: |
173 raise Exception('Please specify revision or pull_request_id') | 180 raise Exception('Please specify revision or pull_request_id') |
174 | 181 |
175 comments = q.all() | 182 comments = q.all() |
176 | 183 |