##// END OF EJS Templates
quick-search: added ability to search for pull-requests using `pr:` prefix....
marcink -
r4329:4543620f default
parent child Browse files
Show More
@@ -35,8 +35,8 b' from rhodecode.lib.index import searcher'
35 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
35 from rhodecode.lib.utils2 import safe_unicode, str2bool, safe_int
36 from rhodecode.lib.vcs.nodes import FileNode
36 from rhodecode.lib.vcs.nodes import FileNode
37 from rhodecode.model.db import (
37 from rhodecode.model.db import (
38 func, true, or_, case, in_filter_generator, Session,
38 func, true, or_, case, cast, in_filter_generator, String, Session,
39 Repository, RepoGroup, User, UserGroup)
39 Repository, RepoGroup, User, UserGroup, PullRequest)
40 from rhodecode.model.repo import RepoModel
40 from rhodecode.model.repo import RepoModel
41 from rhodecode.model.repo_group import RepoGroupModel
41 from rhodecode.model.repo_group import RepoGroupModel
42 from rhodecode.model.user import UserModel
42 from rhodecode.model.user import UserModel
@@ -111,7 +111,7 b' class HomeView(BaseAppView, DataGridAppV'
111 org_query = name_contains
111 org_query = name_contains
112 allowed_ids = self._rhodecode_user.repo_acl_ids(
112 allowed_ids = self._rhodecode_user.repo_acl_ids(
113 ['repository.read', 'repository.write', 'repository.admin'],
113 ['repository.read', 'repository.write', 'repository.admin'],
114 cache=False, name_filter=name_contains) or [-1]
114 cache=True, name_filter=name_contains) or [-1]
115
115
116 query = Session().query(
116 query = Session().query(
117 Repository.repo_name,
117 Repository.repo_name,
@@ -162,7 +162,7 b' class HomeView(BaseAppView, DataGridAppV'
162 org_query = name_contains
162 org_query = name_contains
163 allowed_ids = self._rhodecode_user.repo_group_acl_ids(
163 allowed_ids = self._rhodecode_user.repo_group_acl_ids(
164 ['group.read', 'group.write', 'group.admin'],
164 ['group.read', 'group.write', 'group.admin'],
165 cache=False, name_filter=name_contains) or [-1]
165 cache=True, name_filter=name_contains) or [-1]
166
166
167 query = Session().query(
167 query = Session().query(
168 RepoGroup.group_id,
168 RepoGroup.group_id,
@@ -282,6 +282,61 b' class HomeView(BaseAppView, DataGridAppV'
282 }
282 }
283 for obj in acl_iter], True
283 for obj in acl_iter], True
284
284
285 def _get_pull_request_list(self, name_contains=None, limit=20):
286 org_query = name_contains
287 if not name_contains:
288 return [], False
289
290 # TODO(marcink): should all logged in users be allowed to search others?
291 allowed_user_search = self._rhodecode_user.username != User.DEFAULT_USER
292 if not allowed_user_search:
293 return [], False
294
295 name_contains = re.compile('(?:pr:[ ]?)(.+)').findall(name_contains)
296 if len(name_contains) != 1:
297 return [], False
298
299 name_contains = name_contains[0]
300
301 allowed_ids = self._rhodecode_user.repo_acl_ids(
302 ['repository.read', 'repository.write', 'repository.admin'],
303 cache=True) or [-1]
304
305 query = Session().query(
306 PullRequest.pull_request_id,
307 PullRequest.title,
308 )
309 query = query.join(Repository, Repository.repo_id == PullRequest.target_repo_id)
310
311 query = query.filter(or_(
312 # generate multiple IN to fix limitation problems
313 *in_filter_generator(Repository.repo_id, allowed_ids)
314 ))
315
316 query = query.order_by(PullRequest.pull_request_id)
317
318 if name_contains:
319 ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
320 query = query.filter(or_(
321 cast(PullRequest.pull_request_id, String).ilike(ilike_expression),
322 PullRequest.title.ilike(ilike_expression),
323 PullRequest.description.ilike(ilike_expression),
324 ))
325
326 query = query.limit(limit)
327
328 acl_iter = query
329
330 return [
331 {
332 'id': obj.pull_request_id,
333 'value': org_query,
334 'value_display': 'pull request: `!{} - {}`'.format(obj.pull_request_id, obj.title[:50]),
335 'type': 'pull_request',
336 'url': h.route_path('pull_requests_global', pull_request_id=obj.pull_request_id)
337 }
338 for obj in acl_iter], True
339
285 def _get_hash_commit_list(self, auth_user, searcher, query, repo=None, repo_group=None):
340 def _get_hash_commit_list(self, auth_user, searcher, query, repo=None, repo_group=None):
286 repo_name = repo_group_name = None
341 repo_name = repo_group_name = None
287 if repo:
342 if repo:
@@ -624,6 +679,17 b' class HomeView(BaseAppView, DataGridAppV'
624 has_specialized_search = True
679 has_specialized_search = True
625 res.append(no_match('No matching user groups found'))
680 res.append(no_match('No matching user groups found'))
626
681
682 # pr: type search
683 if not prefix_match:
684 pull_requests, prefix_match = self._get_pull_request_list(query)
685 if pull_requests:
686 has_specialized_search = True
687 for serialized_pull_request in pull_requests:
688 res.append(serialized_pull_request)
689 elif prefix_match:
690 has_specialized_search = True
691 res.append(no_match('No matching pull requests found'))
692
627 # FTS commit: type search
693 # FTS commit: type search
628 if not prefix_match:
694 if not prefix_match:
629 commits, prefix_match = self._get_hash_commit_list(
695 commits, prefix_match = self._get_hash_commit_list(
@@ -783,6 +783,8 b''
783
783
784 user_group:devops, to search for user groups, always global
784 user_group:devops, to search for user groups, always global
785
785
786 pr:303, to search for pull request number, title, or description, always global
787
786 commit:efced4, to search for commits, scoped to repositories or groups
788 commit:efced4, to search for commits, scoped to repositories or groups
787
789
788 file:models.py, to search for file paths, scoped to repositories or groups
790 file:models.py, to search for file paths, scoped to repositories or groups
@@ -975,6 +977,10 b''
975 else if (searchType === 'user') {
977 else if (searchType === 'user') {
976 icon += '<img class="gravatar" src="{0}"/>'.format(data['icon_link']);
978 icon += '<img class="gravatar" src="{0}"/>'.format(data['icon_link']);
977 }
979 }
980 // pull request
981 else if (searchType === 'pull_request') {
982 icon += '<i class="icon-merge"></i> ';
983 }
978 // commit
984 // commit
979 else if (searchType === 'commit') {
985 else if (searchType === 'commit') {
980 var repo_data = data['repo_data'];
986 var repo_data = data['repo_data'];
General Comments 0
You need to be logged in to leave comments. Login now