changeset 7158:62b7f3d2434a

issues: make issue_prefix optional again Commit 39a59e6915bb398b42c3c2a63c48a950e9d63b55 (helpers: refactor and optimize urlify_issues) made issue_prefix mandatory, while previously it could be empty. An empty issue_prefix is useful when the entire issue pattern needs to be used in the created link. For example, consider a pattern 'PR123' that needs to be translated into: http://example.com/pullrequests/PR123. This could be configured with: issue_pat = (PR\d+) issue_server_link = http://example.com/pullrequests/{id} issue_prefix = We still refuse the issue pattern when issue_prefix is not present at all.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Tue, 13 Feb 2018 08:36:26 +0100
parents b43e77fa50dd
children 9cef5615da7b
files kallithea/lib/helpers.py kallithea/tests/other/test_libs.py
diffstat 2 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Wed Feb 14 00:12:59 2018 +0100
+++ b/kallithea/lib/helpers.py	Tue Feb 13 08:36:26 2018 +0100
@@ -1137,7 +1137,7 @@
             issue_pat = CONFIG.get(k)
             issue_server_link = CONFIG.get('issue_server_link%s' % suffix)
             issue_prefix = CONFIG.get('issue_prefix%s' % suffix)
-            if issue_pat and issue_server_link and issue_prefix:
+            if issue_pat and issue_server_link and issue_prefix is not None: # issue_prefix can be empty but should be present
                 log.debug('issue pattern %r: %r -> %r %r', suffix, issue_pat, issue_server_link, issue_prefix)
             else:
                 log.error('skipping incomplete issue pattern %r: %r -> %r %r', suffix, issue_pat, issue_server_link, issue_prefix)
--- a/kallithea/tests/other/test_libs.py	Wed Feb 14 00:12:59 2018 +0100
+++ b/kallithea/tests/other/test_libs.py	Tue Feb 13 08:36:26 2018 +0100
@@ -415,7 +415,7 @@
         (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}, <a class="issue-tracker-link" href="https://bar/repo_name/">BUG12345</a>.'),
         (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
+            'interesting issue #123, err PR-56', 'interesting issue #123, err <a class="issue-tracker-link" href="http://foo/repo_name/issue/PR-56">PR-56</a>'),
     ])
     def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected):
         from kallithea.lib.helpers import urlify_issues
@@ -436,7 +436,7 @@
         ('pull request7 #', '<a class="issue-tracker-link" href="http://pr/repo_name/pr/7">PR#7</a> #'),
         ('look PR9 and pr #11', 'look <a class="issue-tracker-link" href="http://pr/repo_name/pr/9">PR#9</a> and <a class="issue-tracker-link" href="http://pr/repo_name/pr/11">PR#11</a>'),
         ('pullrequest#10 solves issue 9', '<a class="issue-tracker-link" href="http://pr/repo_name/pr/10">PR#10</a> solves <a class="issue-tracker-link" href="http://bug/repo_name/bug/9">bug#9</a>'),
-        ('issue FAIL67', 'issue FAIL67'), # no match because empty prefix
+        ('issue FAIL67', 'issue <a class="issue-tracker-link" href="http://fail/repo_name/67">67</a>'),
         ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix
     ])
     def test_urlify_issues_multiple_issue_patterns(self, sample, expected):