Skip to content

Commit

Permalink
fix(tags): parse timezone information from a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Oct 25, 2023
1 parent d698e76 commit 4b444dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 2 additions & 3 deletions gto/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions gto/tag.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion tests/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 4b444dd

Please sign in to comment.