diff --git a/changes/fix_jira.md b/changes/fix_jira.md new file mode 100644 index 000000000..64055755d --- /dev/null +++ b/changes/fix_jira.md @@ -0,0 +1,2 @@ +Fix comments not applying in some jira updates + diff --git a/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java b/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java index 1ca117c68..e3a8aa128 100644 --- a/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java +++ b/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java @@ -410,22 +410,6 @@ boolean transition( } request.setTransition(transition); - /** "update": { "comment": [ { "add": { "body": "Bug has been fixed." } } ] } */ - Map 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( @@ -458,9 +442,40 @@ boolean transition( lokiLabels.put("issue", issue.getKey()); ((Definer) 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 lokiLabels = new HashMap<>(); + lokiLabels.put("issue", issue.getKey()); + ((Definer) definer).log(errorBuilder.toString(), lokiLabels); + } + return isGood; } } return false;