Authentication-Results: mail-b.sr.ht; dkim=pass header.d=aarsen.me header.i=@aarsen.me Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by mail-b.sr.ht (Postfix) with ESMTPS id 990BB11EFC3 for <~sircmpwn/sr.ht-dev@lists.sr.ht>; Thu, 9 Sep 2021 15:05:48 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4H52Pl2hTNzQlRW; Thu, 9 Sep 2021 17:05:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1631199945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4TSbHwQNkvHMXvg1o5ZzIll72nwsR5oeMrdAja21jLI=; b=ljZFMIp8tjNWg72WoNCAwrRLRhNPKTIknKeV/7hXCLKrzulZAJKKX/pFs7HE5zKkM+DEDO 6JSZwQT3dNXQm5xQwCJFVPYpsLcQTeEUQGw3CwovAUBmpszzAcPmzQ73BH8c2su8eB9yl2 TynuMOnIBedm7NRaFWzBz9bfwO2StAqr6pDTvFOpLW+jNTm4UqVx/a9Ua9LpkKxA/oxE/w HHK1hAoNJCI2ZeF5rwAY041kCv8ZODeR31xgd2qNmpHej79LE4/OKeULwOvAeLRe5Nsgxk swyer6BsAvYyZ7hzv+Y8NVcQaKLMD2arMLOWu+laUJTrzy4vjub/8fPiu8WSDw== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: ~sircmpwn/sr.ht-dev@lists.sr.ht Cc: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= Subject: [PATCH git.sr.ht] refs: show the accurate annotated tag time Date: Thu, 9 Sep 2021 17:02:43 +0200 Message-Id: <20210909150243.18418-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 79C77188C After this patch, the ref and refs pages will show the time based on the tagger line of tags for annotated tags. --- I'd possibly make some changes here, notably, add a prefix such as "tagged on" and "committed on" depending on the kind of tag, to make it clear what time was specified, but it'd be a larger visual change in the UI so I'd rather ask about that first. For an example, see: https://git.sr.ht/~sircmpwn/getopt/refs/v1.0.0 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}}