mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Auto-link bug reports in comments
Automatically detect references to Flyspray bug reports in comments and convert them to links to the Arch Linux bug tracker. Implements FS#52008. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
0aa67b278a
commit
efa8da5ca2
1 changed files with 15 additions and 0 deletions
|
@ -26,6 +26,20 @@ class LinkifyExtension(markdown.extensions.Extension):
|
||||||
md.preprocessors.add('linkify', LinkifyPreprocessor(md), '_end')
|
md.preprocessors.add('linkify', LinkifyPreprocessor(md), '_end')
|
||||||
|
|
||||||
|
|
||||||
|
class FlysprayLinksPreprocessor(markdown.preprocessors.Preprocessor):
|
||||||
|
_fsre = re.compile(r'\b(FS#(\d+))\b')
|
||||||
|
_sub = r'[\1](https://bugs.archlinux.org/task/\2)'
|
||||||
|
|
||||||
|
def run(self, lines):
|
||||||
|
return [self._fsre.sub(self._sub, line) for line in lines]
|
||||||
|
|
||||||
|
|
||||||
|
class FlysprayLinksExtension(markdown.extensions.Extension):
|
||||||
|
def extendMarkdown(self, md, md_globals):
|
||||||
|
preprocessor = FlysprayLinksPreprocessor(md)
|
||||||
|
md.preprocessors.add('flyspray-links', preprocessor, '_end')
|
||||||
|
|
||||||
|
|
||||||
class GitCommitsPreprocessor(markdown.preprocessors.Preprocessor):
|
class GitCommitsPreprocessor(markdown.preprocessors.Preprocessor):
|
||||||
_oidre = re.compile(r'(\b)([0-9a-f]{7,40})(\b)')
|
_oidre = re.compile(r'(\b)([0-9a-f]{7,40})(\b)')
|
||||||
_repo = pygit2.Repository(repo_path)
|
_repo = pygit2.Repository(repo_path)
|
||||||
|
@ -102,6 +116,7 @@ def main():
|
||||||
text, pkgbase = get_comment(conn, commentid)
|
text, pkgbase = get_comment(conn, commentid)
|
||||||
html = markdown.markdown(text, extensions=['fenced_code',
|
html = markdown.markdown(text, extensions=['fenced_code',
|
||||||
LinkifyExtension(),
|
LinkifyExtension(),
|
||||||
|
FlysprayLinksExtension(),
|
||||||
GitCommitsExtension(pkgbase),
|
GitCommitsExtension(pkgbase),
|
||||||
HeadingExtension()])
|
HeadingExtension()])
|
||||||
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + \
|
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + \
|
||||||
|
|
Loading…
Add table
Reference in a new issue