-
Notifications
You must be signed in to change notification settings - Fork 13
/
debuginfo.py
executable file
·97 lines (70 loc) · 2.74 KB
/
debuginfo.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
import os
from git import Repo
from datetime import datetime
rd = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.abspath(os.path.join(rd, ".."))
CLIENT = "client"
SERVER = "server"
BUILDTOOLS = "buildtools"
REPO_CLIENT_URL = f"https://github.com/ONLYOFFICE/DocSpace-client"
REPO_SERVER_URL = f"https://github.com/ONLYOFFICE/DocSpace-server"
REPO_BUILDTOOLS_URL = f"https://github.com/ONLYOFFICE/DocSpace-buildtools"
LIMIT_DAYS = 30
MESSAGE_SEPARATOR = '__MESSAGE_SEPARATOR__'
SEP = '§'
# https://git-scm.com/docs/pretty-formats
format = f"%H{SEP}%as{SEP}%an{SEP}%s %b{MESSAGE_SEPARATOR}"
data = {}
def fetchCommits(url, type):
path = os.path.join(root_dir, type)
#print(path, os.path.exists(path))
if os.path.exists(path) == False:
print("Error folder does not exists", path)
return
repo = Repo(path)
info = f"| [DocSpace-{type}]({url}) | [{repo.active_branch.name}]({url}/tree/{repo.active_branch.name}) | [{repo.head.commit}]({url}/commit/{repo.head.commit}) |{os.linesep}"
commits_str = repo.git.log(f"--pretty=format: {format}", "--no-merges", f"--since={LIMIT_DAYS}.days")
#print(commits_str)
commits = commits_str.strip().split(MESSAGE_SEPARATOR)
#print(commits)
for item in commits:
elements = item.replace('\n', '').split(SEP)
if len(elements) != 4:
continue
hash = elements[0].strip()
date = datetime.strptime(elements[1].strip(), "%Y-%m-%d")
name = elements[2].strip()
text = elements[3].strip().capitalize()
if date not in data:
data[date] = {}
if name not in data[date]:
data[date][name] = []
data[date][name].append(f"- [{type}]: {text} [`{hash[0:7]}`]({url}/commit/{hash})")
return info
result = f"## Changelog{os.linesep}"
result += f"| Repo | Branch | Last Commit |{os.linesep}"
result += f"| :- | :- | :- |{os.linesep}"
result += fetchCommits(REPO_CLIENT_URL, CLIENT)
result += fetchCommits(REPO_SERVER_URL, SERVER)
result += fetchCommits(REPO_BUILDTOOLS_URL, BUILDTOOLS)
# Create debuginfo.md content
for date in sorted(data, reverse=True):
niceDate = date.strftime("%d %B %Y")
result += f"### {niceDate}{os.linesep}"
for name in sorted(data[date]):
result += f"#### {name}{os.linesep}"
for commit in data[date][name]:
result += f"{commit}{os.linesep}"
print(result)
pathMD = os.path.join(root_dir, CLIENT, "public/debuginfo.md")
# Open text file in write mode
text_file = open(pathMD, "w")
# Write content to file
n = text_file.write(result)
if n == len(result):
print("Success! String written to text file.")
else:
print("Failure! String not written to text file.")
# Close file
text_file.close()