SCM integration example local_replace.py
Bernhard Reiter <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.devel,gmane.comp.bug-tracking.roundup.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, as you may know it is possible to have the webinterface interpret strings for example to link to an SCM. For example see http://issues.roundup-tracker.org/msg5316 where it links to the roundup source directory. It is possible to customize this behaviour by using a local_replace.py file by playing a file in extensions, here is the one used by our tracker: https://sourceforge.net/p/roundup/code/ci/default/tree/website/issues/extensions/local_replace.py I'm attaching another example with a) a link to github b) Using more readable regular expressions with options "re.X". (If someone likes to put this on the wiki or the repo, feel free to. I lack the time in the next days. I think we should add the possibilities of local_replace.py and other integrations with scm into the documentation.) Hope it is helpful, Bernhard -- www.intevation.de/~bernhard +49 541 33 508 3-3 Intevation GmbH, Osnabrück, DE; Amtsgericht Osnabrück, HRB 18998 Geschäftsführer Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner ------------------------------------------------------------------------------ _______________________________________________ Roundup-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/roundup-devel
local_replace.py
(application/x-python, 4.6 KB)
import re
hg_url_base = r'https://github.com/Intevation/'
substitutions = [ (re.compile(r'debian:\#(?P<id>\d+)'),
r'<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=\g<id>">debian#\g<id></a>' ),
(re.compile(r'\#(?P<ws>\s*)(?P<id>\d+)'),
r"<a href='issue\g<id>'>#\g<ws>\g<id></a>" ),
(re.compile(r'(?P<prews>^|\s+)issue(?P<ws>\s*)(?P<id>\d+)'),
r"\g<prews><a href='issue\g<id>'>issue\g<ws>\g<id></a>" ),
# matching revison number or hash
(re.compile(r'(?P<prews>(^|\s+))(?P<revstr>(revision|rev|r)\s?)(?P<revision>([1-9][0-9]*)|[0-9a-fA-F]{4,40})(?P<post>\W+|$)'),
r'\g<prews><a href="' + hg_url_base + r'intelmq/commit/' + '\g<revision>">\g<revstr>\g<revision></a>\g<post>'),
(re.compile(r"""
(?P<prews>(^|\s+)) # start w beginning of line or at least 1 whitespace
(?P<revstr>(intelmq)?[:/]?) # optional keyword 'mailgen' and opt sep char
(?P<revshort>([0-9a-fA-F]{7})) # mandatory 7 chars of hex code
(?P<revrest>([0-9a-fA-F]{0,33})) # optional additional hex code 0-33 chars
(?P<post>\W+|$) # followed by >=1 non-alpha-num char or end of line
""", re.X),
r'\g<prews><a href="' + hg_url_base + r'intelmq/commit/' + '\g<revshort>\g<revrest>">\g<revstr>\g<revshort></a>\g<post>'),
(re.compile(r"""
(?P<prews>(^|\s+)) # start w beginning of line or at least 1 whitespace
(?P<revstr>(mailgen)[:/]?) # keyword 'mailgen' followed by optional sep char
(?P<revshort>([0-9a-fA-F]{7})) # mandatory 7 chars of hex code
(?P<revrest>([0-9a-fA-F]{0,33})) # optional additional hex code 0-33 chars
(?P<post>\W+|$) # followed by >=1 non-alpha-num char or end of line
""", re.X),
r'\g<prews><a href="' + hg_url_base + r'intelmq-mailgen/commit/' + '\g<revshort>\g<revrest>">\g<revstr>\g<revshort></a>\g<post>'),
(re.compile(r"""
(?P<prews>(^|\s+)) # start w beginning of line or at least 1 whitespace
(?P<revstr>(manager)[:/]?) # keyword 'manager' followed by optional sep char
(?P<revshort>([0-9a-fA-F]{7})) # mandatory 7 chars of hex code
(?P<revrest>([0-9a-fA-F]{0,33})) # optional additional hex code 0-33 chars
(?P<post>\W+|$) # followed by >=1 non-alpha-num char or end of line
""", re.X),
r'\g<prews><a href="' + hg_url_base + r'intelmq-manager/commit/' + '\g<revshort>\g<revrest>">\g<revstr>\g<revshort></a>\g<post>'),
(re.compile(r"""
(?P<prews>(^|\s+)) # start w beginning of line or at least 1 whitespace
(?P<revstr>(certtools)[:/]?) # keyword 'mailgen' followed by optional sep char
(?P<revshort>([0-9a-fA-F]{7})) # mandatory 7 chars of hex code
(?P<revrest>([0-9a-fA-F]{0,33})) # optional additional hex code 0-33 chars
(?P<post>\W+|$) # followed by >=1 non-alpha-num char or end of line
""", re.X),
r'\g<prews><a href="' + r'https://github.com/certtools/intelmq/commit/' + '\g<revshort>\g<revrest>">\g<revstr>\g<revshort></a>\g<post>'),
]
def local_replace(message):
for cre, replacement in substitutions:
message = cre.sub(replacement, message)
return message
def init(instance):
instance.registerUtil('localReplace', local_replace)
def quicktest(msgstr, should_replace = True):
if not should_replace:
print "(no)",
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
if "__main__" == __name__:
print "Replacement examples. '(no)' should result in no replacement:"
quicktest(" debian:#222")
quicktest(" #555")
quicktest("issue333")
quicktest(" revision 222")
quicktest(" r 222")
quicktest(" wordthatendswithr 222", False)
quicktest(" references", False)
quicktest(" too many spaces r 222", False)
quicktest("re-evaluate", False)
quicktest("rex140eb", False)
quicktest("rev 012", False) # too short for a hg hash
quicktest("rev 0123")
quicktest("re140eb")
quicktest(" r7140eb")
quicktest(" rev7140eb ")
quicktest("rev7140eb")
quicktest("rev7140eb,")
quicktest("rev4891:ad3d628e73f2", False)
quicktest("hg4891:ad3d628e73f2", False)
quicktest("changeset: 4542:46239c21a1eb", False)
quicktest("mailgen2a53f77")
quicktest("manager83318fcc66e365848c8ae07cbf02ed80f5e89591")
quicktest("manager/83318fcc66e365848c8ae07cbf02ed80f5e89591")
quicktest("manager:83318fcc")
quicktest("37a3db9850c7ae67f586693b3393d5b5086d2177")
quicktest("certtools:87409c6b40a64eec3fc6b8f2a749fab46ee3715d")
signature.asc
(application/pgp-signature, 473 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJX7mytAAoJEDxD9Mjv9dQqxxAH/A9PADGiGRSArsJ22GJ89T5X UPDhGQIFuvRIOUMYnQm3j3oALIcvzMdUKQ3gUHzQWX+O6Ryvlbf9rONdmBJO1Vxy lA7xJVv/cL3fFrVMA90HM7rXm/KKJ1pYz3rnrBGAz5ljxi3ywzYofLTdo02FpMhB WIaoziU05qvomjRUNuNSoQ8qsio1/TuZoKEV5VCC8PGLKyqeI6Xc4MuzS5icDECz tyboJZkme1TgImrhtg6PaS19d7zoCjSe4S6/1A9/f8iHnbE5kFuwe+P2XKm7j2yK x3MNrdXF+iqGMVysl1raQ5SWL856uKAFmF9sJc1P/QBuN76xqdVjVBrPZAcBhQE= =ymOW -----END PGP SIGNATURE-----