Show More
@@ -271,8 +271,8 b' def includeme(config):' | |||||
271 | repo_route=True) |
|
271 | repo_route=True) | |
272 |
|
272 | |||
273 | config.add_route( |
|
273 | config.add_route( | |
274 |
name='pullrequest_repo_ |
|
274 | name='pullrequest_repo_targets', | |
275 |
pattern='/{repo_name:.*?[^/]}/pull-request/repo- |
|
275 | pattern='/{repo_name:.*?[^/]}/pull-request/repo-targets', | |
276 | repo_route=True) |
|
276 | repo_route=True) | |
277 |
|
277 | |||
278 | config.add_route( |
|
278 | config.add_route( |
@@ -45,7 +45,7 b' def route_path(name, params=None, **kwar' | |||||
45 | 'pullrequest_show_all': '/{repo_name}/pull-request', |
|
45 | 'pullrequest_show_all': '/{repo_name}/pull-request', | |
46 | 'pullrequest_show_all_data': '/{repo_name}/pull-request-data', |
|
46 | 'pullrequest_show_all_data': '/{repo_name}/pull-request-data', | |
47 | 'pullrequest_repo_refs': '/{repo_name}/pull-request/refs/{target_repo_name:.*?[^/]}', |
|
47 | 'pullrequest_repo_refs': '/{repo_name}/pull-request/refs/{target_repo_name:.*?[^/]}', | |
48 |
'pullrequest_repo_ |
|
48 | 'pullrequest_repo_targets': '/{repo_name}/pull-request/repo-destinations', | |
49 | 'pullrequest_new': '/{repo_name}/pull-request/new', |
|
49 | 'pullrequest_new': '/{repo_name}/pull-request/new', | |
50 | 'pullrequest_create': '/{repo_name}/pull-request/create', |
|
50 | 'pullrequest_create': '/{repo_name}/pull-request/create', | |
51 | 'pullrequest_update': '/{repo_name}/pull-request/{pull_request_id}/update', |
|
51 | 'pullrequest_update': '/{repo_name}/pull-request/{pull_request_id}/update', |
@@ -812,37 +812,50 b' class RepoPullRequestsView(RepoAppView, ' | |||||
812 | @HasRepoPermissionAnyDecorator( |
|
812 | @HasRepoPermissionAnyDecorator( | |
813 | 'repository.read', 'repository.write', 'repository.admin') |
|
813 | 'repository.read', 'repository.write', 'repository.admin') | |
814 | @view_config( |
|
814 | @view_config( | |
815 |
route_name='pullrequest_repo_ |
|
815 | route_name='pullrequest_repo_targets', request_method='GET', | |
816 | renderer='json_ext', xhr=True) |
|
816 | renderer='json_ext', xhr=True) | |
817 |
def pull |
|
817 | def pullrequest_repo_targets(self): | |
818 | _ = self.request.translate |
|
818 | _ = self.request.translate | |
819 | filter_query = self.request.GET.get('query') |
|
819 | filter_query = self.request.GET.get('query') | |
820 |
|
820 | |||
821 | query = Repository.query() \ |
|
821 | # get the parents | |
|
822 | parent_target_repos = [] | |||
|
823 | if self.db_repo.parent: | |||
|
824 | parents_query = Repository.query() \ | |||
822 | .order_by(func.length(Repository.repo_name)) \ |
|
825 | .order_by(func.length(Repository.repo_name)) \ | |
823 | .filter( |
|
826 | .filter(Repository.fork_id == self.db_repo.parent.repo_id) | |
824 | or_(Repository.repo_name == self.db_repo.repo_name, |
|
|||
825 | Repository.fork_id == self.db_repo.repo_id)) |
|
|||
826 |
|
827 | |||
827 | if filter_query: |
|
828 | if filter_query: | |
828 | ilike_expression = u'%{}%'.format(safe_unicode(filter_query)) |
|
829 | ilike_expression = u'%{}%'.format(safe_unicode(filter_query)) | |
829 | query = query.filter( |
|
830 | parents_query = parents_query.filter( | |
830 | Repository.repo_name.ilike(ilike_expression)) |
|
831 | Repository.repo_name.ilike(ilike_expression)) | |
|
832 | parents = parents_query.limit(20).all() | |||
|
833 | ||||
|
834 | for parent in parents: | |||
|
835 | parent_vcs_obj = parent.scm_instance() | |||
|
836 | if parent_vcs_obj and not parent_vcs_obj.is_empty(): | |||
|
837 | parent_target_repos.append(parent) | |||
831 |
|
838 | |||
832 | add_parent = False |
|
839 | # get other forks, and repo itself | |
833 | if self.db_repo.parent: |
|
840 | query = Repository.query() \ | |
834 | if filter_query in self.db_repo.parent.repo_name: |
|
841 | .order_by(func.length(Repository.repo_name)) \ | |
835 | parent_vcs_obj = self.db_repo.parent.scm_instance() |
|
842 | .filter( | |
836 | if parent_vcs_obj and not parent_vcs_obj.is_empty(): |
|
843 | or_(Repository.repo_id == self.db_repo.repo_id, # repo itself | |
837 | add_parent = True |
|
844 | Repository.fork_id == self.db_repo.repo_id) # forks of this repo | |
|
845 | ) \ | |||
|
846 | .filter(~Repository.repo_id.in_([x.repo_id for x in parent_target_repos])) | |||
838 |
|
847 | |||
839 | limit = 20 - 1 if add_parent else 20 |
|
848 | if filter_query: | |
840 | all_repos = query.limit(limit).all() |
|
849 | ilike_expression = u'%{}%'.format(safe_unicode(filter_query)) | |
841 | if add_parent: |
|
850 | query = query.filter(Repository.repo_name.ilike(ilike_expression)) | |
842 | all_repos += [self.db_repo.parent] |
|
851 | ||
|
852 | limit = max(20 - len(parent_target_repos), 5) # not less then 5 | |||
|
853 | target_repos = query.limit(limit).all() | |||
|
854 | ||||
|
855 | all_target_repos = target_repos + parent_target_repos | |||
843 |
|
856 | |||
844 | repos = [] |
|
857 | repos = [] | |
845 | for obj in ScmModel().get_repos(all_repos): |
|
858 | for obj in ScmModel().get_repos(all_target_repos): | |
846 | repos.append({ |
|
859 | repos.append({ | |
847 | 'id': obj['name'], |
|
860 | 'id': obj['name'], | |
848 | 'text': obj['name'], |
|
861 | 'text': obj['name'], |
@@ -218,7 +218,7 b' function registerRCRoutes() {' | |||||
218 | pyroutes.register('pullrequest_show_all', '/%(repo_name)s/pull-request', ['repo_name']); |
|
218 | pyroutes.register('pullrequest_show_all', '/%(repo_name)s/pull-request', ['repo_name']); | |
219 | pyroutes.register('pullrequest_show_all_data', '/%(repo_name)s/pull-request-data', ['repo_name']); |
|
219 | pyroutes.register('pullrequest_show_all_data', '/%(repo_name)s/pull-request-data', ['repo_name']); | |
220 | pyroutes.register('pullrequest_repo_refs', '/%(repo_name)s/pull-request/refs/%(target_repo_name)s', ['repo_name', 'target_repo_name']); |
|
220 | pyroutes.register('pullrequest_repo_refs', '/%(repo_name)s/pull-request/refs/%(target_repo_name)s', ['repo_name', 'target_repo_name']); | |
221 |
pyroutes.register('pullrequest_repo_ |
|
221 | pyroutes.register('pullrequest_repo_targets', '/%(repo_name)s/pull-request/repo-targets', ['repo_name']); | |
222 | pyroutes.register('pullrequest_new', '/%(repo_name)s/pull-request/new', ['repo_name']); |
|
222 | pyroutes.register('pullrequest_new', '/%(repo_name)s/pull-request/new', ['repo_name']); | |
223 | pyroutes.register('pullrequest_create', '/%(repo_name)s/pull-request/create', ['repo_name']); |
|
223 | pyroutes.register('pullrequest_create', '/%(repo_name)s/pull-request/create', ['repo_name']); | |
224 | pyroutes.register('pullrequest_update', '/%(repo_name)s/pull-request/%(pull_request_id)s/update', ['repo_name', 'pull_request_id']); |
|
224 | pyroutes.register('pullrequest_update', '/%(repo_name)s/pull-request/%(pull_request_id)s/update', ['repo_name', 'pull_request_id']); |
@@ -257,7 +257,7 b'' | |||||
257 | query.callback({results: cachedData.results}); |
|
257 | query.callback({results: cachedData.results}); | |
258 | } else { |
|
258 | } else { | |
259 | $.ajax({ |
|
259 | $.ajax({ | |
260 |
url: pyroutes.url('pullrequest_repo_ |
|
260 | url: pyroutes.url('pullrequest_repo_targets', {'repo_name': templateContext.repo_name}), | |
261 | data: {query: query.term}, |
|
261 | data: {query: query.term}, | |
262 | dataType: 'json', |
|
262 | dataType: 'json', | |
263 | type: 'GET', |
|
263 | type: 'GET', |
General Comments 0
You need to be logged in to leave comments.
Login now