-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataobjects.py
79 lines (63 loc) · 1.75 KB
/
dataobjects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"Dataobjects module"
from dataclasses import dataclass
from typing import Self
@dataclass
class Log:
"""Class for representation of each log."""
uuid: str
operation: str
source: str
path: str
created_at: str
@staticmethod
def map(data: dict) -> Self:
"""Log mapper"""
return Log(**data)
@dataclass
class Commit:
"""Class for representation of each commit. Also used for stash."""
message: str
uuid: str
created_at: str
logs: list[Log]
@staticmethod
def map(data: dict) -> Self:
"""Commit mapper"""
return Commit(
message=data["message"],
uuid=data["uuid"],
logs=[Log.map(log) for log in data["logs"]],
created_at=data["created_at"],
)
@dataclass
class Version:
"""Class for representation of each version."""
name: str
uuid: str
created_at: str
commits: list[Commit]
@staticmethod
def map(data: dict) -> Self:
"""Version mapper"""
return Version(
name=data["name"],
uuid=data["uuid"],
created_at=data["created_at"],
commits=[Commit.map(commit) for commit in data["commits"]],
)
@dataclass
class Metadata:
"""Class for representation of all versions."""
current_version: str
stage: list[Log]
stash: list[Commit]
versions: list[Version]
@staticmethod
def map(data: dict) -> Self:
"""Metadata mapper"""
return Metadata(
current_version=data["current_version"],
stage=[Log.map(log) for log in data["stage"]],
stash=[Commit.map(stash) for stash in data["stash"]],
versions=[Version.map(version) for version in data["versions"]],
)