Use implied branch matcher for implied branches
When not expressing branches each job automatically matches the branch where it is defined. Currently that match is not a fullmatch because the default BranchMatcher is used in this case. This leads to the situation that when having a job on branch stable and on stable-foo a change to stable-foo matches both because stable is a submatch of stable-foo. Using the ImpliedBranchMatcher on implied branches fixes this. Change-Id: I37e2a5dcf5df5c85812327a09d2678c0544bd366
This commit is contained in:
parent
dddbb3dbfe
commit
29ab34a3ad
|
@ -4977,12 +4977,14 @@ class ZuulTestCase(BaseTestCase):
|
|||
self.assertNotEqual(job.name, name,
|
||||
'Job %s found in history' % name)
|
||||
|
||||
def getJobFromHistory(self, name, project=None, result=None):
|
||||
def getJobFromHistory(self, name, project=None, result=None, branch=None):
|
||||
for job in self.history:
|
||||
if (job.name == name and
|
||||
(project is None or
|
||||
job.parameters['zuul']['project']['name'] == project) and
|
||||
(result is None or job.result == result)):
|
||||
(result is None or job.result == result) and
|
||||
(branch is None or
|
||||
job.parameters['zuul']['branch'] == branch)):
|
||||
return job
|
||||
raise Exception("Unable to find job %s in history" % name)
|
||||
|
||||
|
|
3
tests/fixtures/config/templated-project/git/untrusted-config/zuul.d/jobs.yaml
vendored
Normal file
3
tests/fixtures/config/templated-project/git/untrusted-config/zuul.d/jobs.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
- job:
|
||||
name: project-test7
|
||||
parent: project-test1
|
|
@ -6846,6 +6846,9 @@ class TestSchedulerTemplatedProject(ZuulTestCase):
|
|||
name: untrusted-config
|
||||
templates:
|
||||
- test-three-and-four
|
||||
check:
|
||||
jobs:
|
||||
- project-test7
|
||||
""")
|
||||
file_dict = {'zuul.d/project.yaml': in_repo_conf}
|
||||
B = self.fake_gerrit.addFakeChange('untrusted-config', 'stable-foo',
|
||||
|
@ -6856,12 +6859,26 @@ class TestSchedulerTemplatedProject(ZuulTestCase):
|
|||
self.assertHistory([
|
||||
dict(name='project-test1', result='SUCCESS', changes='1,1'),
|
||||
dict(name='project-test2', result='SUCCESS', changes='1,1'),
|
||||
dict(name='project-test7', result='SUCCESS', changes='2,1'),
|
||||
dict(name='layered-project-test3', result='SUCCESS',
|
||||
changes='2,1'),
|
||||
dict(name='layered-project-test4', result='SUCCESS',
|
||||
changes='2,1'),
|
||||
], ordered=False)
|
||||
|
||||
# Inheritance path should not contain items from branch stable
|
||||
# This tests that not only is it the case that the stable
|
||||
# branch project-template did not apply, but also that the
|
||||
# stable branch definitions of the project-test7 did not apply
|
||||
# (since the job definitions also have implied branch
|
||||
# matchers).
|
||||
job = self.getJobFromHistory('project-test7', branch='stable-foo')
|
||||
inheritance_path = job.parameters['zuul']['_inheritance_path']
|
||||
self.assertEqual(len(inheritance_path), 4)
|
||||
stable_items = [x for x in inheritance_path
|
||||
if 'untrusted-config/zuul.d/jobs.yaml@stable#' in x]
|
||||
self.assertEqual(len(stable_items), 0)
|
||||
|
||||
|
||||
class TestSchedulerSuccessURL(ZuulTestCase):
|
||||
tenant_config_file = 'config/success-url/main.yaml'
|
||||
|
|
|
@ -931,12 +931,14 @@ class JobParser(object):
|
|||
job.allowed_projects = frozenset(allowed)
|
||||
|
||||
branches = None
|
||||
implied = False
|
||||
if 'branches' in conf:
|
||||
branches = as_list(conf['branches'])
|
||||
elif not project_pipeline:
|
||||
branches = self.pcontext.getImpliedBranches(job.source_context)
|
||||
implied = True
|
||||
if branches:
|
||||
job.setBranchMatcher(branches)
|
||||
job.setBranchMatcher(branches, implied=implied)
|
||||
if 'files' in conf:
|
||||
job.setFileMatcher(as_list(conf['files']))
|
||||
if 'irrelevant-files' in conf:
|
||||
|
|
|
@ -1430,12 +1430,16 @@ class Job(ConfigObject):
|
|||
# Return the raw branch list that match this job
|
||||
return self._branches
|
||||
|
||||
def setBranchMatcher(self, branches):
|
||||
def setBranchMatcher(self, branches, implied=False):
|
||||
# Set the branch matcher to match any of the supplied branches
|
||||
self._branches = branches
|
||||
matchers = []
|
||||
if implied:
|
||||
matcher_class = change_matcher.ImpliedBranchMatcher
|
||||
else:
|
||||
matcher_class = change_matcher.BranchMatcher
|
||||
for branch in branches:
|
||||
matchers.append(change_matcher.BranchMatcher(branch))
|
||||
matchers.append(matcher_class(branch))
|
||||
self.branch_matcher = change_matcher.MatchAny(matchers)
|
||||
|
||||
def setFileMatcher(self, files):
|
||||
|
|
Loading…
Reference in New Issue