Coverage for ghtc/models.py: 95%
41 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-11-25 11:59 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-11-25 11:59 +0000
1from typing import Optional, List, Dict
2import enum
3import time
4from dataclasses import dataclass, field
6UNRELEASED_TAG_TIMESTAMP = 9999999999
9class ConventionalCommitType(enum.Enum):
10 OTHER = 0
11 BUILD = 1
12 CHORE = 2
13 STYLE = 3
14 CI = 4
15 REFACTOR = 5
16 TEST = 6
17 DOCS = 7
18 PERF = 8
19 FIX = 9
20 FEAT = 10
23@dataclass(frozen=True)
24class ConventionalCommitFooter:
25 key: str
26 value: str
29@dataclass(frozen=True, unsafe_hash=True)
30class ConventionalCommitMessage:
31 type: ConventionalCommitType
32 description: str
33 breaking: bool
34 scope: Optional[str]
35 body: Optional[str]
36 footers: List[ConventionalCommitFooter]
39@dataclass(frozen=True)
40class ChangelogLine:
41 commit_message: ConventionalCommitMessage
42 commit_sha: str
43 commit_timestamp: int
44 commit_date: str = field(init=False)
46 def __post_init__(self):
47 object.__setattr__(
48 self,
49 "commit_date",
50 time.strftime("%Y-%m-%d", time.gmtime(self.commit_timestamp)),
51 ) # because frozen=True, we have to use this ugly __setattr__
54@dataclass(frozen=True)
55class ChangelogEntryForATag:
56 tag_name: str
57 tag_timestamp: int
58 lines_by_type: Dict[ConventionalCommitType, List[ChangelogLine]]
59 tag_date: str = field(init=False)
61 def __post_init__(self):
62 object.__setattr__(
63 self, "tag_date", time.strftime("%Y-%m-%d", time.gmtime(self.tag_timestamp))
64 ) # because frozen=True, we have to use this ugly __setattr__