diff --git a/librarian/discord/cogs/server.py b/librarian/discord/cogs/server.py index 69e6e03..12d3ae8 100644 --- a/librarian/discord/cogs/server.py +++ b/librarian/discord/cogs/server.py @@ -105,7 +105,7 @@ async def show(self, ctx: types.Context, *args): return await ctx.message.channel.send(content=reply) - # the final docstring for this command is generated automatically + # the final docstring for this command is generated automatically -- see __init__() @commands.command(name="set") @helpers.is_promoted() @commands.guild_only() diff --git a/librarian/discord/languages/__init__.py b/librarian/discord/languages/__init__.py index 5cd7a6d..38f229b 100644 --- a/librarian/discord/languages/__init__.py +++ b/librarian/discord/languages/__init__.py @@ -1,6 +1,6 @@ from .base import LanguageMeta # noqa from . import ( - ru, + ru, special, ) -__all__ = ("ru",) +__all__ = ("ru", "special",) diff --git a/librarian/discord/languages/special.py b/librarian/discord/languages/special.py new file mode 100644 index 0000000..133d8b6 --- /dev/null +++ b/librarian/discord/languages/special.py @@ -0,0 +1,31 @@ +from librarian.discord.languages import base + + +class UnspecifiedLanguage(base.Language): + """ + Matches everything that don't match the "[LANGUAGE_CODE] PR title" format + """ + + code = "none" + highlights = [""] + + @classmethod + def match(cls, line): + return not line.strip().startswith("[") + + +class EveryLanguage(base.Language): + """ + Matches everything + """ + + code = "all" + highlights = [""] + + @classmethod + def match(cls, _): + return True + + @property + def random_highlight(self): + return "" diff --git a/librarian/discord/settings/custom.py b/librarian/discord/settings/custom.py index bd266c7..f1a9491 100644 --- a/librarian/discord/settings/custom.py +++ b/librarian/discord/settings/custom.py @@ -16,13 +16,14 @@ class PinMessages(base.Bool): class Language(base.String): """ pulls with this language code will be watched. - possible values: anything from https://osu.ppy.sh/wiki/en/Article_styling_criteria/Formatting#locales + possible values: anything from https://osu.ppy.sh/wiki/en/Article_styling_criteria/Formatting#locales, plus "all" and "none" """ name = "language" __whitelisted = frozenset(( "en", "ar", "be", "bg", "cs", "da", "de", "gr", "es", "fi", "fr", "hu", "id", "it", "ja", "ko", "nl", "no", "pl", "pt", "pt-br", "ro", "ru", "sk", "sv", "th", "tr", "uk", "vi", "zh", "zh-tw", + languages.special.UnspecifiedLanguage.code, languages.special.EveryLanguage.code, )) def __init__(self, *a, **kw): diff --git a/tests/discord/languages/test_special.py b/tests/discord/languages/test_special.py new file mode 100644 index 0000000..d1816a3 --- /dev/null +++ b/tests/discord/languages/test_special.py @@ -0,0 +1,35 @@ +import re + +import pytest + +from librarian.discord.languages import base, special + + +class TestLanguages: + def test__matching__unspecified_language(self): + assert base.LanguageMeta.get("none") is special.UnspecifiedLanguage + for good_title in ( + "Update OWC2022", + "Update dependencies", + " Some spaces! Wow", + "\"Special\" pull request", + ): + assert special.UnspecifiedLanguage.match(good_title) + + for bad_title in ( + "[EN] Update OWC2022", + "[TEST] Update dependencies", + "[EN/RU] Test", + ): + assert not special.UnspecifiedLanguage.match(bad_title), bad_title + + def test__matching__every_language(self): + assert base.LanguageMeta.get("all") is special.EveryLanguage + for any_title in ( + "Update OWC2022", + "[RU] Update OWC2023", + "[RU/EN] Update OWC2024", + " Spa ces", + "\"Rhythm Games from Outer Space\" (Short 1992)", + ): + assert special.EveryLanguage.match(any_title) diff --git a/tests/discord/settings/test_custom.py b/tests/discord/settings/test_custom.py index 2a5c27d..2a3b810 100644 --- a/tests/discord/settings/test_custom.py +++ b/tests/discord/settings/test_custom.py @@ -1,5 +1,7 @@ import pytest +from librarian.discord.languages import special + from librarian.discord.settings import ( base, custom @@ -30,6 +32,11 @@ def test__language(self): custom.Language(val).match("[DOES NOT] compute") assert "non-existent language" in str(e) + for val in [special.EveryLanguage.code, special.UnspecifiedLanguage.code]: + instance = custom.Language(val) + assert instance.check() and instance.cast() == val.strip().lower() + assert len(instance.random_highlight) == 0 + def test__reviewer_role(self): for val in ["123", "<@&1234>", 12345678901234567890]: instance = custom.ReviewerRole(val)