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