-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
Description
Original comment by @spinscale:
The following example jira configuration will result in no changes in the components array due to the current implementation, regular string fields are correctly replaced
"actions": {
"create-jira-issue": {
"jira": {
"account": "monitoring",
"fields": {
"summary": "correctly replaced {{ctx.payload}}",
"issuetype": {
"name": "Alert"
},
"components": [
{
"name": "not replaced {{ctx.payload}}"
}
],
"project": {
"key": "MMA"
},
"customfield_10200": 2
}
}
}
}
}
The reason for this is the broken ExecutableJiraAction.merge method, because it does not do the right thing when a list, that is not comprised of a string value is found - which for a map is simple to add.
This unit test resembles the broken behaviour and fails on the last assert
public void testMerge() {
Map<String, Object> writeableMap = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("foo", "bar");
Map<String, Object> componentMap = new HashMap<>();
componentMap.put("name", "value");
List<Map<String, Object>> list = new ArrayList<>();
list.add(componentMap);
map.put("components", list);
Map<String, Object> result = ExecutableJiraAction.merge(writeableMap, map, s -> s.toUpperCase(Locale.ROOT));
assertThat(result, hasEntry("FOO", "BAR"));
assertThat(result.get("COMPONENTS"), instanceOf(List.class));
List<Map<String, Object>> components = (List<Map<String, Object>>) result.get("COMPONENTS");
assertThat(components.get(0), hasEntry("NAME", "VALUE"));
}