-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathregression.py
More file actions
118 lines (88 loc) · 3.66 KB
/
regression.py
File metadata and controls
118 lines (88 loc) · 3.66 KB
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from bugbot.bugbug_utils import get_bug_ids_classification
from bugbot.bzcleaner import BzCleaner
from bugbot.utils import nice_round
class Regression(BzCleaner):
def __init__(self):
super().__init__()
self.autofix_regression = []
def description(self):
return "[Using ML] Bugs with missing regression keyword"
def columns(self):
return ["id", "summary", "confidence", "autofixed"]
def sort_columns(self):
return lambda p: (-p[2], -int(p[0]))
def get_bz_params(self, date):
start_date, end_date = self.get_dates(date)
resolution_skiplist = self.get_config("resolution_skiplist", default=[])
resolution_skiplist = " ".join(resolution_skiplist)
reporter_skiplist = self.get_config("reporter_skiplist", default=[])
reporter_skiplist = ",".join(reporter_skiplist)
params = {
"include_fields": ["id", "groups", "summary"],
"bug_type": "defect",
"f1": "keywords",
"o1": "nowords",
"v1": "regression,feature,meta",
"f2": "resolution",
"o2": "nowords",
"v2": resolution_skiplist,
"f3": "longdesc",
"o3": "changedafter",
"v3": start_date,
"f4": "reporter",
"o4": "nowords",
"v4": reporter_skiplist,
}
return params
def get_bugs(self, date="today", bug_ids=[]):
# Retrieve the bugs with the fields defined in get_bz_params
raw_bugs = super().get_bugs(date=date, bug_ids=bug_ids, chunk_size=7000)
if len(raw_bugs) == 0:
return {}
# Extract the bug ids
bug_ids = list(raw_bugs.keys())
# Classify those bugs
bugs = get_bug_ids_classification("regression", bug_ids)
results = {}
for bug_id in sorted(bugs.keys()):
bug_data = bugs[bug_id]
if not bug_data.get("available", True):
# The bug was not available, it was either removed or is a
# security bug
continue
if not {"prob"}.issubset(bug_data.keys()):
raise Exception(f"Invalid bug response {bug_id}: {bug_data!r}")
bug = raw_bugs[bug_id]
prob = bug_data["prob"]
if prob[1] < 0.5:
continue
bug_id = str(bug_id)
results[bug_id] = {
"id": bug_id,
"summary": bug["summary"],
"confidence": nice_round(prob[1]),
"autofixed": False,
}
# Only autofix results for which we are sure enough.
if prob[1] >= self.get_config("confidence_threshold"):
results[bug_id]["autofixed"] = True
self.autofix_regression.append((bug_id, prob[1]))
return results
def get_autofix_change(self):
cc = self.get_config("cc")
autofix_change = {}
for bug_id, confidence in self.autofix_regression:
autofix_change[bug_id] = {
"keywords": {"add": ["regression"]},
"cc": {"add": cc},
}
if confidence != 1.0:
autofix_change[bug_id]["comment"] = {
"body": "The [Bugbug](https://github.com/mozilla/bugbug/) bot thinks this bug is a regression, but please revert this change in case of error."
}
return autofix_change
if __name__ == "__main__":
Regression().run()