Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

257: Proper setting of custom fields in Jira issues #392

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1293,7 +1293,19 @@ void testIssueBackport(TestInfo testInfo) throws IOException {
TestBotRunner.runPeriodicItems(notifyBot);

// Create an issue and commit a fix
var issue = issueProject.createIssue("This is an issue", List.of("Indeed"), Map.of("issuetype", JSON.of("Enhancement")));
var issue = issueProject.createIssue("This is an issue", List.of("Indeed"),
Map.of("issuetype", JSON.of("Enhancement"),
"customfield_10008", JSON.object()
.put("id", 244)
.put("name", "java.io"),
"customfield_10005", JSON.array()
.add(JSON.object()
.put("id", "17010")
.put("value", "generic"))
.add(JSON.object()
.put("id", "17019")
.put("value", "other"))
));
issue.setProperty("fixVersions", JSON.array().add("13.0.1"));
issue.setProperty("priority", JSON.of("1"));

@@ -1321,6 +1333,9 @@ void testIssueBackport(TestInfo testInfo) throws IOException {

// Custom properties should also propagate
assertEquals("1", backport.properties().get("priority").asString());
assertEquals(244, backport.properties().get("customfield_10008").get("id").asInt());
assertEquals("java.io", backport.properties().get("customfield_10008").get("name").asString());
assertEquals(2, backport.properties().get("customfield_10005").asArray().size());
}
}

@@ -196,6 +196,22 @@ private boolean isInitialField(String name, JSONValue value) {
return false;
}

// Custom fields are set a bit differently depending on their type
private JSONValue filterCustomFieldValue(String name, JSONValue unfiltered) {
if (!name.startsWith("customfield_")) {
return unfiltered;
}
if (unfiltered.isObject()) {
if (unfiltered.asObject().contains("id")) {
return unfiltered.get("id");
} else {
return unfiltered;
}
} else {
return unfiltered;
}
}

@Override
public Issue createIssue(String title, List<String> body, Map<String, JSONValue> properties) {
var query = JSON.object();
@@ -239,7 +255,8 @@ public Issue createIssue(String title, List<String> body, Map<String, JSONValue>
var editFields = JSON.object();
finalProperties.entrySet().stream()
.filter(entry -> !isInitialField(entry.getKey(), entry.getValue()))
.forEach(entry -> editFields.put(entry.getKey(), entry.getValue()));
.forEach(entry -> editFields.put(entry.getKey(), filterCustomFieldValue(entry.getKey(),
entry.getValue())));

if (editFields.fields().size() > 0) {
var id = data.get("key").asString();