Use Custom Regex to Link Anywhere On Bitbucket

By on June 18, 2012

A few weeks ago we introduced Bitbucket Links, which among other things makes it possible to integrate Bitbucket to your JIRA issue tracker by using issue keys in your commit message. We have just rolled out an update for this feature that allows you to specify custom regular expressions and custom replacement URLs. Link your repositories to content that matters to you without having to wait for the Bitbucket team to roll out support for it.

To link your own custom regex and replacement URLs, enter the Links configuration in a repository’s Admin settings. Bitbucket supports the Python regex replacement syntax, and you can reference your regex capture groups in your replacement URL via the syntax \1, \2.

For example, the URL http://jira.atlassian.com/browse/\1 matched with the regex (BB-\d+) will link your JIRA issue keys that start with BB-.

We were going to include this functionality when we originally launched the feature but we were worried about the effect of ReDoS on Bitbucket’s performance. However, thanks to the power of Erik’s awesome interrupting cow utility, we are able to bound the total execution time of the linking we perform and push out this feature.

  • Anonymous

    I’ve just tried it and it doesn’t seem to work. “#(d+)” does nothing, and “#d+” makes the repo crash with “oops, error”.

    • Dylan Etkin

      Hi hsoft,

      The regex #(d+) is the system regex for issue links. System regex’s will take precedence over user provided regex’s.

      The second thing is a bug and I have rolled out a fix for that. So if you are referencing a capture group in your url that does not exist in the regex it will just not link the content.

      Cheers,

      Dylan

      • Anonymous

        If I understand correctly: if I use the format #123 in my commit messages to link to an external ticket system, I’m out of luck and can’t use the feature?

        • Dylan Etkin

          Thats correct. Links to commit hashes, bb issue keys, mentions, pull requests, repos and emoji are all reserved patterns so there can be a consistent expectation of markup across the site.

          • http://twitter.com/neogic Ben Johnson

            Translated – you’re required to use an Atlassian issue tracker in order to properly use this feature. #123 is obviously a very common pattern for citing tickets, regardless of system, so this seems like a sales driven decision rather than a usability one, which is disappointing.

            Surely the user’s regex should be allowed to override Atlassian-specific ones? I could understand the built in ones taking precedence if JIRA integration or the BB issue tracker is enabled – but I’ve just tried on a repo with both these disabled and #(d+) still doesn’t work.

  • normanr

    How do you around having to run the interrupting cow reg ex code on the main thread?

    • http://twitter.com/erikvanzijst Erik van Zijst

      We use Gunicorn (http://gunicorn.org) to run Bitbucket which is a classic pre-forked daemon using single threaded worker process.

      Each worker processes requests in its main thread, which is ideal for interruptingcow.

  • manypeopledesign

    Logos Site[www.LOGOinLOGO.com] Similar Sites : Taiwan,Hong Kong Logos Site[www.LOGOinLOGO.tw] China Logos Site[cn.LOGOinLOGO.com]