How do I replace text in the last comment posted?

Our Perforce integration writes to the Jira comments when code is submitted for a bug fix.

We would like to replace text (make hyperlinks) within the last comment posted from Perforce.

Can this be done using Automation for Jira?

1 answer

1 accepted

This widget could not be displayed.
Andreas Knecht Community Champion Jul 03, 2017

Hi Jonathan,

We don't support editing comments just yet.  It's a good suggestion though and I've raised https://codebarrel.atlassian.net/browse/AUT-419 now to track this!

We've got quite a few higher priority items in our backlog at the moment so it will be a while before we can get to this, but we'll let you know when we get a chance to work on this.

Cheers,

  Andreas

Hi Andreas,

Thanks for the quick response.

As i cannot modify the comment, is it possible to read the last comment, take the info i need and create an  'Issue Links - Link to (web link)'?

Capture.PNG

I see the example for Linking Issues  but the 'links to' needs to be type 'Web link'.

 

Capture1.PNG

Andreas Knecht Community Champion Jul 03, 2017

Hi Jonathan,

Sorry, but we don't support creating remote issue linkes yet either (https://codebarrel.atlassian.net/browse/AUT-176).  They use a different REST API compared to standard issue linkes when creating them.

Cheers,
  Andreas

Thanks.

My last idea then is to simply write the link to a multi-line text field.

Unfortunately, I'm currently struggling append to any values currently in the field:

Is this possible?

{
"update": {
"Commit ID": [{
"add": "{{issue.comments.last.body.replaceAll(\"Change: ([0-9]*), User: ([a-z]*),\", \"http://myURL/changes/$1\")}}"
}]
}
}

Andreas Knecht Community Champion Jul 03, 2017

Hi Jonathan,

So you you can't use the 'add' operation like this with text fields to add a value. 'add' is meant for multi-value fields like labels or multi-selects.

I think what you want is to set it to the old value plus the new value.  This should work:

{
"update": { "Commit ID": [{ "set": "{{issue.fields.Commit ID}} {{issue.comments.last.body.replaceAll(\"Change: ([0-9]*), User: ([a-z]*),\", \"http://myURL/changes/$1\")}}" }] } }

So you're basically setting it to the current field value + the new links.

Hope this helps!

Cheers,

  Andreas

Hi Andreas,

Thank you! this is exactly what i needed :)

The final solution:

Our Perforce integration writes to the Jira Comments field: 

Change: 142491, User: jowalton, Date: 2016/12/14 15:27:42
Description: Change filetype

  

Automation: When: Issue Commented If: Initiator is P4 integration account Then: Edit issue fields (Advanced). 

{
  "update": {
    "Commit ID": [{
      "set": "{{issue.fields.Commit ID}}{{issue.comments.last.body.split(\",\").first.replaceAll(\"Change: ([0-9]*)\", \" http://myURL/changes/$1\").concat(\"\\n\").trim()}}"
    }]
  }
}

 

Commit ID displays (multi-line text field):
http://myURL/changes/142491

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 9 hours ago in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

25 views 3 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you