Merge "Paginate all the gitea get requests"
This commit is contained in:
commit
5c7804d4a5
@ -71,6 +71,18 @@ class Gitea(object):
|
||||
def get(self, endpoint, *args, **kwargs):
|
||||
return self.request('GET', endpoint, *args, **kwargs)
|
||||
|
||||
def get_paginated(self, endpoint, *args, **kwargs):
|
||||
params = { 'limit': 50, 'page': 1 }
|
||||
results = []
|
||||
gitea_data = self.get(endpoint, *args, params=params, **kwargs).json()
|
||||
while gitea_data:
|
||||
results.extend(gitea_data)
|
||||
# Gitea paginates and returns an empty list at the end of the
|
||||
# listing. 50 items is the max limit.
|
||||
params['page'] += 1
|
||||
gitea_data = self.get(endpoint, *args, params=params, **kwargs).json()
|
||||
return results
|
||||
|
||||
def post(self, endpoint, *args, **kwargs):
|
||||
return self.request('POST', endpoint, *args, **kwargs)
|
||||
|
||||
@ -78,7 +90,7 @@ class Gitea(object):
|
||||
return self.request('PUT', endpoint, *args, **kwargs)
|
||||
|
||||
def get_gitea_orgs(self):
|
||||
orgs = self.get("/api/v1/user/orgs").json()
|
||||
orgs = self.get_paginated("/api/v1/user/orgs")
|
||||
return [f['username'] for f in orgs]
|
||||
|
||||
def make_gitea_org(self, org):
|
||||
@ -88,33 +100,19 @@ class Gitea(object):
|
||||
self.log("Created org:", org)
|
||||
|
||||
def ensure_gitea_teams(self, org):
|
||||
team_list = self.get('/api/v1/orgs/{org}/teams'.format(org=org)).json()
|
||||
team_list = self.get_paginated('/api/v1/orgs/{org}/teams'.format(org=org))
|
||||
owner_id = [f['id'] for f in team_list if f['name'] == 'Owners'][0]
|
||||
|
||||
org_owners = self.get(
|
||||
org_owners = self.get_paginated(
|
||||
'/api/v1/teams/{owner_id}/members'.format(owner_id=owner_id))
|
||||
if 'gerrit' not in [f['username'] for f in org_owners.json()]:
|
||||
if 'gerrit' not in [f['username'] for f in org_owners]:
|
||||
self.put('/api/v1/teams/{owner_id}/members/gerrit'.format(
|
||||
owner_id=owner_id))
|
||||
self.log("Added gerrit to team:", org)
|
||||
|
||||
def get_org_repo_list(self, org):
|
||||
params = { 'limit': 50, 'page': 1 }
|
||||
repos = []
|
||||
gitea_data = self.get(
|
||||
'/api/v1/orgs/{org}/repos'.format(org=org),
|
||||
params=params
|
||||
).json()
|
||||
while gitea_data:
|
||||
repos.extend([x['full_name'] for x in gitea_data])
|
||||
# Gitea paginates and returns an empty list at the end of the
|
||||
# listing. 50 items is the max limit.
|
||||
params['page'] += 1
|
||||
gitea_data = self.get(
|
||||
'/api/v1/orgs/{org}/repos'.format(org=org),
|
||||
params=params
|
||||
).json()
|
||||
return repos
|
||||
return [x['full_name'] for x in
|
||||
self.get_paginated('/api/v1/orgs/{org}/repos'.format(org=org))]
|
||||
|
||||
def get_csrf_token(self):
|
||||
resp = self.get('/')
|
||||
|
Loading…
x
Reference in New Issue
Block a user