Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Automation: Get comment ID based on query

sebastien.devarennes
Contributor
November 23, 2021

Hi,

I am currently setting up some automation for our projects to copy a PR description into an issue's comment and update that same comment if the PR is edited.

 

So far so good when I use last or first comment, but I'd like to make it failproof by having the comment edit be based on a query result. E.g. I add AUTO-COMMENT at the top of the comment and then look for the first comment with that on an issue when time to edit.

 

I'm also extracting markdown from the github webhook, but can't seem to find a way to apply markdown into comments via automation, any clue on that too?

2 answers

1 accepted

1 vote
Answer accepted
sebastien.devarennes
Contributor
November 29, 2021

For anyone else stumbling upon this question, here is how I managed to fix my automation issue in the end

I added AUTO-PR-COMMENT at the end of the initial comment posted when a PR is Opened. You can change this text for whatever fits your liking.

Then on the "edited" condition, I added an edit comment action with a smart value for the issue. In the smart value field I put this:
{{#comments}}{{#body.endsWith("AUTO-PR-COMMENT")}}{{id}}{{/}}{{/}}

This basically means, loop over the comments. Then, for each comment, verify if the body ends with the added text. If it does, return the comment's id.

And there you have it. ;)

Beatrice Glienke
Contributor
March 22, 2022

Dear Sebastien,
thanks for the smartvalue. In general it works great. 
My situation is, that I have more than ohne comment with that Text,
so the smartvalue holds several IDs. When I than place 
{{#comments}}{{#body.endsWith("AUTO-PR-COMMENT")}}{{id}}{{/}}{{/}}

into my automation to delete these comments, it does not work as this can only hold one ID at a time.

Do you have any ideas how to handle this?

Thanks in advance.

Best,

Bea

0 votes
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

Hi @sebastien.devarennes -- Welcome to the Atlassian Community!

What type of markdown are you trying to use?  And, have you tried the same markdown in a simpler test rule which only creates a comment?

I have noted that some of the markdown possible when entering fields like comment and description cannot be automated.  Perhaps also try using HTML and the text encoding functions if you need to work-around these limitations.

Kind regards,
Bill

sebastien.devarennes
Contributor
November 29, 2021

Well I have no control over the source format, it's a Github Pull Request description, that's markdown, plain and simple.

Since the automation comment editor has no support for Markdown, I ended up simply having the description inside a no-format code block so as to keep the essential readability of the source text.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events