From 4b444dd159846b47a465437d5f6e48196b67fba3 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Mon, 9 Oct 2023 12:47:33 -0700 Subject: [PATCH] fix(tags): parse timezone information from a tag --- gto/index.py | 5 ++--- gto/tag.py | 6 +++--- .../sample_remote_repo_expected_history_churn.json | 8 ++++---- tests/test_tag.py | 10 +++++++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/gto/index.py b/gto/index.py index 4b1ac8c1..db917003 100644 --- a/gto/index.py +++ b/gto/index.py @@ -3,7 +3,6 @@ from abc import ABC, abstractmethod from collections import defaultdict from contextlib import contextmanager -from datetime import datetime from functools import wraps from pathlib import Path from typing import ( @@ -524,7 +523,7 @@ def update_state( EnrichmentEvent( artifact=artifact.artifact, version=version.version, - created_at=datetime.fromtimestamp(commit.commit_time), + created_at=commit.commit_datetime, author=commit.author_name, author_email=commit.author_email, commit_hexsha=commit.hexsha, @@ -548,7 +547,7 @@ def update_state( EnrichmentEvent( artifact=artifact.artifact, version=version.version, - created_at=datetime.fromtimestamp(commit.commit_time), + created_at=commit.commit_datetime, author=commit.author_name, author_email=commit.author_email, commit_hexsha=commit.hexsha, diff --git a/gto/tag.py b/gto/tag.py index 43c9ec26..e7aec549 100644 --- a/gto/tag.py +++ b/gto/tag.py @@ -1,6 +1,6 @@ +import datetime import os import re -from datetime import datetime from enum import Enum from typing import FrozenSet, Iterable, Optional, Union @@ -124,7 +124,7 @@ class Tag(BaseModel): name: str version: Optional[str] stage: Optional[str] - created_at: datetime + created_at: datetime.datetime tag: GitTag class Config: @@ -134,7 +134,7 @@ class Config: def parse_tag(tag: GitTag): return Tag( tag=tag, - created_at=datetime.fromtimestamp(tag.tag_time), + created_at=tag.tag_datetime, **parse_name(tag.name), ) diff --git a/tests/resources/sample_remote_repo_expected_history_churn.json b/tests/resources/sample_remote_repo_expected_history_churn.json index e90dc1de..00d1c182 100644 --- a/tests/resources/sample_remote_repo_expected_history_churn.json +++ b/tests/resources/sample_remote_repo_expected_history_churn.json @@ -1,6 +1,6 @@ [ { - "timestamp": "2022-05-26 23:49:52", + "timestamp": "2022-05-27 02:49:52+03:00", "artifact": "churn", "event": "assignment", "priority": 5, @@ -13,7 +13,7 @@ "ref": "churn#prod#2" }, { - "timestamp": "2022-05-25 20:03:12", + "timestamp": "2022-05-25 23:03:12+03:00", "artifact": "churn", "event": "assignment", "priority": 5, @@ -26,7 +26,7 @@ "ref": "churn#staging#1" }, { - "timestamp": "2022-05-24 16:16:32", + "timestamp": "2022-05-24 19:16:32+03:00", "artifact": "churn", "event": "registration", "priority": 3, @@ -39,7 +39,7 @@ "ref": "churn@v3.1.0" }, { - "timestamp": "2022-05-20 01:09:52", + "timestamp": "2022-05-20 04:09:52+03:00", "artifact": "churn", "event": "registration", "priority": 3, diff --git a/tests/test_tag.py b/tests/test_tag.py index 1db10140..e0ee9efc 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -3,7 +3,7 @@ from gto.constants import Action from gto.exceptions import RefNotFound, TagExists -from gto.tag import create_tag, find, name_tag, parse_name +from gto.tag import create_tag, find, name_tag, parse_name, parse_tag def test_name_tag(scm: Git): @@ -148,3 +148,11 @@ def test_create_tag_repeated_tagname(scm: Git): def test_lightweight_tag(scm: Git): scm.tag("lightweight-tag@v0.0.1") assert find(scm=scm) == [] + + +@pytest.mark.usefixtures("repo_with_commit") +def test_parse_tag_created_at_timezone(scm: Git): + create_tag(scm, "nn#prod", rev="HEAD", message="msg") + tag = parse_tag(scm.get_tag("nn#prod")) + d = tag.created_at + assert d.tzinfo is not None and d.tzinfo.utcoffset(d) is not None