4040import sonar .platform as pf
4141
4242from sonar .util import types , cache
43+ from sonar .util import project_utils as putils
44+
4345from sonar import exceptions , errcodes
4446from sonar import sqobject , components , qualitygates , qualityprofiles , tasks , settings , webhooks , devops
4547import sonar .permissions .permissions as perms
@@ -1357,14 +1359,22 @@ def count(endpoint: pf.Platform, params: types.ApiParams = None) -> int:
13571359def search (endpoint : pf .Platform , params : types .ApiParams = None , threads : int = 8 ) -> dict [str , Project ]:
13581360 """Searches projects in SonarQube
13591361
1360- :param endpoint: Reference to the SonarQube platform
1361- :param params: list of parameters to narrow down the search
1362- :returns: list of projects
1362+ :param Platform endpoint: Reference to the SonarQube platform
1363+ :param ApiParams params: list of filter parameters to narrow down the search
1364+ :param int threads: Number of threads to use for the search
13631365 """
13641366 new_params = {} if params is None else params .copy ()
1365- if not endpoint .is_sonarcloud ():
1367+ if not endpoint .is_sonarcloud () and not new_params . get ( "filter" , None ) :
13661368 new_params ["filter" ] = _PROJECT_QUALIFIER
1367- return sqobject .search_objects (endpoint = endpoint , object_class = Project , params = new_params , threads = threads )
1369+ try :
1370+ log .info ("Searching projects with parameters: %s" , str (new_params ))
1371+ return sqobject .search_objects (endpoint = endpoint , object_class = Project , params = new_params , threads = threads )
1372+ except exceptions .TooManyResults as e :
1373+ log .warning (e .message )
1374+ filter_1 , filter_2 = putils .split_loc_filter (new_params ["filter" ])
1375+ return search (endpoint , params = {** new_params , "filter" : filter_1 }, threads = threads ) | search (
1376+ endpoint , params = {** new_params , "filter" : filter_2 }, threads = threads
1377+ )
13681378
13691379
13701380def get_list (endpoint : pf .Platform , key_list : types .KeyList = None , threads : int = 8 , use_cache : bool = True ) -> dict [str , Project ]:
@@ -1375,8 +1385,8 @@ def get_list(endpoint: pf.Platform, key_list: types.KeyList = None, threads: int
13751385 :return: the list of all projects
13761386 :rtype: dict{key: Project}
13771387 """
1378- with _CLASS_LOCK :
1379- if key_list is None or len ( key_list ) == 0 or not use_cache :
1388+ if key_list is None or len ( key_list ) == 0 or not use_cache :
1389+ with _CLASS_LOCK :
13801390 log .info ("Listing projects" )
13811391 p_list = dict (sorted (search (endpoint = endpoint , threads = threads ).items ()))
13821392 return p_list
0 commit comments