This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
bug_check.py
119 lines (110 loc) · 3.88 KB
/
bug_check.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
from db import *
import requests
#------------------------------------------------------------------------------
#
# This python module polls the bugs marked as 'investigating' in the
# database. It then polls bugzilla for the status of each bug, and builds
# a list of 'conflicts' where the bug is resolved on bugzilla, but not in the
# database
#
#------------------------------------------------------------------------------
def getStatus(bugid):
status = None
try:
url = "https://bugzilla.mozilla.org/rest/bug/" + str(bugid)+ "?include_fields=id,status,resolution,creation_time,cf_last_resolved"
bzjson = requests.get(url).json()
bugs = bzjson['bugs']
details = []
# bugs is an array of bugs, for this query it is a single item in the array
if (int(bugs[0]['id']) == int(bugid)):
status = bugs[0]['status']
details.append(bugs[0]['id'])
details.append(status)
details.append(bugs[0]['resolution'])
details.append(bugs[0]['creation_time'])
details.append(bugs[0]['cf_last_resolved'])
return details
except:
return "None"
def get_investigating_bugs():
"""
Builds a list of bugs for which the status is marked as 'investigating'
in the local database
INPUTS: None
OUTPUT: List of bugids which are marked as 'investigating'
"""
#Get database connection
db = create_db_connnection()
cursor = db.cursor()
#Query for the 'investigating' bugs
query = "select bug from alerts where status = 'Investigating'"
cursor.execute(query)
ids = cursor.fetchall()
#Append the bug id's to the list object to be returned
buglist = []
for bugid in ids:
buglist.append(bugid[0])
cursor.close()
db.close()
bugslist = []
for bugid in buglist:
try :
bugs = [int(x.strip()) for x in bugid.split(',')]
except :
pass
bugslist.extend(bugs)
bugslist.sort()
allbugs = []
allbugs.append(int(bugslist[0]))
for i in range(1,len(bugslist)):
try:
if (int(bugslist[i]) != int(bugslist[i-1])):
allbugs.append(bugslist[i])
except:
print "ERROR: bugslist has an invalid type: %s or %s" % (bugslist[i], bugslist[i-1])
pass
return allbugs
def get_conflicting_bugs():
"""
Get a list of bugs for which their status is 'investigating' in the local
database, but 'RESOLVED' at bugzilla
INPUTS: None
OUTPUT: List of bugids which are 'conflicting' as per the above definition
"""
conflicting = []
#Get the local db bugs marked as 'investigating'
investigating = get_investigating_bugs()
db = create_db_connnection()
cursor = db.cursor()
#Query for the 'investigating' bugs
#Check to see if any 'investigating' bugs are resolved on bugzilla
for bugid in investigating:
query = "select status from alerts where bug = '%s'" % (bugid)
cursor.execute(query)
param = cursor.fetchall()
if not(param and param[0]):
continue
if (param[0][0] == 'Resolved'):
conflicting.append(bugid)
cursor.close()
db.close()
return conflicting
def write_bug_report():
conflicting = []
investigating = get_investigating_bugs()
db = create_db_connnection()
cursor = db.cursor()
for bugid in investigating:
params = []
params = getStatus(bugid)
if len(params) != 5:
continue
#write details to database here
query = '''INSERT into details (bug, status, resolution, date_opened, date_resolved)
values ('%s', '%s', '%s', '%s', '%s')''' % \
(params[0], params[1], params[2], params[3], params[4])
cursor.execute(query)
cursor.close()
db.close()
if __name__ == "__main__":
write_bug_report()