mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Gracefully handle H2s that dont match the schema
This commit is contained in:
parent
98c21e4078
commit
13ddc5a1f9
@ -66,7 +66,8 @@ class VersionEntry:
|
|||||||
self.date: Optional[datetime.date] = None
|
self.date: Optional[datetime.date] = None
|
||||||
self.tags: List[str] = []
|
self.tags: List[str] = []
|
||||||
self.link: str = ''
|
self.link: str = ''
|
||||||
self.line_no = -1
|
self.link_id: str = None
|
||||||
|
self.line_no: int = -1
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
if self.link:
|
if self.link:
|
||||||
@ -74,8 +75,11 @@ class VersionEntry:
|
|||||||
else:
|
else:
|
||||||
segments = [self.name]
|
segments = [self.name]
|
||||||
|
|
||||||
|
if self.date or len(self.tags) > 0:
|
||||||
|
segments.append('-')
|
||||||
|
|
||||||
if self.date:
|
if self.date:
|
||||||
segments += ['-', self.date.isoformat()]
|
segments.append(self.date.isoformat())
|
||||||
|
|
||||||
segments += [f'[{t.upper()}]' for t in self.tags]
|
segments += [f'[{t.upper()}]' for t in self.tags]
|
||||||
|
|
||||||
@ -159,24 +163,36 @@ class Changelog:
|
|||||||
if segment[2] == 'h2':
|
if segment[2] == 'h2':
|
||||||
# start of a version
|
# start of a version
|
||||||
|
|
||||||
split = text.rstrip('-').strip('#').strip().split()
|
slug = text.rstrip('-').strip('#').strip()
|
||||||
|
split = slug.split()
|
||||||
if '-' in split:
|
if '-' in split:
|
||||||
split.remove('-')
|
split.remove('-')
|
||||||
|
|
||||||
version = VersionEntry()
|
version = VersionEntry()
|
||||||
section = ''
|
section = ''
|
||||||
|
|
||||||
version.name, version.link, version.link_id = _strip_link(split[0])
|
version.name = slug
|
||||||
version.line_no = segment[0]
|
version.line_no = segment[0]
|
||||||
|
tags = []
|
||||||
|
date = []
|
||||||
|
|
||||||
if len(split) > 1:
|
for word in split[1:]:
|
||||||
|
if match := re.match(r'\d{4}-\d{2}-\d{2}', word):
|
||||||
|
# date
|
||||||
try:
|
try:
|
||||||
version.date = datetime.date.fromisoformat(split[1].strip(string.punctuation))
|
date = datetime.date.fromisoformat(match[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
version.date = None
|
break
|
||||||
|
elif match := re.match(r'^\[(?P<tag>\S*)]', word):
|
||||||
|
tags.append(match['tag'])
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
if len(split) > 2:
|
else:
|
||||||
version.tags = [s.strip('[]') for s in split[2:]]
|
# matches the schema
|
||||||
|
version.name, version.link, version.link_id = _strip_link(split[0])
|
||||||
|
version.date = date
|
||||||
|
version.tags = tags
|
||||||
|
|
||||||
self.versions.append(version)
|
self.versions.append(version)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user