This article shows how to synchronize comments.

You can handle comments in different ways:

Source side

Outgoing sync

You can decide which comments to share:

Synchronize only public comments

replica.comments = commentHelper.filterLocal(issue.comments)

Send only comments created by a certain user 

//send only Luke Skywalker's comments
replica.comments = issue.comments.findAll { comment -> == "Luke Skywalker" }

Destination side

Incoming sync

You can perform  the following actions on comments locally:

  • merge local and remote comments
  • add remote comments
  • filter: add comments created by a specific user
  • format comments using custom formatting

You can add new comments and keep the existing comments updated using mergeComments comment helper.

This method would prepend the comment content with the author of the original comment. This is the default behavior.

issue.comments = commentHelper.mergeComments(issue, replica)

Apply received comments without custom formatting

The comment will be added just with the body from the original comment, without an extra message.

issue.comments = commentHelper.mergeComments(issue, replica, {it})

Manipulate the comments via helper methods

With the help of commentHelper methods you can manipulate comments and define how to apply received comments on the local issue.

// Format each remote comment - add the author

issue.comments = commentHelper.mergeComments(issue, replica,                       
                       comment ->
                       comment.body =
                          "[" + +
                                  "| mailto:" + + "]" +
                                  " commented: \n" +
                          "{quote}\n" +
                          comment.body + ";\n" +

Gather statistic from comments

This is an example of groovy collection methods usage. It helps to get better control over the collection contents.

def numberOfCommentsPerAuthors = issue.comments.inject([:]) { result, comment ->   
  def numberOfCommentsPerAuthor = result[]
  numberOfCommentsPerAuthor = numberOfCommentsPerAuthor ?: 0
  result[] = numberOfCommentsPerAuthor + 1

Example for a comment list
   body:"I'm a jedi knight, like my father before me"
   body:"I am your father!"

numberOfCommentsPerAuthors would be ["luke.skywalker" : 2,"darth.vader" : 1]

See Also