The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Stash Jira key pattern false positives

Mark Bewley
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 Champions.
August 10, 2014

I am no expert on regular expressions. I have the following key pattern:

((?<!([A-Z]{3}[0-9]{4})-?)[A-Z0-9]+-\d+)

This is so our Jira project codes match out company coding system. However the following code in a commit is detected as a Jira Issue (CLC0001-1):

prepare release 4701-CLC0001-1.0

Can I improve the key pattern to ignore this kind of match?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
TimP
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 Champions.
August 11, 2014

Hi again Mark,

I think this will do the trick:

(?<=^|[^a-zA-Z0-9-])[a-zA-Z0-9]+-\d+(?=$|[^a-zA-Z0-9-])

To explain, the first part:

(?<=^|[^a-zA-Z0-9-])

Is a positive lookbehind that means the matched key must be at the start of a line (^) or immediately after a character that isn't in the range a-z, A-Z, 0-9 or a -.

The middle part:

[a-zA-Z0-9]+-\d+

Matches one or more characters in the range a-z, A-Z or 0-9; followed by a dash; followed by one or more numbers.

The last part:

(?=$|[^a-zA-Z0-9-])

Is a positive lookahead that means the matched key must be at the of a line ($) or immediately before a character that again isn't in the range a-z, A-Z, 0-9 or a -.

If all of your issue keys are three letters followed by four numbers followed by a dash and then another number (i.e. LLL####-#) you can use a slightly stricter regular expression:

(?<=^|[^a-zA-Z0-9-])[a-zA-Z]{3}\d{4}-\d+(?=$|[^a-zA-Z0-9-])

These regular expressions are for Java applications (which most Atlassian applications are) as there are some differences between different language's implementations. There great docs on Java regular expressions if you'd like to know more, or if you want to test out other variations, you can use this neat online tool.

cheers,

Tim

Mark Bewley
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 Champions.
August 12, 2014

Thanks again Tim, I had to put an extra set of brackets around expression for Stash to accept it.

-Dintegration.jira.key.pattern=((?&lt;=^|[^a-zA-Z0-9-])[a-zA-Z]{3}\d{4}-\d+(?=$|[^a-zA-Z0-9-]))

I did have to hack the Stash and Jira databases to remove the false positives; https://confluence.atlassian.com/display/STASHKB/Reindex+JIRA+issue+keysonly seemed helpful for triggering missed keys to be added.

0 votes
TimP
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 Champions.
August 11, 2014

Hi Mark,

You could use negative lookahead/lookbehinds, non-capturing groups and/or word boundary tokens to achieve this. I'm happy to craft you a suitable regular expression, but to be sure it suits your needs can you give a few examples of what issue keys you do want to match on and what strings you don't want to match on?

cheers,

Tim

Mark Bewley
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 Champions.
August 11, 2014

Thanks Tim,

Here are some of our commits:

CNC0021-11: Only set the abort if..

2001-CNC0012: Build version...

[maven-release-plugin] prepare release 4701-CLC0001-1.0

Only the first one is a Jira Issue. (The four digits before the Jira code denotes a component, the digits after the code are a version number [when a dot is included])

Mark

TAGS
AUG Leaders

Atlassian Community Events