From 31ce2a8054f6e3973c44dbac9923f4205b4a4333 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 24 Jan 2022 19:14:41 +0100 Subject: [PATCH 1/2] Remove email addresses and (!UNKNOWN) from author names. --- changelogs/fragments/389-remove-email-addresses.yml | 2 ++ src/antsibull/data/docsite/plugin.rst.j2 | 2 +- src/antsibull/data/docsite/role.rst.j2 | 2 +- src/antsibull/jinja2/environment.py | 2 ++ src/antsibull/jinja2/filters.py | 8 ++++++++ 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/389-remove-email-addresses.yml diff --git a/changelogs/fragments/389-remove-email-addresses.yml b/changelogs/fragments/389-remove-email-addresses.yml new file mode 100644 index 00000000..468cc48b --- /dev/null +++ b/changelogs/fragments/389-remove-email-addresses.yml @@ -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)." diff --git a/src/antsibull/data/docsite/plugin.rst.j2 b/src/antsibull/data/docsite/plugin.rst.j2 index db3e14f9..019d5dc3 100644 --- a/src/antsibull/data/docsite/plugin.rst.j2 +++ b/src/antsibull/data/docsite/plugin.rst.j2 @@ -374,7 +374,7 @@ Authors ~~~~~~~ {% for author_name in doc['author'] %} -- @{ author_name }@ +- @{ author_name | massage_author_name }@ {% endfor %} {% endif %} diff --git a/src/antsibull/data/docsite/role.rst.j2 b/src/antsibull/data/docsite/role.rst.j2 index 59129999..8317a22a 100644 --- a/src/antsibull/data/docsite/role.rst.j2 +++ b/src/antsibull/data/docsite/role.rst.j2 @@ -173,7 +173,7 @@ Authors ^^^^^^^ {% for author_name in ep_doc['author'] %} -- @{ author_name }@ +- @{ author_name | massage_author_name }@ {% endfor %} {% endif %} diff --git a/src/antsibull/jinja2/environment.py b/src/antsibull/jinja2/environment.py index 7eaf8ad6..43e3e650 100644 --- a/src/antsibull/jinja2/environment.py +++ b/src/antsibull/jinja2/environment.py @@ -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 @@ -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 diff --git a/src/antsibull/jinja2/filters.py b/src/antsibull/jinja2/filters.py index e7e2b711..2ef6ada2 100644 --- a/src/antsibull/jinja2/filters.py +++ b/src/antsibull/jinja2/filters.py @@ -27,6 +27,7 @@ _REF = re.compile(r"\bR\(([^)]+), *([^)]+)\)") _CONST = re.compile(r"\bC\(([^)]+)\)") _RULER = re.compile(r"\bHORIZONTALLINE\b") +_EMAIL_ADDRESS = re.compile(r"[(<]?[\w.]+@[\w.]+\.\w+[)>]?") def html_ify(text): @@ -185,3 +186,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 From 29a72016f9edc6541ffc170faed2ea7143dcf9da Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 25 Jan 2022 07:33:13 +0100 Subject: [PATCH 2/2] Improve email matching. --- src/antsibull/jinja2/filters.py | 3 ++- tests/units/test_jinja2.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/antsibull/jinja2/filters.py b/src/antsibull/jinja2/filters.py index 2ef6ada2..c8fba7cd 100644 --- a/src/antsibull/jinja2/filters.py +++ b/src/antsibull/jinja2/filters.py @@ -27,7 +27,8 @@ _REF = re.compile(r"\bR\(([^)]+), *([^)]+)\)") _CONST = re.compile(r"\bC\(([^)]+)\)") _RULER = re.compile(r"\bHORIZONTALLINE\b") -_EMAIL_ADDRESS = re.compile(r"[(<]?[\w.]+@[\w.]+\.\w+[)>]?") + +_EMAIL_ADDRESS = re.compile(r"(?:<{mail}>|\({mail}\)|{mail})".format(mail=r"[\w.+-]+@[\w.-]+\.\w+")) def html_ify(text): diff --git a/tests/units/test_jinja2.py b/tests/units/test_jinja2.py index 03875d2b..6f2f0659 100644 --- a/tests/units/test_jinja2.py +++ b/tests/units/test_jinja2.py @@ -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 = { @@ -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 (@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