From 416a0874187fdf96346e3f504d6542b3214957db Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 22 Aug 2020 02:49:28 +0200 Subject: Move git SHA fetcher into utils. --- pydis_site/__init__.py | 5 ----- pydis_site/context_processors.py | 4 ++-- pydis_site/settings.py | 4 ++-- pydis_site/utils/resources.py | 10 ++++++++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pydis_site/__init__.py b/pydis_site/__init__.py index f0702577..df67cf71 100644 --- a/pydis_site/__init__.py +++ b/pydis_site/__init__.py @@ -1,4 +1,3 @@ -import git from wiki.plugins.macros.mdx import toc # Remove the toc header prefix. There's no option for this, so we gotta monkey patch it. @@ -8,7 +7,3 @@ toc.HEADER_ID_PREFIX = '' # by a string because Allauth won't let us just give it a list _there_, we have to point # at a list _somewhere else_ instead. VALIDATORS = [] - -# Git SHA -repo = git.Repo(search_parent_directories=True) -GIT_SHA = repo.head.object.hexsha diff --git a/pydis_site/context_processors.py b/pydis_site/context_processors.py index bb66f21d..e905d9c7 100644 --- a/pydis_site/context_processors.py +++ b/pydis_site/context_processors.py @@ -1,8 +1,8 @@ from django.template import RequestContext -from pydis_site import GIT_SHA +from pydis_site.utils.resources import get_git_sha def git_sha_processor(_: RequestContext) -> dict: """Expose the git SHA for this repo to all views.""" - return {'git_sha': GIT_SHA} + return {'git_sha': get_git_sha()} diff --git a/pydis_site/settings.py b/pydis_site/settings.py index ff2942f0..e707a526 100644 --- a/pydis_site/settings.py +++ b/pydis_site/settings.py @@ -20,7 +20,7 @@ import sentry_sdk from django.contrib.messages import constants as messages from sentry_sdk.integrations.django import DjangoIntegration -from pydis_site import GIT_SHA +from pydis_site.utils.resources import get_git_sha if typing.TYPE_CHECKING: from django.contrib.auth.models import User @@ -35,7 +35,7 @@ sentry_sdk.init( dsn=env('SITE_SENTRY_DSN'), integrations=[DjangoIntegration()], send_default_pii=True, - release=f"pydis-site@{GIT_SHA}" + release=f"pydis-site@{get_git_sha()}" ) # Build paths inside the project like this: os.path.join(BASE_DIR, ...) diff --git a/pydis_site/utils/resources.py b/pydis_site/utils/resources.py index 637fd785..d36c4b77 100644 --- a/pydis_site/utils/resources.py +++ b/pydis_site/utils/resources.py @@ -4,8 +4,13 @@ import glob import typing from dataclasses import dataclass +import git import yaml +# Git SHA +repo = git.Repo(search_parent_directories=True) +GIT_SHA = repo.head.object.hexsha + @dataclass class URL: @@ -89,3 +94,8 @@ def load_categories(order: typing.List[str]) -> typing.List[Category]: categories.append(Category.construct_from_directory(direc)) return categories + + +def get_git_sha() -> str: + """Get the Git SHA for this repo.""" + return GIT_SHA -- cgit v1.2.3