diff --git a/tests/unit/test_web.py b/tests/unit/test_web.py index aa70176b3c..339ec2169e 100644 --- a/tests/unit/test_web.py +++ b/tests/unit/test_web.py @@ -847,6 +847,7 @@ class TestWeb(BaseTestWeb): 'connection_name': 'gerrit', 'name': 'org/project1', 'metadata': { + 'is_template': False, 'default_branch': 'master', 'merge_mode': 'merge-resolve', 'queue_name': 'integrated', @@ -855,6 +856,7 @@ class TestWeb(BaseTestWeb): 'source_context': {'branch': 'master', 'path': 'zuul.yaml', 'project': 'common-config'}, + 'is_template': False, 'templates': [], 'default_branch': None, 'queue_name': 'integrated', diff --git a/web/src/actions/project.js b/web/src/actions/project.js index de1da21970..af7d0e172e 100644 --- a/web/src/actions/project.js +++ b/web/src/actions/project.js @@ -28,7 +28,7 @@ export const receiveProject = (tenant, projectName, project) => { const templateIdx = [] let idx project.configs.forEach((config, idx) => { - if (config.default_branch === null) { + if (config.is_template === true) { // This must be a template templateIdx.push(idx) config.pipelines.forEach(templatePipeline => { diff --git a/zuul/configloader.py b/zuul/configloader.py index 2e6b2559a2..09c4fbab89 100644 --- a/zuul/configloader.py +++ b/zuul/configloader.py @@ -1162,6 +1162,7 @@ class ProjectTemplateParser(object): project_template = model.ProjectConfig(conf.get('name')) project_template.source_context = conf['_source_context'] project_template.start_mark = conf['_start_mark'] + project_template.is_template = True project_template.queue_name = conf.get('queue') for pipeline_name, conf_pipeline in conf.items(): if pipeline_name in self.not_pipelines: @@ -1284,6 +1285,10 @@ class ProjectParser(object): project_config.name = project.canonical_name + # Explicitly override this to False since we're reusing the + # project-template loading method which sets it True. + project_config.is_template = False + # Pragmas can cause templates to end up with implied # branch matchers for arbitrary branches, but project # stanzas should not. They should either have the current diff --git a/zuul/model.py b/zuul/model.py index 429ec706a3..9811fd0aef 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -7313,6 +7313,7 @@ class ProjectConfig(ConfigObject): def __init__(self, name): super(ProjectConfig, self).__init__() self.name = name + self.is_template = False self.templates = [] # Pipeline name -> ProjectPipelineConfig self.pipelines = {} @@ -7334,6 +7335,7 @@ class ProjectConfig(ConfigObject): r = self.__class__(self.name) r.source_context = self.source_context r.start_mark = self.start_mark + r.is_template = self.is_template r.templates = self.templates r.pipelines = self.pipelines r.branch_matcher = self.branch_matcher @@ -7365,6 +7367,7 @@ class ProjectConfig(ConfigObject): MERGER_MAP.items()))[0][0] else: d['merge_mode'] = None + d['is_template'] = self.is_template d['templates'] = self.templates d['queue_name'] = self.queue_name return d @@ -7381,6 +7384,7 @@ class ProjectMetadata: def __init__(self): self.merge_mode = None self._default_branch = None + self.is_template = False self.queue_name = None def isDefaultBranchSet(self): @@ -7398,6 +7402,7 @@ class ProjectMetadata: return { 'merge_mode': self.merge_mode, 'default_branch': self.default_branch, + 'is_template': self.is_template, 'queue_name': self.queue_name, } @@ -7406,6 +7411,7 @@ class ProjectMetadata: o = cls() o.merge_mode = data['merge_mode'] o.default_branch = data['default_branch'] + o.is_template = data['is_template'] o.queue_name = data['queue_name'] return o