-
Notifications
You must be signed in to change notification settings - Fork 62
/
spambug.py
90 lines (66 loc) · 2.58 KB
/
spambug.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
# 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 auto_nag import people
from auto_nag.bugbug_utils import get_bug_ids_classification
from auto_nag.bzcleaner import BzCleaner
from auto_nag.utils import nice_round
class SpamBug(BzCleaner):
def __init__(self):
super().__init__()
self.people = people.People.get_instance()
def description(self):
return "[Using ML] Detect spam bugs"
def columns(self):
return ["id", "summary", "confidence", "autofixed"]
def sort_columns(self):
return lambda p: (-p[2], -int(p[0]))
def handle_bug(self, bug, data):
reporter = bug["creator"]
if self.people.is_mozilla(reporter):
return None
return bug
def get_bz_params(self, date):
start_date, _ = self.get_dates(date)
return {
"include_fields": ["id", "groups", "summary", "creator"],
# Ignore closed bugs.
"bug_status": "__open__",
"f1": "reporter",
"v1": "%group.editbugs%",
"o1": "notsubstring",
"f2": "creation_ts",
"o2": "greaterthan",
"v2": start_date,
}
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("spambug", 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", "index"}.issubset(bug_data.keys()):
raise Exception(f"Invalid bug response {bug_id}: {bug_data!r}")
bug = raw_bugs[bug_id]
prob = bug_data["prob"]
results[bug_id] = {
"id": bug_id,
"summary": bug["summary"],
"confidence": nice_round(prob[1]),
"autofixed": prob[1] > self.get_config("confidence_threshold"),
}
return results
def get_autofix_change(self):
return {}
if __name__ == "__main__":
SpamBug().run()