-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathgenerate_version_string.py
executable file
·46 lines (37 loc) · 1.33 KB
/
generate_version_string.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
#!/usr/bin/python3
import shutil, os, sys, pkgutil
debug = False
if len(sys.argv) > 1:
debug = True
major = 0
minor = 0
patch = 0
patch_terms = {"(balance)", "(bugfix)", "(refactor)"}
minor_terms = {"(char-rework)", "(feature)"}
major_terms = {"(major)"}
merge_lines = []
for line in reversed(pkgutil.run_command("git log --oneline").split("\n")):
if "Merge pull request #" in line:
hash = line.split(" ", 1)[0]
commit_body = pkgutil.run_command("git log -n 1 --pretty=format:%b " + hash)
if any(major_term in commit_body for major_term in major_terms):
major += 1
minor = 0
patch = 0
if debug:
print(commit_body)
print(str(major) + "." + str(minor) + "." + str(patch))
elif any(minor_term in commit_body for minor_term in minor_terms):
minor += 1
patch = 0
if debug:
print(commit_body)
print(str(major) + "." + str(minor) + "." + str(patch))
elif any(patch_term in commit_body for patch_term in patch_terms):
patch += 1
if debug:
print(commit_body)
print(str(major) + "." + str(minor) + "." + str(patch))
if debug:
print("final:")
print(str(major) + "." + str(minor) + "." + str(patch))