diff development.ini @ 7230:d24051ce961c

issues: support generic regex replacements in issue_url and issue_prefix Issue reference linking is pretty limited: - the issue_url is a literal with only three special tokens {id}, {repo} and {repo_name}. There is no way to let the URL be dependent on other elements of the input issue reference. - The value for {id} is somewhat oddly determined by the concatenation of all parenthesized groups in the issue_pat regular expression - the link text of the resulting link is limited to the contents of the literal issue_prefix with the determined {id}. It is not possible to retain the input issue reference verbatim, nor to let the link text be dependent on other elements of the input issue reference. This commit makes the issue reference linking more flexible: - issue_prefix is replaced by the more generic issue_sub(stitution), which is a string that may contain backreferences to regex groups specified in issue_pat. This string, with backreferences resolved, is used as the link text of urlified issue references. - if issue_sub is empty, the entire text matched by issue_pat is used as the link text. - like issue_sub, also issue_url can contain backreferences to regex groups. - {id} is no longer treated as a special token, as it can be solved by generic backreferences ('\g<id>' assuming issue pattern contains something like '(P<id>\d+)'. {repo} and {repo_name} are still supported, because their value is provided externally and not normally part of the issue pattern. Documentation and ini file template is updated as well.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Sat, 10 Mar 2018 22:01:59 +0100
parents 6ae76150acbd
children 52544ad8a946
line wrap: on
line diff
--- a/development.ini	Fri Feb 16 22:30:51 2018 +0100
+++ b/development.ini	Sat Mar 10 22:01:59 2018 +0100
@@ -168,34 +168,44 @@
 ## issue tracker for Kallithea (leave blank to disable, absent for default)
 #bugtracker = https://bitbucket.org/conservancy/kallithea/issues
 
-## issue tracking mapping for commits messages
-## comment out issue_pat, issue_server, issue_prefix to enable
+## issue tracking mapping for commit messages, comments, PR descriptions, ...
+## Refer to the documentation ("Integration with issue trackers") for more details.
 
-## pattern to get the issues from commit messages
-## default one used here is #<numbers> with a regex passive group for `#`
-## {id} will be all groups matched from this pattern
+## regular expression to match issue references
+## This pattern may/should contain parenthesized groups, that can
+## be referred to in issue_server_link or issue_sub using Python backreferences
+## (e.g. \1, \2, ...). You can also create named groups with '(?P<groupname>)'.
+## To require mandatory whitespace before the issue pattern, use:
+## (?:^|(?<=\s)) before the actual pattern, and for mandatory whitespace
+## behind the issue pattern, use (?:$|(?=\s)) after the actual pattern.
 
 issue_pat = #(\d+)
 
-## server url to the issue, each {id} will be replaced with match
-## fetched from the regex and {repo} is replaced with full repository name
-## including groups {repo_name} is replaced with just name of repo
-
-issue_server_link = https://issues.example.com/{repo}/issue/{id}
+## server url to the issue
+## This pattern may/should contain backreferences to parenthesized groups in issue_pat.
+## A backreference can be \1, \2, ... or \g<groupname> if you specified a named group
+## called 'groupname' in issue_pat.
+## The special token {repo} is replaced with the full repository name
+## including repository groups, while {repo_name} is replaced with just
+## the name of the repository.
 
-## prefix to add to link to indicate it's an url
-## #314 will be replaced by <issue_prefix><id>
+issue_server_link = https://issues.example.com/{repo}/issue/\1
 
-issue_prefix = #
+## substitution pattern to use as the link text
+## If issue_sub is empty, the text matched by issue_pat is retained verbatim
+## for the link text. Otherwise, the link text is that of issue_sub, with any
+## backreferences to groups in issue_pat replaced.
 
-## issue_pat, issue_server_link, issue_prefix can have suffixes to specify
+issue_sub =
+
+## issue_pat, issue_server_link and issue_sub can have suffixes to specify
 ## multiple patterns, to other issues server, wiki or others
 ## below an example how to create a wiki pattern
 # wiki-some-id -> https://wiki.example.com/some-id
 
-#issue_pat_wiki = (?:wiki-)(.+)
-#issue_server_link_wiki = https://wiki.example.com/{id}
-#issue_prefix_wiki = WIKI-
+#issue_pat_wiki = wiki-(\S+)
+#issue_server_link_wiki = https://wiki.example.com/\1
+#issue_sub_wiki = WIKI-\1
 
 ## alternative return HTTP header for failed authentication. Default HTTP
 ## response is 401 HTTPUnauthorized. Currently Mercurial clients have trouble with