Skip to content

Commit

Permalink
Go back to two requests for jira tickets
Browse files Browse the repository at this point in the history
The single request works in some Jira projects and not others
and I do not understand why
  • Loading branch information
avarsava committed Jun 27, 2024
1 parent 0d50ff4 commit 2951d70
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
2 changes: 2 additions & 0 deletions changes/fix_jira.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix comments not applying in some jira updates

Original file line number Diff line number Diff line change
Expand Up @@ -410,22 +410,6 @@ boolean transition(
}
request.setTransition(transition);

/** "update": { "comment": [ { "add": { "body": "Bug has been fixed." } } ] } */
Map<String, JsonNode> updateComment = new HashMap<>();
updateComment.put(
"comment",
MAPPER
.createArrayNode()
.add(
MAPPER
.createObjectNode()
.set(
"add",
MAPPER
.createObjectNode()
.set("body", version.createDocument(comment)))));
request.setUpdate(updateComment);

final var requestBuilder =
HttpRequest.newBuilder(
new URI(
Expand Down Expand Up @@ -458,9 +442,40 @@ boolean transition(
lokiLabels.put("issue", issue.getKey());
((Definer<JiraConnection>) definer).log(errorBuilder.toString(), lokiLabels);
return false;
} else {
return true;
}

final var updateComment = MAPPER.createObjectNode();
updateComment.set("body", version.createDocument(comment));
final var commentRequestBuilder =
HttpRequest.newBuilder(
new URI(
String.format(
"%s/rest/api/%s/issue/%s/comment", url, version.slug(), issue.getId())));
authenticationHeader.ifPresent(
header -> commentRequestBuilder.header("Authorization", header));

var commentResult =
CLIENT.send(
commentRequestBuilder
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(MAPPER.writeValueAsString(updateComment)))
.build(),
BodyHandlers.ofString());
boolean isGood = commentResult.statusCode() / 100 == 2;
if (!isGood) {
StringBuilder errorBuilder = new StringBuilder();
errorBuilder
.append("Unable to comment on issue ")
.append(issue.getKey())
.append(" using comment ")
.append(comment)
.append("\nGot ")
.append(commentResult.body());
Map<String, String> lokiLabels = new HashMap<>();
lokiLabels.put("issue", issue.getKey());
((Definer<JiraConnection>) definer).log(errorBuilder.toString(), lokiLabels);
}
return isGood;
}
}
return false;
Expand Down

0 comments on commit 2951d70

Please sign in to comment.