Fix complex branch matchers in project configs
A recent change to always apply an implied branch matcher to in-tree
project configs on projects with branches had an optimization to
avoid adding unecessary jobs which was too simple. It assumed that
if the raw text of the matcher on the job did not match the name
of the branch, then there was no need to add the job. That only
works for branch matchers that are simple branch names. One that
is a regex may or may not match the implied branch.
To correct this, when building the job list, run the implied branch
name against the branch matcher regex (if there is one) for the job
to determine whether it will not match.
Change-Id: Ibbe097801a45928bc9942991d868a78f5f441887
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index e2da808..70d9211 100755
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -157,6 +157,27 @@
self.assertIn('Unable to modify final job', A.messages[0])
+class TestBranchNegative(ZuulTestCase):
+ tenant_config_file = 'config/branch-negative/main.yaml'
+
+ def test_negative_branch_match(self):
+ # Test that a negative branch matcher works with implied branches.
+ self.create_branch('org/project', 'stable/pike')
+ self.fake_gerrit.addEvent(
+ self.fake_gerrit.getFakeBranchCreatedEvent(
+ 'org/project', 'stable/pike'))
+ self.waitUntilSettled()
+
+ A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+ self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
+ self.waitUntilSettled()
+ B = self.fake_gerrit.addFakeChange('org/project', 'stable/pike', 'A')
+ self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
+ self.waitUntilSettled()
+ self.assertHistory([
+ dict(name='test-job', result='SUCCESS', changes='1,1')])
+
+
class TestBranchTemplates(ZuulTestCase):
tenant_config_file = 'config/branch-templates/main.yaml'