Comment "massaging": How do I combine those changes

Originally asked by Peter Hochstrasser on 14 September 2019 (original question)


Hi

You have excellent documentation on how to take over and cleanup comments in various ways:
- impersonate comments, or rather, add a header to the comment that mimicks the original comment lead in:
" added a comment on -"
- remove @mentions in bodies to avoid unnecessary notifications
- merging new and existing comments

Now, I’d like to combine these three, such that the final comment body has:
- the original author,
- the updated date,
- no @mentions, but the displayNames of the users who have been mentioned.

All this is for an intra-instance JIRA Server sync, so, all usernames are available in both JIRA projects.

How do I do that?

Source: Jira Server/Datacenter (old community)


Answer by Francis Martens (Exalate) on 14 September 2019

Challenge accepted :smile:

The sanitization needs to be done when composing the message and sending it to the other side>
Add the code snippet from sanitize_mentions.groovy to the outgoing sync of the connection (and remove the standard replica.comments = issue.comments)

The formatting of the comment body on the receiving side can be done with following snippet (available here)

  • Line 15 calls mergeComment using a closure ‘formatBody’
  • Formatbody will apply the formatting logic.
  • Line 5 builds the header - user hyperlinked to its mail address, and the date formatted as day / month / year
  • Line 6,7,8 formats the original comment body as a quote

Results in

When the user directory on both ends are identical - like in your case, you can include the mention sanitization on the destination end - example snippet here