Merge pull request #382 from coreos-inc/manytags
Limit the number of branches and tags loaded to 30
This commit is contained in:
commit
b8bfed915d
2 changed files with 34 additions and 9 deletions
|
@ -461,6 +461,7 @@ class TriggerBuildList(RepositoryParamResource):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FIELD_VALUE_LIMIT = 30
|
||||||
|
|
||||||
@resource('/v1/repository/<repopath:repository>/trigger/<trigger_uuid>/fields/<field_name>')
|
@resource('/v1/repository/<repopath:repository>/trigger/<trigger_uuid>/fields/<field_name>')
|
||||||
@internal_only
|
@internal_only
|
||||||
|
@ -479,7 +480,7 @@ class BuildTriggerFieldValues(RepositoryParamResource):
|
||||||
user_permission = UserAdminPermission(trigger.connected_user.username)
|
user_permission = UserAdminPermission(trigger.connected_user.username)
|
||||||
if user_permission.can():
|
if user_permission.can():
|
||||||
handler = BuildTriggerHandler.get_handler(trigger, config)
|
handler = BuildTriggerHandler.get_handler(trigger, config)
|
||||||
values = handler.list_field_values(field_name)
|
values = handler.list_field_values(field_name, limit=FIELD_VALUE_LIMIT)
|
||||||
|
|
||||||
if values is None:
|
if values is None:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
|
|
@ -197,7 +197,7 @@ class BuildTriggerHandler(object):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def list_field_values(self, field_name):
|
def list_field_values(self, field_name, limit=None):
|
||||||
"""
|
"""
|
||||||
Lists all values for the given custom trigger field. For example, a trigger might have a
|
Lists all values for the given custom trigger field. For example, a trigger might have a
|
||||||
field named "branches", and this method would return all branches.
|
field named "branches", and this method would return all branches.
|
||||||
|
@ -434,7 +434,7 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def list_field_values(self, field_name):
|
def list_field_values(self, field_name, limit=None):
|
||||||
source = self.config['build_source']
|
source = self.config['build_source']
|
||||||
(namespace, name) = source.split('/')
|
(namespace, name) = source.split('/')
|
||||||
|
|
||||||
|
@ -457,14 +457,22 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return data.keys()
|
tags = list(data.keys())
|
||||||
|
if limit:
|
||||||
|
tags = tags[0:limit]
|
||||||
|
|
||||||
|
return tags
|
||||||
|
|
||||||
if field_name == 'branch_name':
|
if field_name == 'branch_name':
|
||||||
(result, data, _) = repository.get_branches()
|
(result, data, _) = repository.get_branches()
|
||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return data.keys()
|
branches = list(data.keys())
|
||||||
|
if limit:
|
||||||
|
branches = branches[0:limit]
|
||||||
|
|
||||||
|
return branches
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -1039,7 +1047,7 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
return self._prepare_build(ref, commit_sha, True, repo=repo)
|
return self._prepare_build(ref, commit_sha, True, repo=repo)
|
||||||
|
|
||||||
|
|
||||||
def list_field_values(self, field_name):
|
def list_field_values(self, field_name, limit=None):
|
||||||
if field_name == 'refs':
|
if field_name == 'refs':
|
||||||
branches = self.list_field_values('branch_name')
|
branches = self.list_field_values('branch_name')
|
||||||
tags = self.list_field_values('tag_name')
|
tags = self.list_field_values('tag_name')
|
||||||
|
@ -1053,7 +1061,11 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
gh_client = self._get_client()
|
gh_client = self._get_client()
|
||||||
source = config['build_source']
|
source = config['build_source']
|
||||||
repo = gh_client.get_repo(source)
|
repo = gh_client.get_repo(source)
|
||||||
return [tag.name for tag in repo.get_tags()]
|
gh_tags = repo.get_tags()
|
||||||
|
if limit:
|
||||||
|
gh_tags = repo.get_tags()[0:limit]
|
||||||
|
|
||||||
|
return [tag.name for tag in gh_tags]
|
||||||
except GitHubBadCredentialsException:
|
except GitHubBadCredentialsException:
|
||||||
return []
|
return []
|
||||||
except GithubException:
|
except GithubException:
|
||||||
|
@ -1066,7 +1078,11 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
||||||
gh_client = self._get_client()
|
gh_client = self._get_client()
|
||||||
source = config['build_source']
|
source = config['build_source']
|
||||||
repo = gh_client.get_repo(source)
|
repo = gh_client.get_repo(source)
|
||||||
branches = [branch.name for branch in repo.get_branches()]
|
gh_branches = repo.get_branches()
|
||||||
|
if limit:
|
||||||
|
gh_branches = repo.get_branches()[0:limit]
|
||||||
|
|
||||||
|
branches = [branch.name for branch in gh_branches]
|
||||||
|
|
||||||
if not repo.default_branch in branches:
|
if not repo.default_branch in branches:
|
||||||
branches.insert(0, repo.default_branch)
|
branches.insert(0, repo.default_branch)
|
||||||
|
@ -1417,7 +1433,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
|
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
def list_field_values(self, field_name):
|
def list_field_values(self, field_name, limit=None):
|
||||||
if field_name == 'refs':
|
if field_name == 'refs':
|
||||||
branches = self.list_field_values('branch_name')
|
branches = self.list_field_values('branch_name')
|
||||||
tags = self.list_field_values('tag_name')
|
tags = self.list_field_values('tag_name')
|
||||||
|
@ -1434,12 +1450,20 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
||||||
tags = gl_client.getrepositorytags(repo['id'])
|
tags = gl_client.getrepositorytags(repo['id'])
|
||||||
if tags is False:
|
if tags is False:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
tags = tags[0:limit]
|
||||||
|
|
||||||
return [tag['name'] for tag in tags]
|
return [tag['name'] for tag in tags]
|
||||||
|
|
||||||
if field_name == 'branch_name':
|
if field_name == 'branch_name':
|
||||||
branches = gl_client.getbranches(repo['id'])
|
branches = gl_client.getbranches(repo['id'])
|
||||||
if branches is False:
|
if branches is False:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
branches = branches[0:limit]
|
||||||
|
|
||||||
return [branch['name'] for branch in branches]
|
return [branch['name'] for branch in branches]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
Reference in a new issue