Move exclude unprotected branches check into tenant

The check if a project excludes unprotected branches will be needed
later in other places as well so refactor this into the tenant object.

Change-Id: I0d36df5f163b0b07152294b090c82d6a47401bc4
This commit is contained in:
Tobias Henkel 2018-06-15 13:02:55 +02:00
parent 6c0b3a2f21
commit 306039f2dc
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 11 additions and 9 deletions

View File

@ -889,19 +889,11 @@ class GithubConnection(BaseConnection):
self.projects[project.name] = project
def getProjectBranches(self, project, tenant):
# Evaluate if unprotected branches should be excluded or not. The first
# match wins. The order is project -> tenant (default is false).
project_config = tenant.project_configs.get(project.canonical_name)
if project_config.exclude_unprotected_branches is not None:
exclude_unprotected = project_config.exclude_unprotected_branches
else:
exclude_unprotected = tenant.exclude_unprotected_branches
github = self.getGithubClient(project.name)
try:
owner, proj = project.name.split('/')
repository = github.repository(owner, proj)
exclude_unprotected = tenant.getExcludeUnprotectedBranches(project)
self._project_branch_cache[project.name] = [
branch.name for branch in repository.branches(
protected=exclude_unprotected)]

View File

@ -3463,6 +3463,16 @@ class Tenant(object):
tpc = self.project_configs[project.canonical_name]
return tpc.branches
def getExcludeUnprotectedBranches(self, project):
# Evaluate if unprotected branches should be excluded or not. The first
# match wins. The order is project -> tenant (default is false).
project_config = self.project_configs.get(project.canonical_name)
if project_config.exclude_unprotected_branches is not None:
exclude_unprotected = project_config.exclude_unprotected_branches
else:
exclude_unprotected = self.exclude_unprotected_branches
return exclude_unprotected
def addConfigProject(self, tpc):
self.config_projects.append(tpc.project)
self._addProject(tpc)