| 1 | # -- wiki.py |
|---|
| 2 | # |
|---|
| 3 | # Author: Christian Boos <cboos@bct-technology.com> |
|---|
| 4 | # Date: 2005-09-26 |
|---|
| 5 | # License: modified BSD (same as Trac) |
|---|
| 6 | # ---------------------------------------------------------------------------- |
|---|
| 7 | |
|---|
| 8 | """Ticket links to the Mantis BTS""" |
|---|
| 9 | |
|---|
| 10 | from trac.core import * |
|---|
| 11 | from trac.wiki import IWikiSyntaxProvider, Formatter |
|---|
| 12 | |
|---|
| 13 | MANTIS_FMT = "https://your.company.com/bugtracker/view.php?id=%d" |
|---|
| 14 | |
|---|
| 15 | class MantisTicketSyntaxProvider(Component): |
|---|
| 16 | """Link for tickets directly go to mantis BTS.""" |
|---|
| 17 | |
|---|
| 18 | implements(IWikiSyntaxProvider) |
|---|
| 19 | |
|---|
| 20 | def get_link_resolvers(self): |
|---|
| 21 | return [('bug', self._format_link), |
|---|
| 22 | ('ticket', self._format_link), |
|---|
| 23 | ('mantis', self._format_link)] |
|---|
| 24 | |
|---|
| 25 | def get_wiki_syntax(self): |
|---|
| 26 | yield ( |
|---|
| 27 | # matches #... but not &#... (HTML entity) |
|---|
| 28 | r"!?(?<!&)#" |
|---|
| 29 | # optional intertrac shorthand #T... + digits |
|---|
| 30 | r"(?P<it_mantis>%s)\d+" % Formatter.INTERTRAC_SCHEME, |
|---|
| 31 | lambda x, y, z: self._format_link(x, 'mantis', y[1:], y, z)) |
|---|
| 32 | |
|---|
| 33 | def _format_link(self, formatter, ns, target, label, fullmatch=None): |
|---|
| 34 | intertrac = formatter.shorthand_intertrac_helper(ns, target, label, |
|---|
| 35 | fullmatch) |
|---|
| 36 | if intertrac: |
|---|
| 37 | return intertrac |
|---|
| 38 | try: |
|---|
| 39 | number = int(target) |
|---|
| 40 | href = MANTIS_FMT % number |
|---|
| 41 | text = target == label and "#%07d" % number or label |
|---|
| 42 | return formatter._make_ext_link(href, text, 'Mantis Bug ' + text) |
|---|
| 43 | except ValueError: |
|---|
| 44 | return label |
|---|