From 3173bdddcdff576a009c6d1969cf77a656945694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Date: Thu, 9 Sep 2021 17:02:43 +0200 Subject: [PATCH] refs: show the accurate annotated tag time After this patch, the ref and refs pages will show the time based on the tagger line of tags for annotated tags. --- gitsrht/app.py | 3 ++- gitsrht/git.py | 11 +++++++---- gitsrht/templates/ref.html | 2 +- gitsrht/templates/refs.html | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gitsrht/app.py b/gitsrht/app.py index 9ad916f..9efa7c5 100644 --- a/gitsrht/app.py +++ b/gitsrht/app.py @@ -3,7 +3,7 @@ import os import stat from functools import lru_cache from gitsrht import urls -from gitsrht.git import commit_time, trim_commit +from gitsrht.git import commit_time, trim_commit, signature_time from gitsrht.repos import GitRepoApi from gitsrht.service import oauth_service, webhooks_notify from gitsrht.types import Access, Redirect, Repository, User @@ -54,6 +54,7 @@ class GitApp(ScmSrhtFlask): del session["notice"] return { "commit_time": commit_time, + "signature_time": signature_time, "humanize": humanize, "notice": notice, "object_storage_enabled": object_storage_enabled, diff --git a/gitsrht/git.py b/gitsrht/git.py index e32bcfe..9caf8c5 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -19,17 +19,20 @@ def trim_commit(msg): return msg return msg[:msg.index("\n")] -def commit_time(commit): - author = commit.author if hasattr(commit, 'author') else commit.get_object().author +def signature_time(signature): # Time handling in python is so dumb try: - tzinfo = timezone(timedelta(minutes=author.offset)) - tzaware = datetime.fromtimestamp(float(author.time), tzinfo) + tzinfo = timezone(timedelta(minutes=signature.offset)) + tzaware = datetime.fromtimestamp(float(signature.time), tzinfo) diff = datetime.now(timezone.utc) - tzaware return datetime.utcnow() - diff except: return datetime.utcnow() +def commit_time(commit): + author = commit.author if hasattr(commit, 'author') else commit.get_object().author + return signature_time(author) + def _get_ref(repo, ref): return repo._get(ref) diff --git a/gitsrht/templates/ref.html b/gitsrht/templates/ref.html index 480b364..3aade25 100644 --- a/gitsrht/templates/ref.html +++ b/gitsrht/templates/ref.html @@ -8,7 +8,7 @@

{{tag.name}} - {{commit_time(tag) | date}} + {{signature_time(tag.tagger) | date}}

diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index 5aef23b..6e077ba 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -37,9 +37,11 @@

{% if isinstance(tag, pygit2.Commit) %} {% set refname = commit.id.hex %} + {% set author = commit.author %} {{ref[len("refs/tags/"):]}} {% else %} {% set refname = tag.raw_name %} + {% set author = tag.tagger %} {% endif %} - {{commit_time(tag) | date}} + {{signature_time(author) | date}}