how to update a comment inside of jira with Plugin?

Ma Hao January 14, 2014

Hi,

I need to update a comment,

I can get the comment id and author.

Just need to update the comment body with plugin.

Which class should i use?

I have tried CommentManager.Update().

But i can not find how to update the comment body.

void update(Comment comment,
            boolean dispatchEvent)
Persists the updated comment.
Parameters:
comment - to update
dispatchEvent - if true then an event of type EventType.ISSUE_COMMENT_EDITED_ID will be dispatched and any notifications listening for that event will be triggered. If false no event will be dispatched.
Throws:
IllegalArgumentException - if comment passed in is null or its id is null

1 answer

1 accepted

1 vote
Answer accepted
Silviu Burcea
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2014

I have had a look in the JIRA sources and you need to get a MutableComment in the first place. Note that getCommentById returns a Comment, but under the hood, there is actually a MutableComment). You can setBody with this interface. The rest is simple, as you have already found out the update method in CommentManager.

Ma Hao January 14, 2014

Thanks so much,

I will try it.

Ma Hao January 16, 2014

HI Silviu,

I can see the mutableComment description says:

Represents a comment's in JIRA. After calling any 'setter' method, you will need to call CommentService.update(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.comments.MutableComment, boolean, com.atlassian.jira.util.ErrorCollection) which does permission checking or CommentManager.update(com.atlassian.jira.issue.comments.Comment, boolean) which will just store the provided object, to persist the change to the database.

https://docs.atlassian.com/jira/6.1.5/com/atlassian/jira/issue/comments/MutableComment.html

Should i use commentService or CommentManager to update comment?

What the different between them?

If i want to use CommentService to update the comment, how to get the ErrorCollection instance?

Silviu Burcea
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2014

Hi,

CommentService uses CommentManager under the hood. If you want, you can use CommentService to also check for permissions, but I think you will only need CommentManager.
As for ErrorCollection, here is how JIRA does:

SimpleErrorCollection errorCollection = new SimpleErrorCollection();

Suggest an answer

Log in or Sign up to answer