Merge pull request #56 from coreos-inc/bbbranchfix
Fix bitbucket triggers when the branch tag filter removes all branches
This commit is contained in:
commit
8493395aec
1 changed files with 12 additions and 8 deletions
|
@ -257,6 +257,13 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
bitbucket_client = self._get_authorized_client()
|
bitbucket_client = self._get_authorized_client()
|
||||||
return bitbucket_client.for_namespace(namespace).repositories().get(name)
|
return bitbucket_client.for_namespace(namespace).repositories().get(name)
|
||||||
|
|
||||||
|
def _get_default_branch(self, repository, default_value='master'):
|
||||||
|
(result, data, _) = repository.get_main_branch()
|
||||||
|
if result:
|
||||||
|
return data['name']
|
||||||
|
|
||||||
|
return default_value
|
||||||
|
|
||||||
def get_oauth_url(self):
|
def get_oauth_url(self):
|
||||||
bitbucket_client = self._get_client()
|
bitbucket_client = self._get_client()
|
||||||
(result, data, err_msg) = bitbucket_client.get_authorization_url()
|
(result, data, err_msg) = bitbucket_client.get_authorization_url()
|
||||||
|
@ -376,6 +383,9 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
# Find the first matching branch.
|
# Find the first matching branch.
|
||||||
repo_branches = self.list_field_values('branch_name') or []
|
repo_branches = self.list_field_values('branch_name') or []
|
||||||
branches = find_matching_branches(config, repo_branches)
|
branches = find_matching_branches(config, repo_branches)
|
||||||
|
if not branches:
|
||||||
|
branches = [self._get_default_branch(repository)]
|
||||||
|
|
||||||
(result, data, err_msg) = repository.get_path_contents('', revision=branches[0])
|
(result, data, err_msg) = repository.get_path_contents('', revision=branches[0])
|
||||||
if not result:
|
if not result:
|
||||||
raise RepositoryReadException(err_msg)
|
raise RepositoryReadException(err_msg)
|
||||||
|
@ -436,10 +446,7 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
|
|
||||||
# Lookup the default branch associated with the repository. We use this when building
|
# Lookup the default branch associated with the repository. We use this when building
|
||||||
# the tags.
|
# the tags.
|
||||||
default_branch = ''
|
default_branch = self._get_default_branch(repository)
|
||||||
(result, data, _) = repository.get_main_branch()
|
|
||||||
if result:
|
|
||||||
default_branch = data['name']
|
|
||||||
|
|
||||||
# Lookup the commit sha.
|
# Lookup the commit sha.
|
||||||
(result, data, _) = repository.changesets().get(commit_sha)
|
(result, data, _) = repository.changesets().get(commit_sha)
|
||||||
|
@ -533,10 +540,7 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
|
||||||
repository = self._get_repository_client()
|
repository = self._get_repository_client()
|
||||||
|
|
||||||
# Find the branch to build.
|
# Find the branch to build.
|
||||||
branch_name = run_parameters.get('branch_name')
|
branch_name = run_parameters.get('branch_name') or self._get_default_branch(repository)
|
||||||
(result, data, _) = repository.get_main_branch()
|
|
||||||
if result:
|
|
||||||
branch_name = branch_name or data['name']
|
|
||||||
|
|
||||||
# Lookup the commit SHA for the branch.
|
# Lookup the commit SHA for the branch.
|
||||||
(result, data, _) = repository.get_branches()
|
(result, data, _) = repository.get_branches()
|
||||||
|
|
Reference in a new issue