Fix the implementation of local userfiles and switch master_branch to default_branch to match the github api.
This commit is contained in:
parent
63cf8beb26
commit
be728ceccb
2 changed files with 15 additions and 8 deletions
|
@ -6,7 +6,7 @@ import magic
|
|||
|
||||
from boto.s3.key import Key
|
||||
from uuid import uuid4
|
||||
from flask import url_for, request, send_file
|
||||
from flask import url_for, request, send_file, make_response
|
||||
from flask.views import View
|
||||
|
||||
|
||||
|
@ -111,6 +111,8 @@ class UserfilesHandlers(View):
|
|||
|
||||
self._userfiles.store_stream(input_stream, file_id)
|
||||
|
||||
return make_response('Okay')
|
||||
|
||||
def dispatch_request(self, file_id):
|
||||
if request.method == 'GET':
|
||||
return self.get(file_id)
|
||||
|
@ -158,7 +160,11 @@ class LocalUserfiles(object):
|
|||
|
||||
def store_file(self, file_like_obj, content_type):
|
||||
file_id = str(uuid4())
|
||||
self.store_stream(file_like_obj, content_type)
|
||||
|
||||
# Rewind the file to match what s3 does
|
||||
file_like_obj.seek(0, os.SEEK_SET)
|
||||
|
||||
self.store_stream(file_like_obj, file_id)
|
||||
return file_id
|
||||
|
||||
def get_file_url(self, file_id, expires_in=300):
|
||||
|
|
|
@ -159,7 +159,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
try:
|
||||
hook = to_add_webhook.create_hook('web', webhook_config)
|
||||
config['hook_id'] = hook.id
|
||||
config['master_branch'] = to_add_webhook.master_branch
|
||||
config['master_branch'] = to_add_webhook.default_branch
|
||||
except GithubException:
|
||||
msg = 'Unable to create webhook on repository: %s'
|
||||
raise TriggerActivationException(msg % new_build_source)
|
||||
|
@ -218,7 +218,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
try:
|
||||
repo = gh_client.get_repo(source)
|
||||
default_commit = repo.get_branch(repo.master_branch or 'master').commit
|
||||
default_commit = repo.get_branch(repo.default_branch or 'master').commit
|
||||
commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)
|
||||
|
||||
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
||||
|
@ -239,7 +239,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
gh_client = self._get_client(auth_token)
|
||||
try:
|
||||
repo = gh_client.get_repo(source)
|
||||
master_branch = repo.master_branch or 'master'
|
||||
master_branch = repo.default_branch or 'master'
|
||||
return 'https://github.com/%s/blob/%s/%s' % (source, master_branch, path)
|
||||
except GithubException as ge:
|
||||
return None
|
||||
|
@ -275,6 +275,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
tarball_subdir = ''
|
||||
with SpooledTemporaryFile(CHUNK_SIZE) as tarball:
|
||||
for chunk in download_archive.iter_content(CHUNK_SIZE):
|
||||
logger.debug('Writing chunk of size: %s', len(chunk))
|
||||
tarball.write(chunk)
|
||||
|
||||
# Seek to position 0 to make tarfile happy
|
||||
|
@ -291,7 +292,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
# compute the tag(s)
|
||||
branch = ref.split('/')[-1]
|
||||
tags = {branch}
|
||||
if branch == repo.master_branch:
|
||||
if branch == repo.default_branch:
|
||||
tags.add('latest')
|
||||
logger.debug('Pushing to tags: %s' % tags)
|
||||
|
||||
|
@ -333,9 +334,9 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
gh_client = self._get_client(auth_token)
|
||||
repo = gh_client.get_repo(source)
|
||||
master = repo.get_branch(repo.master_branch)
|
||||
master = repo.get_branch(repo.default_branch)
|
||||
master_sha = master.commit.sha
|
||||
short_sha = GithubBuildTrigger.get_display_name(master_sha)
|
||||
ref = 'refs/heads/%s' % repo.master_branch
|
||||
ref = 'refs/heads/%s' % repo.default_branch
|
||||
|
||||
return self._prepare_build(config, repo, master_sha, short_sha, ref)
|
||||
|
|
Reference in a new issue