feat(fastapi): add configurable commit hash display

Two new options have been added:

- [devel] commit_url
    - URL including an %s format specifier that can be used to link
      to a webpage for the commit.
- [devel] commit_hash
    - HEAD's commit hash (produced via `git rev-parse HEAD`)

If a `[devel] commit_hash` is configured, a link to the commit based on
`[devel] commit_url` will be displayed in the aurweb footer in
the form: `HEAD@<commit_hash>`. If no `[devel] commit_url` is
configured, a non-linked hash will be displayed.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-24 18:07:56 -07:00
parent da55aa6491
commit 0d734eb07d
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
6 changed files with 82 additions and 1 deletions

View file

@ -88,9 +88,17 @@ def register_function(name: str) -> Callable:
def make_context(request: Request, title: str, next: str = None):
""" Create a context for a jinja2 TemplateResponse. """
commit_url = aurweb.config.get_with_fallback("devel", "commit_url", None)
commit_hash = aurweb.config.get_with_fallback("devel", "commit_hash", None)
if commit_hash:
# Shorten commit_hash to a short Git hash.
commit_hash = commit_hash[:7]
timezone = time.get_request_timezone(request)
return {
"request": request,
"commit_url": commit_url,
"commit_hash": commit_hash,
"language": l10n.get_request_language(request),
"languages": l10n.SUPPORTED_LANGUAGES,
"timezone": timezone,

View file

@ -20,9 +20,14 @@ class Client:
host = "127.0.0.1"
class URL:
path = "/"
class Request:
""" A fake Request object which mimics a FastAPI Request for tests. """
client = Client()
cookies = dict()
headers = dict()
user = User()
url = URL()