Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if any(map(lambda h: h.level == 1, headings)):
raise Exception('Changelog has multiple level 1 headings.')
release = None
for heading in headings:
if heading.level == 2:
if release:
changelog.releases.append(release)
release = Release(heading.title)
elif heading.level == 3:
if not release:
raise Exception('Level 3 heading was not found within a release (level 2 heading).')
release.sections.append(Section(heading.title))
if release:
changelog.releases.append(release)
return changelog