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

Go back to two requests for jira tickets #1307

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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