# HG changeset patch # User Thomas De Schampheleire # Date 2018-02-13 07:36:26 # Node ID 62b7f3d2434ae5c71539ebb0b935317e40285456 # Parent b43e77fa50ddd1c3357a68974fa988c45f8828c3 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. diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -1137,7 +1137,7 @@ def urlify_issues(newtext, repo_name): 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) 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 @@ -415,7 +415,7 @@ class TestLibs(TestController): (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 + 'interesting issue #123, err PR-56', 'interesting issue #123, err PR-56'), ]) def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected): from kallithea.lib.helpers import urlify_issues @@ -436,7 +436,7 @@ class TestLibs(TestController): ('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 FAIL67', 'issue 67'), ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix ]) def test_urlify_issues_multiple_issue_patterns(self, sample, expected):