Skip to content

Commit

Permalink
fix(pipeline_templates): notification inheritance (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach authored Aug 25, 2017
1 parent 6413bdf commit 6500bcf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public Map<String, Object> generate(PipelineTemplate template, TemplateConfigura
pipeline.put("parallel", true);
pipeline.put("limitConcurrent", true);
pipeline.put("keepWaitingPipelines", false);
pipeline.put("notifications", Collections.emptyList());
} else {
pipeline.put("parallel", c.getConcurrentExecutions().getOrDefault("parallel", true));
pipeline.put("limitConcurrent", c.getConcurrentExecutions().getOrDefault("limitConcurrent", true));
pipeline.put("keepWaitingPipelines", c.getConcurrentExecutions().getOrDefault("keepWaitingPipelines", false));
pipeline.put("notifications", c.getNotifications());
}

addNotifications(pipeline, template, configuration);

pipeline.put("stages", template.getStages()
.stream()
.map(s -> {
Expand All @@ -70,4 +70,21 @@ public Map<String, Object> generate(PipelineTemplate template, TemplateConfigura

return pipeline;
}

private void addNotifications(Map<String, Object> pipeline, PipelineTemplate template, TemplateConfiguration configuration) {
if (configuration.getConfiguration().getInherit().contains("notifications")) {
pipeline.put(
"notifications",
TemplateMerge.mergeNamedContent(
template.getConfiguration().getNotifications(),
configuration.getConfiguration().getNotifications()
)
);
} else {
pipeline.put(
"notifications",
Optional.ofNullable(configuration.getConfiguration().getNotifications()).orElse(Collections.emptyList())
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ class V1SchemaExecutionGeneratorSpec extends Specification {
"124" | [application: 'orca'] || "124"
}

@Unroll
def "should set notifications in execution json"() {
given:
PipelineTemplate template = getPipelineTemplate()
TemplateConfiguration configuration = new TemplateConfiguration(
pipeline: new PipelineDefinition([application: 'orca', pipelineConfigId: 'pipelineConfigId']),
configuration: new TemplateConfiguration.PipelineConfiguration(
inherit: inherit,
notifications: [
new NamedHashMap().with {
put('name', 'configuration-notification')
put('address', '[email protected]')
it
}
]
)
)

when:
def result = subject.generate(template, configuration, "pipelineConfigId")

then:
result.notifications*.address == addresses

where:
inherit || addresses
['notifications'] || ['[email protected]', '[email protected]']
[] || ['[email protected]']
}

private PipelineTemplate getPipelineTemplate() {
new PipelineTemplate(
id: 'simpleTemplate',
Expand All @@ -99,6 +129,13 @@ class V1SchemaExecutionGeneratorSpec extends Specification {
put('enabled', true)
it
}
],
notifications: [
new NamedHashMap().with {
put('name', 'template-notification')
put('address', '[email protected]')
it
}
]
),
stages: [
Expand Down

0 comments on commit 6500bcf

Please sign in to comment.