Forums

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

How can I verify whether a string is the same as an existing issue in my Jira instance?

Brock Jolet
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 17, 2023

Background

I have been using one of the built-in Automation templates to automatically link issues that are mentioned in comments. Default settings are below:

link issues default.png

This little rule works pretty well and can be run per project to reduce global rule executions.

However, some of my users started pasting data tables into comments with strings that matched the expression but were not Jira keys. This resulted in a number of emails to my inbox about the rule failing.

 

Potential Fix

I tried to reduce the number of false alerts by making the rule a little more complex. The idea was to verify that a string was an actual Jira issue, in my instance, before trying to link to it. 

After the compare block, I added a Lookup issues block with the same expression from above as a smart value in the JQL query. This accurately searches the instance for those items. I can then return the results in a follow-up compare block as a list of matching keys.

link issues updated.png

If the list of keys is empty, my rule stops, as expected.

If the original string was a partial match to any actual keys, the Lookup issues will only return the matching keys and the rule can continue as planned.

However, if none of the values in the comment matched any Jira issue keys, I still get an error in my inbox. The rule is working as planned, but the Lookup issues failed because there was no match.

 

Lookup issues
There was an error executing a search during custom value definition: .
Custom Smart Value JQL Search: "issue in (HD-3000)" - Issue does not exist or you do not have permission to see it.

 

Question

Is there a better way to validate if a string matches an issue key that won't treat a false result as an error?

Also, this rule has to be treated as global unlike the original so that the Lookup issues can work correctly. I don't suppose I can get around that.

2 answers

1 accepted

2 votes
Answer accepted
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.
July 17, 2023

Hi @Brock Jolet 

Adding to Mark's suggestions...

First, do you ever expect more than one issue key in the comment, particularly on different text lines?  If so, match() will not work as you expected.  Instead you would need to split() the lines, match(), and then recombine the results to form your JQL for the Lookup Issues action.

Next to trap that error you noted, let's assume there is one-and-only-one issue key in the comment.  It would be possible to prevent the error by a work-around:

  • before the call to Lookup Issues, as the JQL handling is the problem...
  • call the REST API with a web request, to get the project properties for the possible issue key (e.g., the text to the left of the hyphen)
  • check the results for errors, and only proceed if the project properties were valid

Kind regards,
Bill

Brock Jolet
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 19, 2023

Hey Bill!

Once again, you've given me the answer that I needed. Using the API call, I'm able to add an If check looking for {{webResponse.statusCategory}} = SUCCESS.

Cheers!

Like Bill Sheboy likes this
0 votes
Mark Segall
Community Champion
July 17, 2023

I would change that last condition to something like this:

  • {{lookupIssues.size}}
    Greater Than
    0

This will make it so if no issues are returned from the lookup issues action, it will not proceed any further.

Brock Jolet
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 17, 2023

Hey Mark,

I see the logic here, but what I have appears to work for the conditional.

The "error" is happening before then. When the Lookup issues query contains invalid issue keys, it doesn't gracefully stop. I think I'll have to do an if/then before the Lookup issues, but I'm not sure what to base it on.

Mark Segall
Community Champion
July 17, 2023

To confirm my understanding, you're saying that the lookup issues errors when the regex picks up a failed string?  In this case, you could try adding the condition I provided previously just after your first lookup issues action. 

Brock Jolet
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 17, 2023

Hey Mark,

As an example, a user may paste this into a comment:

Please order a printer, model HD-1000.

In this case, the string HD-1000 matches the regex in the first conditional. It looks like a Jira key. So the Lookup issues block runs this query:

issue in (HD-1000)

Since HD-1000 is not an existing issue key in our instance, the lookup fails. This sends an error to my email.

Like Dario Seidl likes this
Mark Segall
Community Champion
July 17, 2023

Ahh that makes sense.  Hmm - There may not be a way around this one because the mechanism you're using to validate whether it's legitimate or not will error out when it's not legitimate.  If you trust your rule, you could disable error notifications for it. I don't believe you're getting around that error unfortunately.

Like # people like this
Brock Jolet
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 17, 2023

Yeah, that's unfortunate, but I think you're right. Thanks for the help!

Like Mark Segall likes this

Suggest an answer

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

Atlassian Community Events