-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathprint_version_changelog.py
More file actions
48 lines (38 loc) · 1.26 KB
/
print_version_changelog.py
File metadata and controls
48 lines (38 loc) · 1.26 KB
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
38
39
40
41
42
43
44
45
46
47
48
import os.path
import click
def is_release_head(line):
if line.startswith("## ["):
return True
else:
return False
def check_if_start_of_line_factory(version):
if version is None:
return lambda line: is_release_head(line)
else:
return lambda line: is_release_head(line) and version in line
@click.command("find-version")
@click.option(
"--version", help="Target version to output, if none, the topmost"
)
@click.option(
"--changelog-path",
default="./CHANGELOG.md",
help="Path to changelog, defaults to ./CHANGELOG.md (works if you run it from root of repo)",
)
def find_version_changelog(version, changelog_path):
target_changes = []
in_version = False
is_start_of_version = check_if_start_of_line_factory(version)
with open(os.path.expanduser(changelog_path), "r") as ch_file:
content = ch_file.read()
for line in content.splitlines():
if is_release_head(line) and in_version:
break
elif is_start_of_version(line):
in_version = True
if in_version:
target_changes.append(line)
changes = "\n".join(target_changes)
click.echo(changes)
if __name__ == "__main__":
find_version_changelog()