Optionally limit github to protected branches
When using a branch and pull model on a shared repository there are
usually one or more protected branches which are gated and a dynamic
number of temporary personal/feature branches which are the source for
the pull requests. These temporary branches while ungated can
potentially include broken zuul config and therefore break the global
tenant wide configuration.
In order to deal with this model add support for excluding unprotected
branches. This can be configured on tenant level and overridden per
project.
Change-Id: I8a45fd41539a3c964a84142f04c1644585c0fdcf
diff --git a/tests/unit/test_configloader.py b/tests/unit/test_configloader.py
index d08c6a1..1ba4ed9 100644
--- a/tests/unit/test_configloader.py
+++ b/tests/unit/test_configloader.py
@@ -182,6 +182,7 @@
def test_tenant_groups3(self):
tenant = self.sched.abide.tenants.get('tenant-one')
+ self.assertEqual(False, tenant.exclude_unprotected_branches)
self.assertEqual(['common-config'],
[x.name for x in tenant.config_projects])
self.assertEqual(['org/project1', 'org/project2'],
@@ -212,6 +213,29 @@
project2_config.pipelines['check'].job_list.jobs)
+class TestTenantUnprotectedBranches(TenantParserTestCase):
+ tenant_config_file = 'config/tenant-parser/unprotected-branches.yaml'
+
+ def test_tenant_unprotected_branches(self):
+ tenant = self.sched.abide.tenants.get('tenant-one')
+ self.assertEqual(True, tenant.exclude_unprotected_branches)
+
+ self.assertEqual(['common-config'],
+ [x.name for x in tenant.config_projects])
+ self.assertEqual(['org/project1', 'org/project2'],
+ [x.name for x in tenant.untrusted_projects])
+
+ tpc = tenant.project_configs
+ project_name = tenant.config_projects[0].canonical_name
+ self.assertEqual(False, tpc[project_name].exclude_unprotected_branches)
+
+ project_name = tenant.untrusted_projects[0].canonical_name
+ self.assertIsNone(tpc[project_name].exclude_unprotected_branches)
+
+ project_name = tenant.untrusted_projects[1].canonical_name
+ self.assertIsNone(tpc[project_name].exclude_unprotected_branches)
+
+
class TestSplitConfig(ZuulTestCase):
tenant_config_file = 'config/split-config/main.yaml'