简体   繁体   中英

JIRA id validation in git commit message

I am using below Regex pattern on Bitbucket application to validate Jira id in commit message

[A-Z][A-Z_0-9]+-[0-9]

Sample commit message:

CLB-181 CLB-168 CLB-84::**** testing 3 jira id CRE-507 validation

Need to validate Jira id(s) before :: , ie CLB-181 CLB-168 CLB-84:: but not after ::** Testing 3 jira id CRE-507 validation .

Perhaps this is what you are looking for

.+(?=::)
a= 'CLB-181 CLB-168 CLB-84:: testing 3 jira id CRE-507 validation'
re.findall(r'(.+(?=::)', a )

output --> ['CLB-181 CLB-168 CLB-84']

The place many people get hung up in these problems is that they try to match against the entire string. Change the problem so it's easier to solve. In this case, do your steps backward.

Break up the commit message so you have just the portion that you are interested in. Keeping the first element from splitting on :: is one way to do it:

my( $preamble ) = split /::/, $commit_message;

Now that you have the first part of the commit message, get the Jira IDs. Matching groups of non-whitespace in list context returns all the matches:

my @jira_ids = $preamble =~ m/(\S+)/g;

Now validate whatever is in @jira_ids .

There are many other ways to do the same thing, so choose one that is simple and maps onto how you and those around you think about the problem (adjusting for problem redefinition :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM