Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove email addresses and (!UNKNOWN) from author names #389

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) <john.doe@gmail.com>', 'John Doe (@johndoe) '),
('John Doe (@johndoe) john+doe@gmail.com', 'John Doe (@johndoe) '),
('John Doe (@johndoe) (john-doe@gmail.com)', 'John Doe (@johndoe) '),
('John Doe (@johndoe, john.doe@gmail.com)', 'John Doe (@johndoe, )'),
]


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