How do I replace text in the last comment posted?

Jonathan Walton July 3, 2017

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

1 vote
Answer accepted
andreas
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.
July 3, 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

Jonathan Walton July 3, 2017

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
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.
July 3, 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

Jonathan Walton July 3, 2017

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
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.
July 3, 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

Jonathan Walton July 4, 2017

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