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
This commit is contained in:
Tobias Henkel 2018-08-02 12:15:49 +02:00
parent 4cb9932a4f
commit f9345c3e68
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 31 additions and 1 deletions

View File

@ -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'

View File

@ -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