4141import sonar .platform as pf
4242
4343from sonar .util import types , cache
44+ from sonar .util import project_utils as putils
45+
4446from sonar import exceptions , errcodes
4547from sonar import sqobject , components , qualitygates , qualityprofiles , tasks , settings , webhooks , devops
4648import sonar .permissions .permissions as perms
@@ -1443,14 +1445,22 @@ def count(endpoint: pf.Platform, params: types.ApiParams = None) -> int:
14431445def search (endpoint : pf .Platform , params : types .ApiParams = None , threads : int = 8 ) -> dict [str , Project ]:
14441446 """Searches projects in SonarQube
14451447
1446- :param endpoint: Reference to the SonarQube platform
1447- :param params: list of parameters to narrow down the search
1448- :returns: list of projects
1448+ :param Platform endpoint: Reference to the SonarQube platform
1449+ :param ApiParams params: list of filter parameters to narrow down the search
1450+ :param int threads: Number of threads to use for the search
14491451 """
14501452 new_params = {} if params is None else params .copy ()
1451- if not endpoint .is_sonarcloud ():
1453+ if not endpoint .is_sonarcloud () and not new_params . get ( "filter" , None ) :
14521454 new_params ["filter" ] = _PROJECT_QUALIFIER
1453- return sqobject .search_objects (endpoint = endpoint , object_class = Project , params = new_params , threads = threads )
1455+ try :
1456+ log .info ("Searching projects with parameters: %s" , str (new_params ))
1457+ return sqobject .search_objects (endpoint = endpoint , object_class = Project , params = new_params , threads = threads )
1458+ except exceptions .TooManyResults as e :
1459+ log .warning (e .message )
1460+ filter_1 , filter_2 = putils .split_loc_filter (new_params ["filter" ])
1461+ return search (endpoint , params = {** new_params , "filter" : filter_1 }, threads = threads ) | search (
1462+ endpoint , params = {** new_params , "filter" : filter_2 }, threads = threads
1463+ )
14541464
14551465
14561466def get_list (endpoint : pf .Platform , key_list : types .KeyList = None , threads : int = 8 , use_cache : bool = True ) -> dict [str , Project ]:
@@ -1461,8 +1471,8 @@ def get_list(endpoint: pf.Platform, key_list: types.KeyList = None, threads: int
14611471 :return: the list of all projects
14621472 :rtype: dict{key: Project}
14631473 """
1464- with _CLASS_LOCK :
1465- if key_list is None or len ( key_list ) == 0 or not use_cache :
1474+ if key_list is None or len ( key_list ) == 0 or not use_cache :
1475+ with _CLASS_LOCK :
14661476 log .info ("Listing projects" )
14671477 p_list = dict (sorted (search (endpoint = endpoint , threads = threads ).items ()))
14681478 return p_list
0 commit comments