Skip to content

Commit 23103e3

Browse files
jgrahamsuhaibmujahid
andauthoredJan 20, 2025··
Add webcompat_score rule (#2558)
Co-authored-by: Suhaib Mujahid <[email protected]>
1 parent 6e6ce3c commit 23103e3

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
 

‎bugbot/rules/webcompat_score.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
# You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
from typing import Any, Optional
6+
7+
from bugbot import gcp
8+
from bugbot.bzcleaner import BzCleaner
9+
10+
11+
class WebcompatScore(BzCleaner):
12+
def __init__(self):
13+
super().__init__()
14+
self.scored_bugs = {}
15+
16+
def description(self) -> str:
17+
return "Update WebCompat score fields"
18+
19+
def filter_no_nag_keyword(self) -> bool:
20+
return False
21+
22+
def has_default_products(self) -> bool:
23+
return False
24+
25+
def handle_bug(
26+
self, bug: dict[str, Any], data: dict[str, Any]
27+
) -> Optional[dict[str, Any]]:
28+
scored_bugs_key = bug["id"]
29+
bug_id = str(bug["id"])
30+
31+
if (
32+
scored_bugs_key in self.scored_bugs
33+
and bug["cf_webcompat_score"] != self.scored_bugs[scored_bugs_key]
34+
):
35+
self.autofix_changes[bug_id] = {
36+
"cf_webcompat_score": self.scored_bugs[scored_bugs_key]
37+
}
38+
return bug
39+
40+
return None
41+
42+
def get_bz_params(self, date) -> dict[str, Any]:
43+
fields = ["id", "cf_webcompat_score"]
44+
self.scored_bugs = self.get_bug_scores()
45+
return {
46+
"include_fields": fields,
47+
"resolution": "---",
48+
"j_top": "OR",
49+
"f1": "OP",
50+
"f2": "product",
51+
"o2": "equals",
52+
"v2": "Web Compatibility",
53+
"f3": "component",
54+
"o3": "equals",
55+
"v3": "Site Reports",
56+
"f4": "CP",
57+
"f5": "OP",
58+
"f6": "product",
59+
"o6": "notequals",
60+
"v6": "Web Compatibility",
61+
"f7": "keywords",
62+
"o7": "equals",
63+
"v7": "webcompat:site-report",
64+
"f8": "CP",
65+
}
66+
67+
def get_bug_scores(self) -> dict[int, str]:
68+
project = "moz-fx-dev-dschubert-wckb"
69+
dataset = "webcompat_knowledge_base"
70+
71+
client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
72+
query = f"""
73+
SELECT bugs.number, cast(buckets.score_bucket as string) as score_bucket FROM `{project}.{dataset}.site_reports_bugzilla_buckets` as buckets
74+
JOIN `{project}.{dataset}.bugzilla_bugs` as bugs ON bugs.number = buckets.number
75+
WHERE bugs.resolution = ""
76+
"""
77+
78+
return {
79+
row["number"]: row["score_bucket"] for row in client.query(query).result()
80+
}
81+
82+
83+
if __name__ == "__main__":
84+
WebcompatScore().run()

‎scripts/cron_run_daily.sh

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ python -m bugbot.rules.perfalert_inactive_regression --production
2121
# Send an email about all performance alerts who were recently resolved
2222
python -m bugbot.rules.perfalert_resolved_regression --production
2323

24+
# Update the webcompat score fields
25+
python -m bugbot.rules.webcompat_score --production
26+
2427
# Send a mail if the logs are not empty
2528
# MUST ALWAYS BE THE LAST COMMAND
2629
python -m bugbot.log --send

‎templates/webcompat_score.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<p>The following {{ plural('bug has', data, pword='bugs have') }} had the webcompat score updated:</p>
2+
<table {{ table_attrs }}>
3+
<thead>
4+
<tr>
5+
<th>Bug</th>
6+
<th>Summary</th>
7+
</tr>
8+
</thead>
9+
<tbody>
10+
{% for i, (bugid, summary) in enumerate(data) -%}
11+
<tr {% if i % 2 == 0 %}bgcolor="#E0E0E0"
12+
{% endif -%}
13+
>
14+
<td>
15+
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id={{ bugid }}">{{ bugid }}</a>
16+
</td>
17+
<td>{{ summary | e }}</td>
18+
</tr>
19+
{% endfor -%}
20+
</tbody>
21+
</table>

0 commit comments

Comments
 (0)
Please sign in to comment.