-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_release_notes.py
More file actions
47 lines (37 loc) · 1.19 KB
/
get_release_notes.py
File metadata and controls
47 lines (37 loc) · 1.19 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
"""Get release notes from the CHANGELOG.md file."""
import sys
import logging
logger = logging.getLogger(__name__)
def main(*args) -> int:
"""Main function to get release notes."""
changelog_file_path = "CHANGELOG.md"
version_no = None
if len(args) > 1:
for arg in args[1:]:
if arg.endswith(".md"):
changelog_file_path = arg
elif arg.startswith("v"):
version_no = arg[1:]
break
if not version_no:
raise ValueError("Version number must be specified in the format 'v<version>'")
with open(changelog_file_path) as file:
data = file.read()
start = (
data.index(f"## [{version_no}]")
+ len(f"## [{version_no}]")
+ len(" - YYYY-MM-DD")
)
end = (
data.index("## [", start + 1)
if "## [" in data[start + 1 :]
else data.index("[", start + 1)
if "[" in data[start + 1 :]
else len(data)
)
release_notes = data[start:end].strip()
print(release_notes)
return 0
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
sys.exit(main(*sys.argv))