-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
220 lines (168 loc) · 6.37 KB
/
script.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
""" Script to get issues and bugs from jira """
import json
import sys
import os
from urllib.request import urlopen
# ==============================================================================
def commits(arq,key):
commit = ["",""]
for x in arq:
if(x[0:6] == "commit"):
commit[0] = x
elif(x[0:6] == "Author"):
commit[1] = x
else:
if(key in x):
return commit
def datePlus(before):
plus = str(int(before[8:10]) + 1)
before = before[0:8] + plus
return before
def request(url):
"""Function to make requirements"""
response = urlopen(url).read().decode('utf8')
obj = json.loads(response)
return obj
def getLink(link, maxi, dic, par, name):
"""Function to get links of issues"""
start = 0
while True:
url = link.format(maxi, start)
obj = request(url)
issues = obj["issues"]
for issue in issues:
issueUrl = issue["self"]
dic[par].append(issueUrl)
if (start >= obj["total"]):
print("Complete")
try:
os.makedirs("./{}".format(par))
except:
pass
with open('{}/{}.json'.format(par, name), 'w') as outfile:
json.dump(dic, outfile)
dic = dic[par]
with open('temp/{}.json'.format(name), 'w') as outfile:
json.dump(dic, outfile)
try:
os.system("rm -rf spring-framework")
except:
pass
os.system("git clone https://github.com/spring-projects/spring-framework")
break
# show script progress in terminal
percentage = 100 * start // obj["total"]
percentage = str(percentage) + "%"
print("{}".format(percentage))
sys.stdout.write("\033[F")
start += maxi
def getDetails(par, name):
"""Function to get the details of issues"""
with open('temp/{}.json'.format(name)) as data_file:
data = json.load(data_file)
total = len(allIssueUrl["issues"])
cont = 0
for x in data:
# show script progress in terminal
total = "{} {} are missing".format(len(data), par)
print("{}".format(total))
sys.stdout.write("\033[F")
filtered = filter(request(x))
issueId = filtered["issueID"]
with open('{}/{}.json'.format(par, issueId), 'w') as outfile:
json.dump(filtered, outfile)
del data[0]
with open('temp/{}.json'.format(name), 'w') as outfile:
json.dump(data, outfile)
cont += 1
def filter(json):
dic = {}
comments = []
dic["issueID"] = json["id"]
dic["title"] = json["fields"]["summary"]
dic["author"] = json["fields"]["creator"]["displayName"]
dic["reportDate"] = json["fields"]["created"]
dic["fixDate"] = json["fields"]["resolutiondate"]
os.system("git -C spring-framework log -1 --before={} > temp/log.log".format(json["fields"]["created"]))
arq = open('temp/log.log', 'r')
commit = arq.readlines()
dic["commitReport"] = {}
strCommit = str(commit[0]).split()
dic["commitReport"]["commitReport"] = strCommit[1]
if ("Author" in str(commit[1])):
strCommit = str(commit[1]).split(": ")
else:
strCommit = str(commit[2]).split(": ")
strCommit = str(strCommit[1]).split(" <")
dic["commitReport"]["nameReport"] = strCommit[0]
strCommit = strCommit[1].split(">")
dic["commitReport"]["emailReport"] = strCommit[0]
arq.close()
dic["labels"] = json["fields"]["issuetype"]["name"]
dic["description"] = json["fields"]["description"]
Maxcomments = json["fields"]["comment"]["total"]
for x in range(Maxcomments):
comments.append(json["fields"]["comment"]["comments"][x]["body"])
if (Maxcomments > 0):
dic["comments"] = comments
else:
dic["comments"] = []
before = json["fields"]["resolutiondate"]
after = json["fields"]["created"]
os.system("git -C spring-framework log --before={} --after={} > temp/log.log".format(datePlus(before),after))
arq = open('temp/log.log', 'r')
commit = arq.readlines()
commitlist = commits(commit,json["key"])
arq.close()
dic["commitFix"] = {}
if (commitlist != None):
strCommit = str(commitlist[0]).split()
dic["commitFix"]["commitFix"] = strCommit[1]
strCommit = str(commitlist[1]).split(": ")
strCommit = str(strCommit[1]).split(" <")
dic["commitFix"]["nameFix"] = strCommit[0]
strCommit = strCommit[1].split(">")
dic["commitFix"]["emailFix"] = strCommit[0]
dic["TypeFix"] = "By Description"
else:
os.system("git -C spring-framework log -1 --before={} > temp/log.log".format(before))
arq = open('temp/log.log', 'r')
commit = arq.readlines()
arq.close()
strCommit = str(commit[0]).split()
dic["commitFix"]["commitFix"] = strCommit[1]
if ("Author" in str(commit[1])):
strCommit = str(commit[1]).split(": ")
else:
strCommit = str(commit[2]).split(": ")
strCommit = str(strCommit[1]).split(" <")
dic["commitFix"]["nameFix"] = strCommit[0]
strCommit = strCommit[1].split(">")
dic["commitFix"]["emailFix"] = strCommit[0]
dic["TypeFix"] = "By Date"
return dic
# ==============================================================================
allIssueUrl = {"issues": []}
allBugsUrl = {"bugs": []}
# ==============================================================================
try:
os.makedirs("./temp")
except:
pass
print("Choose an option:\n1: Get issues\n2: Get bugs")
print("3: Get issues details\n4: Get bugs details\n")
choosen = int(input())
if(choosen == 1):
print("Getting list of issues:")
url = "https://jira.spring.io/rest/api/2/search?jql=project=SPR+and+resolutiondate!=null&maxResults={}&startAt={}"
getLink(url, 1000, allIssueUrl, "issues", "issuesUrls")
elif(choosen == 2):
print("Getting list of bugs:")
url = "https://jira.spring.io/rest/api/2/search?jql=project=SPR+and+issuetype=Bug+and+resolutiondate!=null&maxResults={}&startAt={}"
getLink(url, 100, allBugsUrl, "bugs", "bugsUrls")
elif(choosen == 3):
print("Getting details of issues:")
getDetails("issues", "issuesUrls")
elif(choosen == 4):
print("Getting details of issues:")
getDetails("bugs", "bugsUrls")