Skip to content

Commit

Permalink
Remove email addresses and (!UNKNOWN) from author names (#389)
Browse files Browse the repository at this point in the history
* Remove email addresses and (!UNKNOWN) from author names.

* Improve email matching.
  • Loading branch information
felixfontein authored Jan 25, 2022
1 parent 8789427 commit 5023129
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/389-remove-email-addresses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Remove email addresses and ``(!UNKNOWN)`` from plugin and role author names (https://github.com/ansible-community/antsibull/pull/389)."
2 changes: 1 addition & 1 deletion src/antsibull/data/docsite/plugin.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Authors
~~~~~~~

{% for author_name in doc['author'] %}
- @{ author_name }@
- @{ author_name | massage_author_name }@
{% endfor %}

{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull/data/docsite/role.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Authors
^^^^^^^

{% for author_name in ep_doc['author'] %}
- @{ author_name }@
- @{ author_name | massage_author_name }@
{% endfor %}

{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions src/antsibull/jinja2/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .filters import (
do_max, documented_type, html_ify, rst_ify, rst_escape, rst_fmt, rst_xline, move_first,
massage_author_name,
)
from .tests import still_relevant, test_list

Expand Down Expand Up @@ -68,6 +69,7 @@ def doc_environment(template_location):
env.filters['xline'] = rst_xline
env.filters['documented_type'] = documented_type
env.filters['move_first'] = move_first
env.filters['massage_author_name'] = massage_author_name
env.tests['list'] = test_list
env.tests['still_relevant'] = still_relevant

Expand Down
9 changes: 9 additions & 0 deletions src/antsibull/jinja2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
_CONST = re.compile(r"\bC\(([^)]+)\)")
_RULER = re.compile(r"\bHORIZONTALLINE\b")

_EMAIL_ADDRESS = re.compile(r"(?:<{mail}>|\({mail}\)|{mail})".format(mail=r"[\w.+-]+@[\w.-]+\.\w+"))


def html_ify(text):
''' convert symbols like I(this is in italics) to valid HTML '''
Expand Down Expand Up @@ -185,3 +187,10 @@ def move_first(sequence, *move_to_beginning):
pass

return beginning + remaining


def massage_author_name(value):
''' remove email addresses from the given string, and remove `(!UNKNOWN)` '''
value = _EMAIL_ADDRESS.sub('', value)
value = value.replace('(!UNKNOWN)', '')
return value
16 changes: 15 additions & 1 deletion tests/units/test_jinja2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from antsibull.jinja2.filters import rst_ify, rst_escape, move_first
from antsibull.jinja2.filters import rst_ify, rst_escape, move_first, massage_author_name


RST_IFY_DATA = {
Expand Down Expand Up @@ -68,3 +68,17 @@ def test_escape_ify(value, expected):
@pytest.mark.parametrize('input, move_to_beginning, expected', MOVE_FIRST_DATA)
def test_move_first(input, move_to_beginning, expected):
assert move_first(input, *move_to_beginning) == expected


MASSAGE_AUTHOR_NAME = [
('', ''),
('John Doe (@johndoe) <[email protected]>', 'John Doe (@johndoe) '),
('John Doe (@johndoe) [email protected]', 'John Doe (@johndoe) '),
('John Doe (@johndoe) ([email protected])', 'John Doe (@johndoe) '),
('John Doe (@johndoe, [email protected])', 'John Doe (@johndoe, )'),
]


@pytest.mark.parametrize('input, expected', MASSAGE_AUTHOR_NAME)
def test_massage_author_name(input, expected):
assert massage_author_name(input) == expected

0 comments on commit 5023129

Please sign in to comment.