Pivotal Tracker can parse git commits and change ticket status accordingly. I am writing a PHP script that executes post-commit. It searches the commit message and if it finds the right Pivotal Ticket reference it posts it to the PT api. I'm going a bit nuts trying to figure out the regex.
Currently I have:
preg_match('/^\[#([0-9]{1,16})\]/', $commit['message'], $matches);
So the simplest example of a commit passes:
[#12345678] Made a commit
But what I need to pass are the following:
1: [finished #12345678] Made a commit //'fixed', 'complete', or 'finished' changes the status
2: I made a commit [#12345678] to a story //Can occur anywhere in the commit
The sample inputs are:
Based on our regex pattern, only the numerical portion is targeted.
To write the best/most efficient pattern to accurately match your input strings, do not use capture groups -- use
\K
.Demo Link
If you need to ensure that the before the
#numbers
comes either: [nothing],finished
,fixed
, orcomplete
then this is as refined as I can make it:Demo Link
...this is the same effect as the previous pattern, only condensed slightly:
Demo Link
If these patterns do not satisfy your actual requirements for any reason, please leave a comment and edit your question. I will adjust my answer to create a most-efficient accurate answer for you.