-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
180 lines (134 loc) · 6.04 KB
/
release.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from datetime import datetime
import sys
import requests
import re
import random
import json
if __name__ == "__main__":
user, token = sys.argv[1], sys.argv[2]
pr_number = sys.argv[3]
contributors = []
for page_number in range(1, 4): # GitHub API limit
payload = {"per_page": "100", "page": page_number}
pr_commits = requests.get(
"https://api.github.com/repos/fga-eps-mds/2021.1-PC-GO1-Profile/pulls/" +
pr_number + "/commits", params=payload,
auth=requests.auth.HTTPBasicAuth(user, token)
)
pr_commits_json = pr_commits.json()
if len(pr_commits_json) == 0: break
try:
for pr_commit in pr_commits_json:
contributor = pr_commit["author"]["login"]
contributors.append(contributor) if contributor not in contributors else None
except:
raise Exception("Unable to collect PR contributors.")
pr_body = open("pr_body.txt", "r")
pr_body_text = ""
for line in pr_body.readlines(): pr_body_text = pr_body_text + line
pr_body.close()
pr_issues_numbers = [
pr_issue_number.replace("[#", "").replace("]", "")
for pr_issue_number in re.findall(r"\[#\d+\]", pr_body_text)
]
topics = []
try:
for pr_issue_number in pr_issues_numbers:
issue_data = requests.get(
"https://api.github.com/repos/fga-eps-mds/2021.1-PC-GO1/issues/" +
pr_issue_number, auth=requests.auth.HTTPBasicAuth(user, token)
)
topics.append((pr_issue_number, issue_data.json()["title"]))
except:
print('\033[93m' + "WARNING:" + '\033[0m' + " Unable to collect topics.")
last_tag = requests.get(
"https://api.github.com/repos/fga-eps-mds/2021.1-PC-GO1-Profile/tags",
auth=requests.auth.HTTPBasicAuth(user, token)
).json()[0]['name'][1:]
release_type = sys.argv[4]
tag_components = last_tag.split(".")
changelog = open("CHANGELOG.md", "w")
new_tag = ""
if release_type == "PATCH":
new_tag = "v" + tag_components[0] + "." + tag_components[1] + "." \
+ str(int(tag_components[2]) + 1)
changelog.writelines(
"Hoje, estamos lançando, com as correções dos erros encontrados recentemente "
"pela comunidade, uma nova versão da API de Gerenciamento de Usuários do "
"sistema *[SysArq](https://github.com/fga-eps-mds/2021.1-PC-GO1)*. Ainda não "
"conhece o sistema? "
"**[Saiba Mais](https://fga-eps-mds.github.io/2021.1-PC-GO1/)**\n"
)
icon_c = [
":adhesive_bandage:", ":bug:", ":fire_extinguisher:", ":pill:", ":radioactive:"
]
if topics != []:
changelog.writelines("\n## " + random.choice(icon_c) + " Correções de Erros\n")
elif release_type == "MINOR" or release_type == "MAJOR":
if release_type == "MINOR":
new_tag = "v" + tag_components[0] + "." + str(int(tag_components[1]) + 1) + ".0"
changelog.writelines(
"Hoje, estamos lançando, com as alterações recentes, uma nova versão da API"
" de Gerenciamento de Usuários do sistema "
"*[SysArq](https://github.com/fga-eps-mds/2021.1-PC-GO1)*.\nAinda não "
"conhece o sistema? "
"**[Saiba Mais](https://fga-eps-mds.github.io/2021.1-PC-GO1/)**\n"
)
if release_type == "MAJOR":
new_tag = "v" + str(int(tag_components[0]) + 1) + ".0.0"
changelog.writelines(
"Hoje, estamos lançando, para marcar o fim de um prazo, uma nova versão da"
" API de Gerenciamento de Usuários do sistema "
"*[SysArq](https://github.com/fga-eps-mds/2021.1-PC-GO1)*. Ainda não "
"conhece o sistema? "
"**[Saiba Mais](https://fga-eps-mds.github.io/2021.1-PC-GO1/)**\n"
)
icon_c = [":brain:", ":bulb:", ":dart:", ":pushpin:", ":rocket:"]
if topics != []:
changelog.writelines("\n## " + random.choice(icon_c) + " Alterações\n")
else:
raise Exception("Invalid Release Type.")
if len(topics) != 0:
for topic in topics:
changelog.writelines(
"\n- " + topic[1] + " ([#" + topic[0] +
"](https://github.com/fga-eps-mds/2021.1-PC-GO1/issues/" +
topic[0] + "))\n"
)
icon_cc = [":medal_sports:", ":trophy:", ":1st_place_medal:"]
changelog.writelines("\n## " + random.choice(icon_cc) + " Contribuidores\n")
for contributor in contributors: changelog.writelines("\n- @" + contributor + "\n")
changelog.close()
analytics = requests.get(
"https://sonarcloud.io/api/measures/component_tree?"
"component=fga-eps-mds_2021.1-PC-GO1-Profile&"
"metricKeys=files,functions,complexity,comment_lines_density,"
"duplicated_lines_density,coverage,ncloc,security_rating,tests,"
"test_success_density,test_execution_time,reliability_rating&ps=500"
).json()
now = datetime.now()
data_release = (
f"{now.day:02d}-{now.month:02d}-" + str(now.year) + f"-{now.hour:02d}" +
f"-{now.minute:02d}"
)
analytics_path = (
"fga-eps-mds-2021_1-PC-GO1-Profile-" + data_release + ".json"
)
with open(analytics_path, "w") as file:
json.dump(analytics, file)
command = (
"gh release create " + new_tag + " '" + analytics_path +
"#Métricas SonarCloud (json)' -F CHANGELOG.md -t " + new_tag
)
create_release_sh = open("create_release.sh", "w")
create_release_sh.writelines(command)
create_release_sh.close()
command = (
"cp " + analytics_path + " target/analytics-raw-data\n" +
"cd target\n" +
"git add analytics-raw-data/" + analytics_path + "\n"
"git commit -m \"Adiciona Métricas da Release " + new_tag + " do Profile\"\n"
)
doc_update_sh = open("doc_update.sh", "w")
doc_update_sh.writelines(command)
doc_update_sh.close()