Debian Codegraph @

scripts/extract-release-notes

raw
1 #!/usr/bin/env python3
2 """Extract the topmost versioned section from changelog.md and print to stdout.
3
4 The changelog uses level-1 headings: '# X.Y.Z' or '# X.Y.Z: title'.
5 The '# Unreleased' heading is skipped. The first versioned heading found
6 and all lines up to (but not including) the next heading are extracted.
7 """
8 import sys
9
10
11 def extract(path: str) -> str:
12 lines: list[str] = []
13 inside = False
14 with open(path) as f:
15 for line in f:
16 if line.startswith("# ") and not line.startswith("# Unreleased"):
17 if inside:
18 break
19 inside = True
20 # skip the heading — GitHub Release title already carries the version
21 elif inside:
22 lines.append(line)
23 return "".join(lines).strip()
24
25
26 if __name__ == "__main__":
27 if len(sys.argv) != 2:
28 print(f"Usage: {sys.argv[0]} <changelog.md>", file=sys.stderr)
29 sys.exit(1)
30 notes = extract(sys.argv[1])
31 if not notes:
32 print("No versioned release section found in changelog", file=sys.stderr)
33 sys.exit(1)
34 print(notes)