Updating issue comments via workflow

Hello,

Unfortunately can't find the answer in workflow documentation.

Is it possible in workflow to change a text of a new comment during a submission or update text for existing comment? 

Is it possible to delete existing comment via workflow?

Thank you for your assistance.

4 comments
Comment actions Permalink
Official comment

Hello,

 

To change a text of a comment during submission you can use the following code:

```

when issue.comments.added.isNotEmpty {

  for each comment in issue.comments.added {

    comment.text = ... // update the text

  }

}

```

 

To update the text of the existing comment, you can just access the existing comment via `issue.comments` and update the one you need.

 

It is not possible to delete an existing comment via workflow.

 

Comment actions Permalink

Hello,

Maria, thank you for the reply!

Your code works fine for me.

But, now I see that the problem was with the way I tried to edit the text. I've tried to use remove() and replace() methods of string:

...

for each comment in issue.comments.added {
// this works fine
comment.text = "Updated text!";
// it doesn't work
comment.text.remove("text", opts);
// it doesn't work as well
comment.text.replace("Updated", "Replaced");
}

...

Each time new comment added - the text is "Updated text!". 

At this time I finished my task with substring() method. But it will be interesting for me to know how to get works remove() and replace() methods.

Thank you!

0
Comment actions Permalink

Hello,

Both replace() and remove() do not modify the string: they return a new string instead. So what you need is

comment.text = comment.text.remove("text", opts);

comment.text = comment.text.replace("Updated", "Replaced");

0
Comment actions Permalink

I've tried as you suggested. Unfortunately, it still doesn't work:

for each comment in issue.comments.added {
comment.text = "Updated text.";
message(comment.text.remove("text", opts));
}

And I see the message "Updated text."

comment.text = comment.text.remove("text", opts);

Not working also.

0

Please sign in to leave a comment.