Extract the top level zipball subdir from the zip file.

This commit is contained in:
jakedt 2014-02-24 22:57:58 -05:00
parent b094480164
commit b23a7ed130

View file

@ -1,6 +1,7 @@
import logging import logging
import io import io
import os.path import os.path
import zipfile
from github import Github, UnknownObjectException, GithubException from github import Github, UnknownObjectException, GithubException
from tempfile import SpooledTemporaryFile from tempfile import SpooledTemporaryFile
@ -228,10 +229,15 @@ class GithubBuildTrigger(BuildTrigger):
archive_link = repo.get_archive_link('zipball', short_sha) archive_link = repo.get_archive_link('zipball', short_sha)
download_archive = client.get(archive_link, stream=True) download_archive = client.get(archive_link, stream=True)
zipball_subdir = ''
with SpooledTemporaryFile(CHUNK_SIZE) as zipball: with SpooledTemporaryFile(CHUNK_SIZE) as zipball:
for chunk in download_archive.iter_content(CHUNK_SIZE): for chunk in download_archive.iter_content(CHUNK_SIZE):
zipball.write(chunk) 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) dockerfile_id = user_files.store_file(zipball, ZIPBALL)
logger.debug('Successfully prepared job') logger.debug('Successfully prepared job')
@ -245,7 +251,6 @@ class GithubBuildTrigger(BuildTrigger):
# compute the subdir # compute the subdir
repo_subdir = config['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) joined_subdir = os.path.join(zipball_subdir, repo_subdir)
logger.debug('Final subdir: %s' % joined_subdir) logger.debug('Final subdir: %s' % joined_subdir)