diff --git a/kallithea/tests/other/test_libs.py b/kallithea/tests/other/test_libs.py
--- a/kallithea/tests/other/test_libs.py
+++ b/kallithea/tests/other/test_libs.py
@@ -403,6 +403,66 @@ class TestLibs(TestController):
from kallithea.lib.helpers import urlify_text
assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
+ @parametrize('issue_pat,issue_server,issue_prefix,sample,expected', [
+ (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
+ 'issue #123', 'issue #123'),
+ (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
+ 'issue#456', 'issue#456'),
+ (r'#(\d+)', 'http://foo/{repo}/issue/{id}', 'PR',
+ 'interesting issue #123', 'interesting issue PR123'),
+ (r'BUG\d{5}', 'https://bar/{repo}/{id}', 'BUG',
+ 'silly me, I did not parenthesize the {id}, BUG12345.', 'silly me, I did not parenthesize the {id}, BUG.'),
+ (r'BUG(\d{5})', 'https://bar/{repo}/', 'BUG',
+ 'silly me, the URL does not contain {id}, BUG12345.', 'silly me, the URL does not contain {id}, BUG12345.'),
+ (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '',
+ 'interesting issue #123, err PR-56', 'interesting issue #123, err PR-56'), # no match because empty prefix
+ ])
+ def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected):
+ from kallithea.lib.helpers import urlify_issues
+ config_stub = {
+ 'sqlalchemy.url': 'foo',
+ 'issue_pat': issue_pat,
+ 'issue_server_link': issue_server,
+ 'issue_prefix': issue_prefix,
+ }
+ # force recreation of lazy function
+ with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
+ with mock.patch('kallithea.CONFIG', config_stub):
+ assert urlify_issues(sample, 'repo_name') == expected
+
+ @parametrize('sample,expected', [
+ ('abc X5', 'abc #5'),
+ ('abc pullrequest #6 xyz', 'abc PR#6 xyz'),
+ ('pull request7 #', 'PR#7 #'),
+ ('look PR9 and pr #11', 'look PR#9 and PR#11'),
+ ('pullrequest#10 solves issue 9', 'PR#10 solves bug#9'),
+ ('issue FAIL67', 'issue FAIL67'), # no match because empty prefix
+ ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix
+ ])
+ def test_urlify_issues_multiple_issue_patterns(self, sample, expected):
+ from kallithea.lib.helpers import urlify_issues
+ config_stub = {
+ 'sqlalchemy.url': 'foo',
+ 'issue_pat': 'X(\d+)',
+ 'issue_server_link': 'http://main/{repo}/main/{id}/',
+ 'issue_prefix': '#',
+ 'issue_pat_pr': '(?:pullrequest|pull request|PR|pr) ?#?(\d+)',
+ 'issue_server_link_pr': 'http://pr/{repo}/pr/{id}',
+ 'issue_prefix_pr': 'PR#',
+ 'issue_pat_bug': '(?:BUG|bug|issue) ?#?(\d+)',
+ 'issue_server_link_bug': 'http://bug/{repo}/bug/{id}',
+ 'issue_prefix_bug': 'bug#',
+ 'issue_pat_empty_prefix': 'FAIL(\d+)',
+ 'issue_server_link_empty_prefix': 'http://fail/{repo}/{id}',
+ 'issue_prefix_empty_prefix': '',
+ 'issue_pat_absent_prefix': 'FAILMORE(\d+)',
+ 'issue_server_link_absent_prefix': 'http://failmore/{repo}/{id}',
+ }
+ # force recreation of lazy function
+ with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
+ with mock.patch('kallithea.CONFIG', config_stub):
+ assert urlify_issues(sample, 'repo_name') == expected
+
@parametrize('test,expected', [
("", None),
("/_2", '2'),