How can I use a custom Script rule to sync in-line Images in Comments (Zendesk to Jira)

Originally asked by Michael on 16 September 2021 (original question)


Per the title, my use case is for syncing data between Zendesk and Jira.

I have gotten description formatting to sync using:

replica.description = nodeHelper.getHtmlDescription(Zendesk3.issue)
Jira.issue.description = nodeHelper.toMarkDownFromHtml(replica.description)

and comment formatting to sync using a custom script rule.

def includeComments = commentHelper.mergeComments(Jira.issue, replica).collect{it}
Jira.issue.comments += nodeHelper.toMarkDownComments(includeComments)

However, any in-line image in a note in Zendesk results in a Jira comment that looks like:

Exalate support had asked me (In a zoom call) to post a question over here to document how to use the html to wiki feature in the script.


Answer by Ariel Aguilar on 05 November 2021

Solution

If you look at the content being sent in the comment containing attachments - it contains something like

​ !(https://d3v-francis.zendesk.com/attachments/token/AzEkdy3kmZ8X9MsqzAlG8Aarg/?name=hpalm-jira.png)​

By converting it into something like

!

Jira will be able to show the inline attachment.

Note that works only if the attachments is accessible under that token. The day that the token is invalidated, the attachment will not be reachable, so this is not really a solution.

Implementation

It is easy to replace the !(<filename>) into !<filenname>! by using following construct

Line 1 uses the mergeComments to iterate over all the comments in the replica and summons the closure to be run.
Line 4 calls the replaceAll groovy string method. For each string segment matching the regexp a replacement is created. The replacement contains the necessary code to show the image with a maximum width of 512.

Code is available here