Working with comments
In this recipe, we will see how to manage comments on an issue.
Getting ready
Create a JIRA REST client as mentioned in the Writing a Java client for the REST API recipe.
How to do it...
Adding a comment on an issue using the REST API is pretty easy!
Retrieve the issue on which the comment needs to be added and retrieve the user who needs to make the comment.
final Promise<Issue> issue = jiraRestClient.getIssueClient().getIssue(key); Issue browsedIssue = issue.get(); User jobin = jiraRestClient.getUserClient().getUser("jobinkk").get();
Create a
Comment
object using the issue URI, comment text, author, time of the comment, and so on. You can optionally add visibility information as well, similar to what we have seen while adding worklogs. Leave the visibilitynull
if the comment is visible to all.Comment comment = new Comment(null, "Test Comment", jobin, null, new DateTime(), null, new Visibility(Type.GROUP, "jira-developers"), null));
Add the comment using the
addComment...