@@ -541,18 +541,7 @@ def repo_all_list(self, project_key):
541541 else :
542542 url = 'rest/api/2.0/projects/{projectKey}/repos' .format (projectKey = project_key )
543543 params = {}
544- start = 0
545- params ['start' ] = start
546- response = self .get (url , params = params )
547- if 'values' not in response :
548- return []
549- repo_list = (response or {}).get ('values' )
550- while not response .get ('isLastPage' ):
551- start = response .get ('nextPageStart' )
552- params ['start' ] = start
553- response = self .get (url , params = params )
554- repo_list += (response or {}).get ('values' )
555- return repo_list
544+ return self ._get_paged (url , params )
556545
557546 def delete_repo (self , project_key , repository_slug ):
558547 """
@@ -1090,7 +1079,7 @@ def update_pull_request_comment(self, project, repository, pull_request_id, comm
10901079 }
10911080 return self .put (url , data = payload )
10921081
1093- def get_pullrequest (self , project , repository , pull_request_id ):
1082+ def get_pull_request (self , project , repository , pull_request_id ):
10941083 """
10951084 Retrieve a pull request.
10961085 The authenticated user must have REPO_READ permission
@@ -1108,6 +1097,12 @@ def get_pullrequest(self, project, repository, pull_request_id):
11081097 project = project , repository = repository , pullRequestId = pull_request_id )
11091098 return self .get (url )
11101099
1100+ def get_pullrequest (self , * args , ** kwargs ):
1101+ """
1102+ Deprecated name since 1.15.1. Let's use the get_pull_request()
1103+ """
1104+ return self .get_pull_request (* args , ** kwargs )
1105+
11111106 def change_reviewed_status (self , project_key , repository_slug , pull_request_id , status , user_slug ):
11121107 """
11131108 Change the current user's status for a pull request.
@@ -1435,9 +1430,7 @@ def get_branches_permissions(self, project, repository=None, start=0, limit=25):
14351430 project = project ,
14361431 repository = repository )
14371432 else :
1438- url = 'rest/branch-permissions/2.0/projects/{project}/restrictions' .format (
1439- project = project )
1440-
1433+ url = 'rest/branch-permissions/2.0/projects/{project}/restrictions' .format (project = project )
14411434 params = {}
14421435 if limit :
14431436 params ['limit' ] = limit
@@ -1900,6 +1893,18 @@ def create_code_insights_report(self, project_key, repository_slug, commit_id, r
19001893 data .update (report_params )
19011894 return self .put (url , data = data )
19021895
1896+ def search_code (self , team , search_query , page = 1 , limit = 10 ):
1897+ """
1898+ Search repositories for matching code
1899+ :team: str
1900+ :search_query: str
1901+ """
1902+ endpoint = 'rest/api/1.0'
1903+ if self .cloud :
1904+ endpoint = 'rest/api/2.0'
1905+ url = "{endpoint}/teams/{team}/search/code" .format (endpoint = endpoint , team = team )
1906+ return self .get (url , params = {'search_query' : search_query , 'page' : page , 'pagelen' : limit })
1907+
19031908 def get_lfs_repo_status (self , project_key , repo ):
19041909 url = 'rest/git-lfs/git-lfs/admin/projects/{projectKey}/repos/{repositorySlug}/enabled' .format (
19051910 projectKey = project_key ,
@@ -1917,3 +1922,21 @@ def get_users(self, user_filter=None):
19171922 if user_filter :
19181923 params ['filter' ] = user_filter
19191924 return self .get (url , params = params )
1925+
1926+ def _get_paged (self , url , params ):
1927+ """
1928+ Use for get all methods
1929+ :param url:
1930+ :param params:
1931+ :return:
1932+ """
1933+ params ['start' ] = 0
1934+ response = self .get (url , params = params )
1935+ if 'values' not in response :
1936+ return []
1937+ values = response .get ('values' )
1938+ while not response .get ('isLastPage' ):
1939+ params ['start' ] = response .get ('nextPageStart' )
1940+ response = self .get (url , params = params )
1941+ values += response .get ('values' )
1942+ return values
0 commit comments