-
Notifications
You must be signed in to change notification settings - Fork 5
/
updateChangelog.py
66 lines (53 loc) · 1.89 KB
/
updateChangelog.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
65
66
import sys
import re
# Read the Git diff from standard input
diff = sys.stdin.read()
# Patterns for searching for added, removed, and modified entries
added_pattern = re.compile(r'^\+name = "(.*)"$')
removed_pattern = re.compile(r'^-name = "(.*)"$')
modified_pattern = re.compile(r'^@@.*name = "(.*)"$')
# Initialize lists for added, removed, and modified entries
added = []
removed = []
modified = []
# Process the lines of the Git diff
for line in diff.split('\n'):
added_match = added_pattern.match(line)
removed_match = removed_pattern.match(line)
modified_match = modified_pattern.match(line)
if added_match:
added.append(added_match.group(1))
elif removed_match:
removed.append(removed_match.group(1))
elif modified_match:
modified.append(modified_match.group(1))
# Generate the desired output
with open("CHANGELOG.md", "r+") as file:
first_line = file.readline()
# Extract the version number from the first line
match = re.match(r"# Release (\d+\.\d+\.\d+)", first_line)
if match:
old_version = match.group(1)
print(f"Old version number: {old_version}")
# Increase the version number by 1
major, minor, patch = map(int, old_version.split("."))
new_version = f"{major}.{minor}.{patch+1}"
print(f"New version number: {new_version}")
file.seek(0)
content = file.read()
file.seek(0)
file.write(f"# Release {new_version}\n\n")
if modified:
file.write('**Updated**\n')
for item in modified:
file.write(f'- {item}\n')
if added:
file.write('**Added**\n')
for item in added:
file.write(f'- {item}\n')
if removed:
file.write('**Removed**\n')
for item in removed:
file.write(f'- {item}\n')
file.write("\n"+content)
file.close