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>')
|
||||
@internal_only
|
||||
|
@ -479,7 +480,7 @@ class BuildTriggerFieldValues(RepositoryParamResource):
|
|||
user_permission = UserAdminPermission(trigger.connected_user.username)
|
||||
if user_permission.can():
|
||||
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:
|
||||
raise NotFound()
|
||||
|
|
|
@ -197,7 +197,7 @@ class BuildTriggerHandler(object):
|
|||
"""
|
||||
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
|
||||
field named "branches", and this method would return all branches.
|
||||
|
@ -434,7 +434,7 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
return data
|
||||
|
||||
def list_field_values(self, field_name):
|
||||
def list_field_values(self, field_name, limit=None):
|
||||
source = self.config['build_source']
|
||||
(namespace, name) = source.split('/')
|
||||
|
||||
|
@ -457,14 +457,22 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
|||
if not result:
|
||||
return None
|
||||
|
||||
return data.keys()
|
||||
tags = list(data.keys())
|
||||
if limit:
|
||||
tags = tags[0:limit]
|
||||
|
||||
return tags
|
||||
|
||||
if field_name == 'branch_name':
|
||||
(result, data, _) = repository.get_branches()
|
||||
if not result:
|
||||
return None
|
||||
|
||||
return data.keys()
|
||||
branches = list(data.keys())
|
||||
if limit:
|
||||
branches = branches[0:limit]
|
||||
|
||||
return branches
|
||||
|
||||
return None
|
||||
|
||||
|
@ -1039,7 +1047,7 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
|||
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':
|
||||
branches = self.list_field_values('branch_name')
|
||||
tags = self.list_field_values('tag_name')
|
||||
|
@ -1053,7 +1061,11 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
|||
gh_client = self._get_client()
|
||||
source = config['build_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:
|
||||
return []
|
||||
except GithubException:
|
||||
|
@ -1066,7 +1078,11 @@ class GithubBuildTrigger(BuildTriggerHandler):
|
|||
gh_client = self._get_client()
|
||||
source = config['build_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:
|
||||
branches.insert(0, repo.default_branch)
|
||||
|
@ -1417,7 +1433,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
|
||||
return contents
|
||||
|
||||
def list_field_values(self, field_name):
|
||||
def list_field_values(self, field_name, limit=None):
|
||||
if field_name == 'refs':
|
||||
branches = self.list_field_values('branch_name')
|
||||
tags = self.list_field_values('tag_name')
|
||||
|
@ -1434,12 +1450,20 @@ class GitLabBuildTrigger(BuildTriggerHandler):
|
|||
tags = gl_client.getrepositorytags(repo['id'])
|
||||
if tags is False:
|
||||
return []
|
||||
|
||||
if limit:
|
||||
tags = tags[0:limit]
|
||||
|
||||
return [tag['name'] for tag in tags]
|
||||
|
||||
if field_name == 'branch_name':
|
||||
branches = gl_client.getbranches(repo['id'])
|
||||
if branches is False:
|
||||
return []
|
||||
|
||||
if limit:
|
||||
branches = branches[0:limit]
|
||||
|
||||
return [branch['name'] for branch in branches]
|
||||
|
||||
return None
|
||||
|
|
Reference in a new issue