Skip to content

Commit

Permalink
fix(core): Mark mptv2 items as inherited (#2971)
Browse files Browse the repository at this point in the history
* fix(core): Mark mptv2 items as inherited

spinnaker/spinnaker#4451

* fix(core): Refactor how items are marked inherited

spinnaker/spinnaker#4451
  • Loading branch information
louisjimenez committed Jun 11, 2019
1 parent a52578b commit 62346e4
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void addNotifications(
pipeline.put(
"notifications",
TemplateMerge.mergeDistinct(
(List<HashMap<String, Object>>) template.getPipeline().get("notifications"),
markTemplateCollectionAsInherited(getTemplateCollection(template, "notifications")),
configuration.getNotifications()));
}
}
Expand All @@ -93,7 +93,7 @@ private void addParameters(
pipeline.put(
"parameterConfig",
TemplateMerge.mergeDistinct(
(List<HashMap<String, Object>>) template.getPipeline().get("parameterConfig"),
markTemplateCollectionAsInherited(getTemplateCollection(template, "parameterConfig")),
configuration.getParameters()));
}
}
Expand All @@ -110,8 +110,22 @@ private void addTriggers(
pipeline.put(
"triggers",
TemplateMerge.mergeDistinct(
(List<HashMap<String, Object>>) template.getPipeline().get("triggers"),
markTemplateCollectionAsInherited(getTemplateCollection(template, "triggers")),
configuration.getTriggers()));
}
}

private static List<HashMap<String, Object>> markTemplateCollectionAsInherited(
List<HashMap<String, Object>> templateCollection) {
for (HashMap<String, Object> templateItem : templateCollection) {
templateItem.put("inherited", true);
}
return templateCollection;
}

private static List<HashMap<String, Object>> getTemplateCollection(
V2PipelineTemplate template, String key) {
return Optional.ofNullable((List<HashMap<String, Object>>) template.getPipeline().get(key))
.orElse(Collections.emptyList());
}
}

0 comments on commit 62346e4

Please sign in to comment.