File: changelog_extract.py

package info (click to toggle)
python-sh 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 900 kB
  • sloc: python: 4,157; makefile: 25
file content (37 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
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
import re
import sys
from pathlib import Path
from typing import Iterable

THIS_DIR = Path(__file__).parent
CHANGELOG = THIS_DIR.parent / "CHANGELOG.md"


def fetch_changes(changelog: Path, version: str) -> Iterable[str]:
    with open(changelog, "r") as f:
        lines = f.readlines()

    found_a_change = False
    aggregate = False
    for line in lines:
        if line.startswith(f"## {version}"):
            aggregate = True

        if aggregate:
            if line.startswith("-"):
                line = re.sub(r"-\s*", "", line).strip()
                found_a_change = True
                yield line
            elif found_a_change:
                aggregate = False

    return changes


version = sys.argv[1].strip()
changes = fetch_changes(CHANGELOG, version)
if not changes:
    exit(1)

for change in changes:
    print("- " + change)