diff --git a/website/contrib/code_block/apps.py b/website/contrib/code_block/apps.py new file mode 100644 index 0000000..a2a51ab --- /dev/null +++ b/website/contrib/code_block/apps.py @@ -0,0 +1,11 @@ +from django.apps import AppConfig +from health_check.plugins import plugin_dir + + +class CodeBlockAppConfig(AppConfig): + name = "website.contrib.code_block" + + def ready(self) -> None: + from .healthchecks import GitHubLinguistHealthCheckBackend + + plugin_dir.register(GitHubLinguistHealthCheckBackend) diff --git a/website/contrib/code_block/healthchecks.py b/website/contrib/code_block/healthchecks.py new file mode 100644 index 0000000..55608f3 --- /dev/null +++ b/website/contrib/code_block/healthchecks.py @@ -0,0 +1,14 @@ +from health_check.backends import BaseHealthCheckBackend + +from .utils import _get_linguist_colours + + +class GitHubLinguistHealthCheckBackend(BaseHealthCheckBackend): + def check_status(self) -> None: + colours = _get_linguist_colours() + + if colours is None: + self.add_error("No colours provided") + + def identifier(self) -> str: + return "GitHub Linguist Colours" diff --git a/website/contrib/code_block/utils.py b/website/contrib/code_block/utils.py index be19f5e..8ecd65c 100644 --- a/website/contrib/code_block/utils.py +++ b/website/contrib/code_block/utils.py @@ -11,9 +11,8 @@ PYGMENTS_VERSION_SLUG = PYGMENTS_VERSION.replace(".", "-") LINGUIST_DATA_URL = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml" -@cache -@django_cache_decorator(time=21600) -def get_linguist_colours() -> dict[str, str]: +@django_cache_decorator(time=600) +def _get_linguist_colours() -> dict[str, str]: response = requests.get(LINGUIST_DATA_URL) response.raise_for_status() @@ -25,3 +24,9 @@ def get_linguist_colours() -> dict[str, str]: for language, data in linguist_data.items() if data.get("color") } + + +@cache +@django_cache_decorator(time=21600) +def get_linguist_colours() -> dict[str, str]: + return _get_linguist_colours()