Skip to content

Commit

Permalink
Merge pull request #59 from TicClick/default-language
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick authored Sep 28, 2022
2 parents d6d9fc8 + 32d0c80 commit 10b8e7f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
2 changes: 1 addition & 1 deletion librarian/discord/cogs/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions librarian/discord/languages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .base import LanguageMeta # noqa
from . import (
ru,
ru, special,
)

__all__ = ("ru",)
__all__ = ("ru", "special",)
31 changes: 31 additions & 0 deletions librarian/discord/languages/special.py
Original file line number Diff line number Diff line change
@@ -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 ""
3 changes: 2 additions & 1 deletion librarian/discord/settings/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
35 changes: 35 additions & 0 deletions tests/discord/languages/test_special.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/discord/settings/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from librarian.discord.languages import special

from librarian.discord.settings import (
base,
custom
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 10b8e7f

Please # to comment.