Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira automation. Trying to extract only text comments from comments section

Raju Mandapaka
Contributor
November 19, 2021

Hi,

We are working on an automation which clone certain issues, as a part of it we want to clone only text comments (not images or attachments).

Can someone help with regex expressions or any any thing, which checks the comments and copies to new field in cloned ticket.

I tried this

{{#issue.comments}}
*Comment by* : {{author.displayName}} at: {{created}}
{{body}}
{{/}}

but even images are also copying, but not in a readable format (refer below image)

pic 4.PNG

Thanks,

Raju

 

1 answer

1 vote
Bill Sheboy
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.
November 19, 2021

Hi @Raju Mandapaka 

Would you please post an image of your complete rule for context?  That may help the community to offer ideas.  Thanks!

Until then, I am guessing that you are:

  • cloning a trigger issue, and
  • editing the cloned issue to add comments...
  • either as a block in one new comment or one-by-one with advanced branching.

To do what you ask, I recommend writing to the audit log (or using the REST API) to look at example comments' contents that you want to clean up.  That will show what you need to remove/replace when copying the comments.

Kind regards,
Bill

Raju Mandapaka
Contributor
November 19, 2021

@Bill Sheboy 

Let me add some context on this, this rule is manually triggered by users, who ever wants to clone the issues.

This Automation will clones Epic & its stories also (along with attachments), Now i would like to copy comments also, when ever i am trying to copy comments it is copying attachments also which is in unreadable format (showing a error as failed to load)

Rule Pics.

Rule-1 --> which clones Epics

Rule-1.PNG

Rule -2 --> which clone child user stories.

Rule-2.PNG

 

Code i used for Attachments :

{{issue.description.replaceAll("!","_")}}

*Attachments links from Original Ticket*

{{#issue.attachment}}

- [ {{filename}} | {{content}} ] - {{size}} Bytes - {{author.displayName}} - {{created.jiraDate}}

{{/issue.attachment}}

Image for attachments.

rule-3.PNG

In similar way i would like to copy all comments from original ticket for which i used below code.

{{#issue.comments}}
*Comment by* : {{author.displayName}} at: {{created}}
{{body}}
{{/}}

But it is copying images also, which i didn't want.

 

Hope this context is useful.

Thanks,

Raju

Bill Sheboy
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.
November 19, 2021

Thanks for that information.

Have you confirmed that your "copy" of attachments is duplicating them or is it just pointing to the links from the source issue?

For comments handling as you have asked, again I suggest:

To do what you ask, I recommend writing to the audit log (or using the REST API) to look at example comments' contents that you want to clean up.  That will show what you need to remove/replace when copying the comments.

You would use the text functions, such as remove() or replaceAll() to eliminate any embedded images/attachments from comment text. 

Please note that your adding of attachments earlier *will* still include those as links; they just would not be with the comment text.

Raju Mandapaka
Contributor
November 22, 2021

@Bill Sheboy 

Is there any smart value which gives us what type of comment is added (either text type/image type).

 

Thanks,

Raju

Bill Sheboy
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.
November 23, 2021

As comments could contain a variety of content (plain text and otherwise) there is no single type for a comment.  You would need to check the body for any markup/tags indicating things like images or attachments.

Raju Mandapaka
Contributor
November 28, 2021

 

@Bill Sheboy 

I found that all the comments which contains images starts with ! and ends with !, which i got it from audit log info

Eg: 

 !pic-3.PNG|width=1007,height=489! 

now can you help me with any regex expressions which doesn't pic these, i tried like 

{{#if(issue.comments.body.startsWith("hello"))}}
*Comment by* : {{author.displayName}} at: {{created}}
{{body}}
{{/}}

 

just to copy only hello comment from set of comments. need your assistance in this issue.

 

Thanks,

Raju

Bill Sheboy
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.
November 29, 2021

Perhaps try replaceAll() as I suggested using a simple expression which looks for the common elements between the exclamation points:

{{issue.comment.body.replaceAll("(!.*width=.*height=.*!)", "")}}

You may need to experiment with this as I am not familiar with all possible formats of images in the markup.

Suggest an answer

Log in or Sign up to answer