From f9345c3e68c334f4037dc3a499bce3b8b4a3d4e7 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Thu, 2 Aug 2018 12:15:49 +0200 Subject: [PATCH] Fix wrong matched project template When having the two branches stable and stable-foo with distinct project pipelines that pull in different project-templates currently both project-templates match. The project-templates in this case get implicit branch matchers. However the implied branch matcher currently only does a partial match and so a change to stable-foo matches the project-templates of both stable and stable-foo. Fix this by changing the implied branch matchers to do full matching. Change-Id: I569db50f05c1b53cb1fb26e84ea0af377e3df73c --- tests/unit/test_scheduler.py | 30 ++++++++++++++++++++++++++++++ zuul/change_matcher.py | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index 3d450fd679..f42dbcce86 100644 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -5451,6 +5451,36 @@ class TestSchedulerTemplatedProject(ZuulTestCase): self.getJobFromHistory('project-test1'). parameters['zuul']['_inheritance_path']) + # Now create a new branch named stable-foo and change the project + # pipeline + self.create_branch('untrusted-config', 'stable-foo') + self.fake_gerrit.addEvent( + self.fake_gerrit.getFakeBranchCreatedEvent( + 'untrusted-config', 'stable-foo')) + self.waitUntilSettled() + + in_repo_conf = textwrap.dedent( + """ + - project: + name: untrusted-config + templates: + - test-three-and-four + """) + file_dict = {'zuul.d/project.yaml': in_repo_conf} + B = self.fake_gerrit.addFakeChange('untrusted-config', 'stable-foo', + 'B', files=file_dict) + self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) + self.waitUntilSettled() + + self.assertHistory([ + dict(name='project-test1', result='SUCCESS', changes='1,1'), + dict(name='project-test2', result='SUCCESS', changes='1,1'), + dict(name='layered-project-test3', result='SUCCESS', + changes='2,1'), + dict(name='layered-project-test4', result='SUCCESS', + changes='2,1'), + ], ordered=False) + class TestSchedulerSuccessURL(ZuulTestCase): tenant_config_file = 'config/success-url/main.yaml' diff --git a/zuul/change_matcher.py b/zuul/change_matcher.py index eb12f9b0dd..dc4fe37c34 100644 --- a/zuul/change_matcher.py +++ b/zuul/change_matcher.py @@ -77,7 +77,7 @@ class ImpliedBranchMatcher(AbstractChangeMatcher): def matches(self, change): if hasattr(change, 'branch'): - if self.regex.match(change.branch): + if self.regex.fullmatch(change.branch): return True return False return True