Add a build sample (#22)
This commit is contained in:
Родитель
e780e5c36b
Коммит
61ab7c47c8
|
@ -0,0 +1,43 @@
|
|||
"""
|
||||
Build samples.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from samples import resource
|
||||
from utils import emit, find_any_project, find_any_build_definition
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@resource('definition')
|
||||
def get_definitions(context):
|
||||
project = find_any_project(context)
|
||||
emit(project.name)
|
||||
build_client = context.connection.clients.get_build_client()
|
||||
|
||||
definitions = build_client.get_definitions(project.id)
|
||||
|
||||
for definition in definitions:
|
||||
emit(str(definition.id) + ": " + definition.name)
|
||||
|
||||
return definitions
|
||||
|
||||
|
||||
@resource('build')
|
||||
def queue_build(context):
|
||||
definition = find_any_build_definition(context)
|
||||
|
||||
build_client = context.connection.clients.get_build_client()
|
||||
|
||||
build = {
|
||||
'definition': {
|
||||
'id': definition.id
|
||||
}
|
||||
}
|
||||
|
||||
response = build_client.queue_build(build=build, project=definition.project.id)
|
||||
|
||||
emit(str(response.id) + ": " + response.url)
|
||||
|
||||
return response
|
20
src/utils.py
20
src/utils.py
|
@ -52,3 +52,23 @@ def find_any_repo(context):
|
|||
return context.runner_cache.repo
|
||||
except IndexError:
|
||||
raise AccountStateError('Project "%s" doesn''t appear to have any repos.' % (project.name,))
|
||||
|
||||
|
||||
def find_any_build_definition(context):
|
||||
logger.debug('finding any build definition')
|
||||
|
||||
# if a repo is cached, use it
|
||||
if hasattr(context.runner_cache, 'build_definition'):
|
||||
logger.debug('using cached definition %s', context.runner_cache.build_definition.name)
|
||||
return context.runner_cache.build_definition
|
||||
|
||||
with http_logging.temporarily_disabled():
|
||||
project = find_any_project(context)
|
||||
build_client = context.connection.clients.get_build_client()
|
||||
definitions = build_client.get_definitions(project.id)
|
||||
|
||||
try:
|
||||
context.runner_cache.build_definition = definitions[0]
|
||||
return context.runner_cache.build_definition
|
||||
except IndexError:
|
||||
raise AccountStateError('Project "%s" doesn''t appear to have any build definitions.' % (project.name,))
|
||||
|
|
Загрузка…
Ссылка в новой задаче