Fix a problem with initdb and add a limit to the builds API.
This commit is contained in:
parent
5f0969778e
commit
fde96c736a
4 changed files with 14 additions and 16 deletions
|
@ -1395,7 +1395,7 @@ def load_token_data(code):
|
|||
|
||||
def get_repository_build(namespace_name, repository_name, build_uuid):
|
||||
try:
|
||||
query = list_repository_builds(namespace_name, repository_name)
|
||||
query = list_repository_builds(namespace_name, repository_name, 1)
|
||||
return query.where(RepositoryBuild.uuid == build_uuid).get()
|
||||
|
||||
except RepositoryBuild.DoesNotExist:
|
||||
|
@ -1403,7 +1403,7 @@ def get_repository_build(namespace_name, repository_name, build_uuid):
|
|||
raise InvalidRepositoryBuildException(msg)
|
||||
|
||||
|
||||
def list_repository_builds(namespace_name, repository_name,
|
||||
def list_repository_builds(namespace_name, repository_name, limit,
|
||||
include_inactive=True):
|
||||
query = (RepositoryBuild
|
||||
.select(RepositoryBuild, RepositoryBuildTrigger, BuildTriggerService)
|
||||
|
@ -1412,7 +1412,8 @@ def list_repository_builds(namespace_name, repository_name,
|
|||
.join(RepositoryBuildTrigger, JOIN_LEFT_OUTER)
|
||||
.join(BuildTriggerService, JOIN_LEFT_OUTER)
|
||||
.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name))
|
||||
Repository.namespace == namespace_name)
|
||||
.limit(limit))
|
||||
|
||||
if not include_inactive:
|
||||
query = query.where(RepositoryBuild.phase != 'error',
|
||||
|
@ -1537,11 +1538,6 @@ def list_build_triggers(namespace_name, repository_name):
|
|||
|
||||
|
||||
def list_trigger_builds(namespace_name, repository_name, trigger_uuid,
|
||||
limit=None):
|
||||
query = (list_repository_builds(namespace_name, repository_name)
|
||||
limit):
|
||||
query = (list_repository_builds(namespace_name, repository_name, limit)
|
||||
.where(RepositoryBuildTrigger.uuid == trigger_uuid))
|
||||
|
||||
if limit:
|
||||
return query.limit(limit)
|
||||
else:
|
||||
return query
|
||||
|
|
|
@ -1105,7 +1105,7 @@ def get_repo(namespace, repository):
|
|||
tag_dict = {tag.name: tag_view(tag) for tag in tags}
|
||||
can_write = ModifyRepositoryPermission(namespace, repository).can()
|
||||
can_admin = AdministerRepositoryPermission(namespace, repository).can()
|
||||
active_builds = model.list_repository_builds(namespace, repository,
|
||||
active_builds = model.list_repository_builds(namespace, repository, 1,
|
||||
include_inactive=False)
|
||||
|
||||
return jsonify({
|
||||
|
@ -1160,9 +1160,11 @@ def build_status_view(build_obj, can_write=False):
|
|||
def get_repo_builds(namespace, repository):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
is_public = model.repository_is_public(namespace, repository)
|
||||
if permission.can() or is_public:
|
||||
if permission.can() or is_public:
|
||||
limit = request.args.get('limit', 5)
|
||||
builds = list(model.list_repository_builds(namespace, repository, limit))
|
||||
|
||||
can_write = ModifyRepositoryPermission(namespace, repository).can()
|
||||
builds = model.list_repository_builds(namespace, repository)
|
||||
return jsonify({
|
||||
'builds': [build_status_view(build, can_write) for build in builds]
|
||||
})
|
||||
|
@ -1501,8 +1503,8 @@ def list_trigger_recent_builds(namespace, repository, trigger_uuid):
|
|||
permission = AdministerRepositoryPermission(namespace, repository)
|
||||
if permission.can():
|
||||
limit = request.args.get('limit', 5)
|
||||
builds = model.list_trigger_builds(namespace, repository, trigger_uuid,
|
||||
limit)
|
||||
builds = list(model.list_trigger_builds(namespace, repository,
|
||||
trigger_uuid, limit))
|
||||
return jsonify({
|
||||
'builds': [build_status_view(build, True) for build in builds]
|
||||
})
|
||||
|
|
|
@ -328,7 +328,7 @@ def populate_database():
|
|||
'build_subdir': '',
|
||||
}
|
||||
build = model.create_repository_build(building, token, job_config,
|
||||
'701dcc3724fb4f2ea6c31400528343cd'
|
||||
'701dcc3724fb4f2ea6c31400528343cd',
|
||||
'build-name', trigger)
|
||||
build.uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
||||
build.save()
|
||||
|
|
Binary file not shown.
Reference in a new issue