Originally asked by Waleed Al-Dabbas on 15 July 2022 (original question)
I am currently synchronising a Jira Service Desk instance with a Jira Software instance. To sync comments I am using the following outgoing sync
replica.comments = issue.comments.findAll{!it.internal}
I want to to sanitize mentions when synchronizing issues as shown here:
How do I add internal comments handling to the following code block in our outgoing sync?
replica.comments = issue.comments.collect {
comment ->
def matcher = comment.body =~ /\[~accountid:([\w:-]+)\]/
def newCommentBody = comment.body
matcher.each {
target = nodeHelper.getUser(it[1])?.displayName ?: "Stranger"
newCommentBody = newCommentBody.replace(it[0],target)
}
comment.body = newCommentBody
comment
}
I need to ensure that I am not sending any internal comments, I tried the following, but that introduced a NULL exception:
replica.comments = issue.comments.collect {
comment ->
if (!comment.internal){
def matcher = comment.body =~ /\[~accountid:([\w:-]+)\]/
def newCommentBody = comment.body
matcher.each {
target = nodeHelper.getUser(it[1])?.displayName ?: "Stranger"
newCommentBody = newCommentBody.replace(it[0],target)
}
comment.body = newCommentBody
comment
}
}
Comments:
Ariel Aguilar commented on 15 July 2022
You may try the following:
replica.comments = issue.comments.collect {
comment ->
def matcher = comment.body =~ /\[~accountid:([\w:-]+)\]/
def newCommentBody = comment.body
matcher.each {
target = nodeHelper.getUser(it[1])?.displayName ?: "Stranger"
newCommentBody = newCommentBody.replace(it[0],target)
}
comment.internal = false
comment.body = newCommentBody
comment
}
Kind regards,
Ariel
Waleed Al-Dabbas commented on 18 July 2022
Hi Ariel,
My understanding is this would make all comments sync (including internal comments). What I am want to do is to ensure that I do not send internal comments.
Thank you and kind regards,
Waleed
Ariel Aguilar commented on 18 July 2022
I see…
Try this:
replica.comments = issue.comments.findAll{!it.internal}.collect {
comment ->
def matcher = comment.body =~ /\[~accountid:([\w:-]+)\]/
def newCommentBody = comment.body
matcher.each {
target = nodeHelper.getUser(it[1])?.displayName ?: "Stranger"
newCommentBody = newCommentBody.replace(it[0],target)
}
comment.body = newCommentBody
comment
}
Kind regards,
Ariel