Autolinking to bugs

Hi,

I would like to have links to defects appear in the TeamCity UI when changes are displayed for builds.
We have this in place now but our bug tracking system has changed and the links are no longer correct.
I posted a question about this about 20 months ago and Alexey gave a good regex expression to do this.
I have tried changing it. But each time I do it seems to break the TeamCity UI & I have to revert back to
the original main-config.xml.

Typically, the check-in comments include this in the first line: Bug #<5-digit bug number>.
There are variations. Some examples are:
[ Bug #12345 ]
Bug #12345
bug # 12345
Bug # 12345
bug 12345

The bug numbers are always 5-digits.

I would like to capture the defect id and append it to the following URL as a link:
https://<machine>.<domain>.com/tracker/?func=detail&aid=
So, that the link would be something like this for example:
https://<machine>.<domain>.com/tracker/?func=detail&aid=12345

Can someone describe how to setup <comment-transformation> in main-config.xml to do this?

Thanks,
-Dave

14 comments
Comment actions Permalink

I'm not much of an expert with TeamCity, but from what I remember is uses Java regular expressions doesn't it? If so something like the following:

String resultString = subjectString.replaceAll("[Bb][Uu][Gg].*?([0-9]{5})", "https://<machine>.<domain>.com/tracker/?func=detail&aid=$1");

That'll basically search for the word 'bug' (case insensitive) and then find the next 5 digit number following it (and store it to a register).

Is that of any help to you, or does TeamCity need it in some special format to work or something?

Steve

p.s. The results of the above for your test case are:

[ Bug #12345 ]
Bug #12345
bug # 12345
Bug # 12345
bug 12345

[ https://<machine>.<domain>.com/tracker/?func=detail&aid=12345 ]
https://<machine>.<domain>.com/tracker/?func=detail&aid=12345
https://<machine>.<domain>.com/tracker/?func=detail&aid=12345
https://<machine>.<domain>.com/tracker/?func=detail&aid=12345
https://<machine>.<domain>.com/tracker/?func=detail&aid=12345

0
Comment actions Permalink

Yes, Steve, it does seem to use regular expressions. Thanks for looking into this for me, btw.

I think that I'm having trouble with the format of the <transformation-pattern> tag in main-config.xml among other things.

What I have in place currently is this:
  <comment-transformation>
    <transformation-pattern search="(:|,| )(\w{2,}\d{2,})()" replace="$1&lt;a target=&quot;_blank&quot; title=&quot;Click to open this issue in a newwindow&quot;       href=&quot;http://machine.domain.com/cgi-bin/bug_redir.cgi\?defect_id=$2&quot;&gt;$2&lt;/a&gt;$3" description="Defect Tracking link" />
  </comment-transformation>

What this would do is look for a pattern of <username><3-digit-number> (our old format of bug numbers).within a check-in comment. e.g. dleskovac123
It would be turned into a link like this: http://machine.domain.com/cgi-bin/bug_redir.cgi?defect_id=dleskovac123

But even when I change the URL to: https://machine.domain.com/tracker\?func=detail&aid
I get a critical error about needing to terminate "aid" with a semi-colon & have to revert back to the original main-config.xml file.

BTW, it may actually be enough to find any 5-digit number (surrounded by whitespace) in the check-in comments.

Thanks,
-Dave

0
Comment actions Permalink

XML requires that & character be escaped. You need to replace detail&aid to detail&amp;aid

0
Comment actions Permalink

Oh. right. Thanks, Pavel. This gets me closer. I'm still having trouble making this work as I want.

What it seems that I need to make this work for all the various ways that our developers enter check-in comments is
to simply have all 5-digit numbers within comments become links. I've been unsuccessful in changing the search pattern
to do this so far.

Here's what I have:
    <transformation-pattern search="(:|,| )(\w{2,}\d{2,})()" replace="$1&lt;a target=&quot;_blank&quot; title=&quot;Click to open this issue in a new window&quot;       href=&quot;https://machine.domain.com/tracker/?func=detail&amp;aid=$2&quot;&gt;$2&lt;/a&gt;$3" description="Defect Tracking link" />

Sorry to bother you with this. But I can't spend much more time on this. Can you suggest what would work?

Thanks,
-Dave

0
Comment actions Permalink

Probably this search pattern will work:
([^\d])(\d{5,})(.*)

0
Comment actions Permalink

Thanks, Pavel. That works if there is one bug listed in the comment. Any idea how to make it work if there are multiple bugs numbers (each bug # is always 5-digits) in the comment?

0
Comment actions Permalink

Then try this one:
([^\d])(\d{5,})()

0
Comment actions Permalink

I actually came up with that before I got your response :-)

That works pretty well. It does turn all number strings that are 5-digits or more into links which is okay.

If you can think of an easy way to change the search to only find 5-digit numbers rather than numbers of 5-digits or more (maybe 5-digits + a space?)
that would be ideal. If not, this works fine & it's pretty obvious which links would work & which wouldn't.

Thanks very much for your time.

0
Comment actions Permalink

What about this one:
([^\d])(\d{5})(?!\d)()

0
Comment actions Permalink

Ah. Perfection. Thanks very much, Pavel!

0
Comment actions Permalink

This is an easy case where you replace every numbers in the comments into an hyperlink.
It will produce unexpected behavior when the comment is "Change timeout to 20000 ms".

I have a scenario where I can guaranty that all comments use the same format, which is "Bug : id1, id2, id3".
I'm not a regex expert but I can't find a suitable regex for the search.

The VCS client we use already parse our comments and propose hyperlink.
But it is done using 2 regex. The first expression is used as a pre-filter to find expressions which contain  bug IDs.
The second expression then extracts the bare bug IDs from the result of the  first regex.

For example, if the comment is :
Change timeout to 20000 ms
Bug : 123, 456, 789

And regex 1 is : ([Bb]ug\s*:)(\s*(,\s*)?\d+)+
And regex 2 is :

(\d+)


Then first regex will match : "Bug : 123, 456, 789"
and the second regex will match : "123", "456" and "789"

Which is a better solution. BTW, the VCS client use a single attribute for both regular expressions and separate them by a newline.
Do you think TC can use a similar approach?
0
Comment actions Permalink

Looks like a good idea. Could you please submit a feature request?

0
Comment actions Permalink

Sebastien,

Does this issue look like what you suggest?

0
Comment actions Permalink

Exactly, I have put in my vote.

0

Please sign in to leave a comment.