Mercurial > kallithea
comparison docs/setup.rst @ 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 | 1969f7dfb6b0 |
children | 9937ae52f167 |
comparison
equal
deleted
inserted
replaced
7229:e5a7f8f41370 | 7230:d24051ce961c |
---|---|
533 Integration with issue trackers | 533 Integration with issue trackers |
534 ------------------------------- | 534 ------------------------------- |
535 | 535 |
536 Kallithea provides a simple integration with issue trackers. It's possible | 536 Kallithea provides a simple integration with issue trackers. It's possible |
537 to define a regular expression that will match an issue ID in commit messages, | 537 to define a regular expression that will match an issue ID in commit messages, |
538 and have that replaced with a URL to the issue. To enable this simply | 538 and have that replaced with a URL to the issue. |
539 uncomment the following variables in the ini file:: | 539 |
540 | 540 This is achieved with following three variables in the ini file:: |
541 issue_pat = (?:^#|\s#)(\w+) | 541 |
542 issue_server_link = https://issues.example.com/{repo}/issue/{id} | 542 issue_pat = #(\d+) |
543 issue_prefix = # | 543 issue_server_link = https://issues.example.com/{repo}/issue/\1 |
544 issue_sub = | |
544 | 545 |
545 ``issue_pat`` is the regular expression describing which strings in | 546 ``issue_pat`` is the regular expression describing which strings in |
546 commit messages will be treated as issue references. A match group in | 547 commit messages will be treated as issue references. The expression can/should |
547 parentheses should be used to specify the actual issue id. | 548 have one or more parenthesized groups that can later be referred to in |
548 | 549 ``issue_server_link`` and ``issue_sub`` (see below). If you prefer, named groups |
549 The default expression matches issues in the format ``#<number>``, e.g., ``#300``. | 550 can be used instead of simple parenthesized groups. |
551 | |
552 If the pattern should only match if it is preceded by whitespace, add the | |
553 following string before the actual pattern: ``(?:^|(?<=\s))``. | |
554 If the pattern should only match if it is followed by whitespace, add the | |
555 following string after the actual pattern: ``(?:$|(?=\s))``. | |
556 These expressions use lookbehind and lookahead assertions of the Python regular | |
557 expression module to avoid the whitespace to be part of the actual pattern, | |
558 otherwise the link text will also contain that whitespace. | |
550 | 559 |
551 Matched issue references are replaced with the link specified in | 560 Matched issue references are replaced with the link specified in |
552 ``issue_server_link``. ``{id}`` is replaced with the issue ID, and | 561 ``issue_server_link``, in which any backreferences are resolved. Backreferences |
553 ``{repo}`` with the repository name. Since the # is stripped away, | 562 can be ``\1``, ``\2``, ... or for named groups ``\g<groupname>``. |
554 ``issue_prefix`` is prepended to the link text. ``issue_prefix`` doesn't | 563 The special token ``{repo}`` is replaced with the full repository path |
555 necessarily need to be ``#``: if you set issue prefix to ``ISSUE-`` this will | 564 (including repository groups), while token ``{repo_name}`` is replaced with the |
556 generate a URL in the format: | 565 repository name (without repository groups). |
566 | |
567 The link text is determined by ``issue_sub``, which can be a string containing | |
568 backreferences to the groups specified in ``issue_pat``. If ``issue_sub`` is | |
569 empty, then the text matched by ``issue_pat`` is used verbatim. | |
570 | |
571 The example settings shown above match issues in the format ``#<number>``. | |
572 This will cause the text ``#300`` to be transformed into a link: | |
557 | 573 |
558 .. code-block:: html | 574 .. code-block:: html |
559 | 575 |
560 <a href="https://issues.example.com/example_repo/issue/300">ISSUE-300</a> | 576 <a href="https://issues.example.com/example_repo/issue/300">#300</a> |
577 | |
578 The following example transforms a text starting with either of 'pullrequest', | |
579 'pull request' or 'PR', followed by an optional space, then a pound character | |
580 (#) and one or more digits, into a link with the text 'PR #' followed by the | |
581 digits:: | |
582 | |
583 issue_pat = (pullrequest|pull request|PR) ?#(\d+) | |
584 issue_server_link = https://issues.example.com/\2 | |
585 issue_sub = PR #\2 | |
586 | |
587 The following example demonstrates how to require whitespace before the issue | |
588 reference in order for it to be recognized, such that the text ``issue#123`` will | |
589 not cause a match, but ``issue #123`` will:: | |
590 | |
591 issue_pat = (?:^|(?<=\s))#(\d+) | |
592 issue_server_link = https://issues.example.com/\1 | |
593 issue_sub = | |
561 | 594 |
562 If needed, more than one pattern can be specified by appending a unique suffix to | 595 If needed, more than one pattern can be specified by appending a unique suffix to |
563 the variables. For example:: | 596 the variables. For example, also demonstrating the use of named groups:: |
564 | 597 |
565 issue_pat_wiki = (?:wiki-)(.+) | 598 issue_pat_wiki = wiki-(?P<pagename>\S+) |
566 issue_server_link_wiki = https://wiki.example.com/{id} | 599 issue_server_link_wiki = https://wiki.example.com/\g<pagename> |
567 issue_prefix_wiki = WIKI- | 600 issue_sub_wiki = WIKI-\g<pagename> |
568 | 601 |
569 With these settings, wiki pages can be referenced as wiki-some-id, and every | 602 With these settings, wiki pages can be referenced as wiki-some-id, and every |
570 such reference will be transformed into: | 603 such reference will be transformed into: |
571 | 604 |
572 .. code-block:: html | 605 .. code-block:: html |
573 | 606 |
574 <a href="https://wiki.example.com/some-id">WIKI-some-id</a> | 607 <a href="https://wiki.example.com/some-id">WIKI-some-id</a> |
608 | |
609 Refer to the `Python regular expression documentation`_ for more details about | |
610 the supported syntax in ``issue_pat``, ``issue_server_link`` and ``issue_sub``. | |
575 | 611 |
576 | 612 |
577 Hook management | 613 Hook management |
578 --------------- | 614 --------------- |
579 | 615 |
899 .. __: https://kallithea-scm.org/repos/kallithea/files/tip/init.d/ . | 935 .. __: https://kallithea-scm.org/repos/kallithea/files/tip/init.d/ . |
900 | 936 |
901 | 937 |
902 .. _virtualenv: http://pypi.python.org/pypi/virtualenv | 938 .. _virtualenv: http://pypi.python.org/pypi/virtualenv |
903 .. _python: http://www.python.org/ | 939 .. _python: http://www.python.org/ |
940 .. _Python regular expression documentation: https://docs.python.org/2/library/re.html | |
904 .. _Mercurial: https://www.mercurial-scm.org/ | 941 .. _Mercurial: https://www.mercurial-scm.org/ |
905 .. _Celery: http://celeryproject.org/ | 942 .. _Celery: http://celeryproject.org/ |
906 .. _Celery documentation: http://docs.celeryproject.org/en/latest/getting-started/index.html | 943 .. _Celery documentation: http://docs.celeryproject.org/en/latest/getting-started/index.html |
907 .. _RabbitMQ: http://www.rabbitmq.com/ | 944 .. _RabbitMQ: http://www.rabbitmq.com/ |
908 .. _Redis: http://redis.io/ | 945 .. _Redis: http://redis.io/ |