Start recording the commit sha and other metadata about github triggered builds. We'll eventually show this information in the UI

This commit is contained in:
Joseph Schorr 2015-02-18 14:12:59 -05:00
parent 4cf18c4591
commit 7c81d90cda
5 changed files with 22 additions and 9 deletions

View file

@ -415,13 +415,13 @@ class ActivateBuildTrigger(RepositoryParamResource):
try:
run_parameters = request.get_json()
specs = handler.manual_start(trigger.auth_token, config_dict, run_parameters=run_parameters)
dockerfile_id, tags, name, subdir = specs
dockerfile_id, tags, name, subdir, metadata = specs
repo = model.get_repository(namespace, repository)
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)
pull_robot_name=pull_robot_name, trigger_metadata=metadata)
except TriggerStartException as tse:
raise InvalidRequest(tse.message)

View file

@ -211,7 +211,7 @@ def check_repository_usage(user_or_org, plan_found):
def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
trigger=None, pull_robot_name=None):
trigger=None, pull_robot_name=None, trigger_metadata=None):
host = urlparse.urlparse(request.url).netloc
repo_path = '%s/%s/%s' % (host, repository.namespace_user.username, repository.name)
@ -223,7 +223,8 @@ def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
job_config = {
'docker_tags': tags,
'registry': host,
'build_subdir': subdir
'build_subdir': subdir,
'trigger_metadata': trigger_metadata or {}
}
with app.config['DB_TRANSACTION_FACTORY'](db):

View file

@ -345,8 +345,10 @@ class GithubBuildTrigger(BuildTrigger):
# compute the tag(s)
branch = ref.split('/')[-1]
tags = {branch}
if branch == repo.default_branch:
tags.add('latest')
logger.debug('Pushing to tags: %s' % tags)
# compute the subdir
@ -354,7 +356,14 @@ class GithubBuildTrigger(BuildTrigger):
joined_subdir = os.path.join(tarball_subdir, repo_subdir)
logger.debug('Final subdir: %s' % joined_subdir)
return dockerfile_id, list(tags), build_name, joined_subdir
# compute the metadata
metadata = {
'commit_sha': commit_sha,
'ref': ref,
'default_branch': repo.default_branch
}
return dockerfile_id, list(tags), build_name, joined_subdir, metadata
@staticmethod
def get_display_name(sha):

View file

@ -91,7 +91,7 @@ def build_trigger_webhook(trigger_uuid, **kwargs):
try:
specs = handler.handle_trigger_request(request, trigger.auth_token,
config_dict)
dockerfile_id, tags, name, subdir = specs
dockerfile_id, tags, name, subdir, metadata = specs
except ValidationRequestException:
# This was just a validation request, we don't need to build anything
@ -104,7 +104,7 @@ def build_trigger_webhook(trigger_uuid, **kwargs):
pull_robot_name = model.get_pull_robot_name(trigger)
repo = model.get_repository(namespace, repository)
start_build(repo, dockerfile_id, tags, name, subdir, False, trigger,
pull_robot_name=pull_robot_name)
pull_robot_name=pull_robot_name, trigger_metadata=metadata)
return make_response('Okay')

View file

@ -2276,7 +2276,7 @@ class FakeBuildTrigger(BuildTriggerBase):
return [auth_token, 'foo', 'bar', config['somevalue']]
def handle_trigger_request(self, request, auth_token, config):
return ('foo', ['bar'], 'build-name', 'subdir')
return ('foo', ['bar'], 'build-name', 'subdir', {'foo': 'bar'})
def is_active(self, config):
return 'active' in config and config['active']
@ -2290,7 +2290,7 @@ class FakeBuildTrigger(BuildTriggerBase):
return config
def manual_start(self, auth_token, config, run_parameters=None):
return ('foo', ['bar'], 'build-name', 'subdir')
return ('foo', ['bar'], 'build-name', 'subdir', {'foo': 'bar'})
def dockerfile_url(self, auth_token, config):
return 'http://some/url'
@ -2501,6 +2501,9 @@ class TestBuildTriggers(ApiTestCase):
self.assertEquals("build-name", start_json['display_name'])
self.assertEquals(['bar'], start_json['job_config']['docker_tags'])
# Verify the metadata was added.
build_obj = database.RepositoryBuild.get(database.RepositoryBuild.uuid == start_json['id'])
self.assertEquals('bar', py_json.loads(build_obj.job_config)['trigger_metadata']['foo'])
def test_invalid_robot_account(self):
self.login(ADMIN_ACCESS_USER)