-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_changelog.py
executable file
·64 lines (52 loc) · 1.71 KB
/
update_changelog.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# vf new changelog
# pip3 install python-debian==0.1.39
# pip3 install requests==2.24.0
import re
import sys
from typing import Dict, List
import debian.changelog
import requests
from debian.changelog import Changelog
def read_netxms_changelog(input_lines: List[str]) -> Dict[str, List[str]]:
changelog: Dict[str, List[str]] = {}
version = "UNKNOWN"
padding = ""
for line in input_lines:
if line == "":
continue
if line.strip() == "*":
continue
m = re.match(r"^\# ([0-9.]+(-SNAPSHOT)?)", line)
if m:
padding = ""
version = m.group(1)
if version not in changelog:
v: List[str] = []
changelog[version] = v
if line.startswith("## Fixed issues"):
changelog[version].append(" * Fixed issues:")
padding = " "
if line[0] == "-":
changelog[version].append(" * " + padding + line[2:].strip())
return changelog
version = sys.argv[1]
text = requests.get('https://raw.githubusercontent.com/netxms/changelog/master/ChangeLog.md').text.splitlines()
new_changes = read_netxms_changelog(text)[version]
with open('changelog', 'r') as f:
changelog = Changelog(f)
changelog.new_block(
package='netxms',
version=f'{version}-1',
distributions='stable',
urgency='medium',
author="Alex Kirhenshtein <[email protected]>",
date=debian.changelog.format_date()
)
changelog.add_change('')
for change in new_changes:
changelog.add_change(change)
changelog.add_change('')
# print(changelog)
with open('changelog', 'w') as f:
changelog.write_to_open_file(f)