diff --git a/endpoints/trigger.py b/endpoints/trigger.py index acd1ab127..9dc266394 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -1,6 +1,7 @@ import logging import io import os.path +import zipfile from github import Github, UnknownObjectException, GithubException from tempfile import SpooledTemporaryFile @@ -228,10 +229,15 @@ class GithubBuildTrigger(BuildTrigger): archive_link = repo.get_archive_link('zipball', short_sha) download_archive = client.get(archive_link, stream=True) + zipball_subdir = '' with SpooledTemporaryFile(CHUNK_SIZE) as zipball: for chunk in download_archive.iter_content(CHUNK_SIZE): zipball.write(chunk) + # Pull out the name of the subdir that GitHub generated + with zipfile.ZipFile(zipball) as archive: + zipball_subdir = archive.namelist()[0] + dockerfile_id = user_files.store_file(zipball, ZIPBALL) logger.debug('Successfully prepared job') @@ -245,7 +251,6 @@ class GithubBuildTrigger(BuildTrigger): # compute the subdir repo_subdir = config['subdir'] - zipball_subdir = '%s-%s-%s' % (repo.owner.login, repo.name, short_sha) joined_subdir = os.path.join(zipball_subdir, repo_subdir) logger.debug('Final subdir: %s' % joined_subdir) diff --git a/endpoints/webhooks.py b/endpoints/webhooks.py index d2beccc2d..65a2ec403 100644 --- a/endpoints/webhooks.py +++ b/endpoints/webhooks.py @@ -87,7 +87,7 @@ def build_trigger_webhook(namespace, repository, trigger_uuid): 'resource_key': dockerfile_id, } build_request = model.create_repository_build(trigger.repository, token, - job_config, name) + job_config, name, trigger) dockerfile_build_queue.put(json.dumps({ 'build_uuid': build_request.uuid,