Include new rule for detecting accessibility related bugs (#2308)

This commit is contained in:
John Pangas 2024-02-05 17:39:37 +03:00 коммит произвёл GitHub
Родитель 6966638cf3
Коммит 6ebc889439
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 111 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,81 @@
# 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 AccessibilityBug(BzCleaner):
def __init__(self, confidence_threshold: float = 0.9):
"""
Initialize the AccessibilityBug class.
Args:
confidence_threshold: The confidence threshold for
considering a bug as accessibility related.
"""
super().__init__()
self.confidence_threshold = confidence_threshold
def description(self):
return "[Using ML] Detected accessibility bugs"
def columns(self):
return ["id", "summary", "confidence", "autofixed"]
def get_bz_params(self, date):
start_date, _ = self.get_dates(date)
return {
"f1": "creation_ts",
"o1": "greaterthan",
"v1": start_date,
"f2": "cf_accessibility_severity",
"o2": "equals",
"v2": "---",
"f3": "keywords",
"o3": "notsubstring",
"v3": "access",
}
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("accessibility", bug_ids)
results = {}
for bug_id, bug_data in bugs.items():
if not bug_data.get("available", True):
# The bug was not available, it was either removed or is a
# security bug
continue
bug = raw_bugs[bug_id]
prob = bug_data["prob"]
if prob[1] < 0.2:
continue
results[bug_id] = {
"id": bug_id,
"summary": bug["summary"],
"confidence": nice_round(prob[1]),
"autofixed": prob[1] >= self.confidence_threshold,
}
return results
if __name__ == "__main__":
AccessibilityBug().run()

Просмотреть файл

@ -354,6 +354,10 @@
}
}
},
"accessibilitybug": {
"max_days_in_cache": 7,
"days_lookup": 7
},
"component": {
"confidence_threshold": 0.35,
"general_confidence_threshold": 0.8,

Просмотреть файл

@ -9,6 +9,9 @@ python -m bugbot.iam
# Daily (but really runs during the soft freeze week)
python -m bugbot.rules.code_freeze_week -D yesterday --production
# Detect accessibility-related bugs using accessibility model from bugbug
python -m bugbot.rules.accessibilitybug --production
# Try to detect potential performance-related bugs using bugbug
python -m bugbot.rules.performancebug --production

Просмотреть файл

@ -0,0 +1,23 @@
<p>The following {{ plural('bug is', data, pword='bugs are') }} probably accessibility related :</p>
<table {{ table_attrs }}>
<thead>
<tr>
<th>Bug</th>
<th>Summary</th>
<th>Confidence (%)</th>
</tr>
</thead>
<tbody>
{% for i, (bugid, summary, confidence, autofixed) in enumerate(data) -%}
<tr {% if i % 2 == 0 %}bgcolor="#E0E0E0"
{% endif -%}
>
<td>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id={{ bugid }}">{{ bugid }}</a>
</td>
<td>{{ summary | e }}</td>
<td {% if autofixed %}bgcolor="#00FF00"{% endif -%}>{{ confidence }}</td>
</tr>
{% endfor -%}
</tbody>
</table>