Start on the new build view
This commit is contained in:
parent
5cc1c90021
commit
e227d7e526
30 changed files with 816 additions and 11 deletions
|
@ -93,7 +93,11 @@ def build_status_view(build_obj, can_write=False):
|
|||
'is_writer': can_write,
|
||||
'trigger': trigger_view(build_obj.trigger),
|
||||
'resource_key': build_obj.resource_key,
|
||||
'pull_robot': user_view(build_obj.pull_robot) if build_obj.pull_robot else None
|
||||
'pull_robot': user_view(build_obj.pull_robot) if build_obj.pull_robot else None,
|
||||
'repository': {
|
||||
'namespace': build_obj.repository.namespace_user.username,
|
||||
'name': build_obj.repository.name
|
||||
}
|
||||
}
|
||||
|
||||
if can_write:
|
||||
|
@ -214,6 +218,18 @@ class RepositoryBuildList(RepositoryParamResource):
|
|||
@path_param('build_uuid', 'The UUID of the build')
|
||||
class RepositoryBuildResource(RepositoryParamResource):
|
||||
""" Resource for dealing with repository builds. """
|
||||
@require_repo_read
|
||||
@nickname('getRepoBuild')
|
||||
def get(self, namespace, repository, build_uuid):
|
||||
""" Returns information about a build. """
|
||||
try:
|
||||
build = model.get_repository_build(build_uuid)
|
||||
except model.InvalidRepositoryBuildException:
|
||||
raise NotFound()
|
||||
|
||||
can_write = ModifyRepositoryPermission(namespace, repository).can()
|
||||
return build_status_view(build, can_write)
|
||||
|
||||
@require_repo_admin
|
||||
@nickname('cancelRepoBuild')
|
||||
def delete(self, namespace, repository, build_uuid):
|
||||
|
|
|
@ -421,7 +421,8 @@ class ActivateBuildTrigger(RepositoryParamResource):
|
|||
pull_robot_name = model.get_pull_robot_name(trigger)
|
||||
|
||||
build_request = start_build(repo, dockerfile_id, tags, name, subdir, True,
|
||||
pull_robot_name=pull_robot_name, trigger_metadata=metadata)
|
||||
trigger=trigger, pull_robot_name=pull_robot_name,
|
||||
trigger_metadata=metadata)
|
||||
except TriggerStartException as tse:
|
||||
raise InvalidRequest(tse.message)
|
||||
|
||||
|
|
|
@ -224,7 +224,8 @@ def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
|
|||
'docker_tags': tags,
|
||||
'registry': host,
|
||||
'build_subdir': subdir,
|
||||
'trigger_metadata': trigger_metadata or {}
|
||||
'trigger_metadata': trigger_metadata or {},
|
||||
'is_manual': manual
|
||||
}
|
||||
|
||||
with app.config['DB_TRANSACTION_FACTORY'](db):
|
||||
|
|
|
@ -310,6 +310,30 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
message = ge.data.get('message', 'Unable to read Dockerfile: %s' % source)
|
||||
raise RepositoryReadException(message)
|
||||
|
||||
@staticmethod
|
||||
def _build_commit_info(repo, commit_sha):
|
||||
try:
|
||||
commit = repo.get_commit(commit_sha)
|
||||
except GithubException:
|
||||
logger.exception('Could not load data for commit')
|
||||
return
|
||||
|
||||
return {
|
||||
'url': commit.html_url,
|
||||
'message': commit.commit.message,
|
||||
'author': {
|
||||
'username': commit.author.login,
|
||||
'avatar_url': commit.author.avatar_url,
|
||||
'url': commit.author.html_url
|
||||
},
|
||||
'committer': {
|
||||
'username': commit.committer.login,
|
||||
'avatar_url': commit.committer.avatar_url,
|
||||
'url': commit.committer.html_url
|
||||
},
|
||||
'date': commit.last_modified
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _prepare_build(config, repo, commit_sha, build_name, ref):
|
||||
# Prepare the download and upload URLs
|
||||
|
@ -360,9 +384,14 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
metadata = {
|
||||
'commit_sha': commit_sha,
|
||||
'ref': ref,
|
||||
'default_branch': repo.default_branch
|
||||
'default_branch': repo.default_branch,
|
||||
}
|
||||
|
||||
# add the commit info.
|
||||
commit_info = GithubBuildTrigger._build_commit_info(repo, commit_sha)
|
||||
if commit_info is not None:
|
||||
metadata['commit_info'] = commit_info
|
||||
|
||||
return dockerfile_id, list(tags), build_name, joined_subdir, metadata
|
||||
|
||||
@staticmethod
|
||||
|
@ -417,6 +446,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
branch_name = run_parameters.get('branch_name') or repo.default_branch
|
||||
branch = repo.get_branch(branch_name)
|
||||
branch_sha = branch.commit.sha
|
||||
commit_info = branch.commit
|
||||
short_sha = GithubBuildTrigger.get_display_name(branch_sha)
|
||||
ref = 'refs/heads/%s' % (branch_name)
|
||||
|
||||
|
|
Reference in a new issue