Skip to content

Commit 5321aa4

Browse files
authored
Set webcompat:platform-bug on site reports likely to be platform bugs (#2674)
1 parent 5810532 commit 5321aa4

File tree

1 file changed

+73
-15
lines changed

1 file changed

+73
-15
lines changed

bugbot/rules/webcompat_platform_without_keyword.py

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,103 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44

5+
from datetime import datetime
6+
from typing import Any, Optional
7+
58
from bugbot import gcp
69
from bugbot.bzcleaner import BzCleaner
710

811

912
class WebcompatPlatformWithoutKeyword(BzCleaner):
1013
normal_changes_max = 200
1114

12-
def description(self):
15+
def __init__(self):
16+
super().__init__()
17+
self.last_bugzilla_import_time: Optional[datetime] = None
18+
19+
def description(self) -> str:
1320
return "Web Compat platform bugs without webcompat:platform-bug keyword"
1421

15-
def filter_no_nag_keyword(self):
22+
def filter_no_nag_keyword(self) -> bool:
1623
return False
1724

18-
def has_default_products(self):
25+
def has_default_products(self) -> bool:
1926
return False
2027

2128
def get_autofix_change(self):
2229
return {
2330
"keywords": {"add": ["webcompat:platform-bug"]},
2431
}
2532

26-
def get_bz_params(self, date):
27-
fields = ["id", "summary", "keywords"]
28-
return {"include_fields": fields, "id": self.get_core_bug_ids()}
33+
def handle_bug(
34+
self, bug: dict[str, Any], data: dict[str, Any]
35+
) -> Optional[dict[str, Any]]:
36+
bug_id = str(bug["id"])
37+
38+
# If the bug was updated later than our latest bugzilla data there could be a race,
39+
# so prefer to do nothing.
40+
if (
41+
self.last_bugzilla_import_time
42+
and datetime.fromisoformat(bug["last_change_time"])
43+
> self.last_bugzilla_import_time
44+
):
45+
return None
2946

30-
def get_core_bug_ids(self):
47+
self.autofix_changes[bug_id] = self.get_autofix_change()
48+
return bug
49+
50+
def get_bz_params(self, date) -> dict[str, Any]:
51+
fields = ["id", "summary", "keywords", "last_change_time"]
52+
return {"include_fields": fields, "id": self.get_bug_ids()}
53+
54+
def get_bug_ids(self) -> list[int]:
3155
project = "moz-fx-dev-dschubert-wckb"
3256
dataset = "webcompat_knowledge_base"
3357

3458
client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
59+
60+
last_run_at_rows = list(
61+
client.query(
62+
f"""
63+
SELECT run_at FROM `{project}.{dataset}.import_runs` WHERE is_history_fetch_completed ORDER BY run_at DESC LIMIT 1
64+
"""
65+
).result()
66+
)
67+
if last_run_at_rows:
68+
self.last_bugzilla_import_time = last_run_at_rows[0]["run_at"]
69+
3570
query = f"""
36-
SELECT core_bug
37-
FROM `{project}.{dataset}.prioritized_kb_entries` as kb_entries
38-
JOIN `moz-fx-dev-dschubert-wckb.webcompat_knowledge_base.bugzilla_bugs` as bugzilla_bugs ON bugzilla_bugs.number = kb_entries.core_bug
39-
WHERE "webcompat:platform-bug" not in UNNEST(bugzilla_bugs.keywords)
40-
LIMIT {self.normal_changes_max}
41-
"""
42-
43-
return list(row["core_bug"] for row in client.query(query).result())
71+
WITH webcompat_removed AS (
72+
SELECT number FROM `{project}.{dataset}.bugs_history` as bugs_history
73+
JOIN bugs_history.changes AS changes
74+
WHERE changes.field_name = "keywords" AND changes.removed = "webcompat:platform-bug"
75+
),
76+
77+
site_reports AS (
78+
SELECT DISTINCT bugs.number AS number FROM `{project}.{dataset}.bugzilla_bugs` AS bugs
79+
JOIN `{project}.{dataset}.breakage_reports` as breakage_reports ON bugs.number = breakage_reports.breakage_bug
80+
JOIN `{project}.{dataset}.breakage_reports_core_bugs` as breakage_reports_core_bugs ON bugs.number = breakage_reports_core_bugs.breakage_bug
81+
LEFT JOIN webcompat_removed ON webcompat_removed.number = bugs.number
82+
JOIN `{project}.{dataset}.bugzilla_bugs` AS core_bugs ON breakage_reports_core_bugs.core_bug = core_bugs.number
83+
WHERE "webcompat:platform-bug" NOT IN UNNEST(bugs.keywords) AND "webcompat:needs-diagnosis" NOT IN UNNEST(bugs.keywords) AND bugs.resolution = "" AND core_bugs.resolution = "" AND webcompat_removed.number IS NULL
84+
),
85+
86+
core_bugs AS (
87+
SELECT core_bug AS number
88+
FROM `{project}.{dataset}.prioritized_kb_entries` as kb_entries
89+
JOIN `{project}.{dataset}.bugzilla_bugs` as bugzilla_bugs ON bugzilla_bugs.number = kb_entries.core_bug
90+
WHERE "webcompat:platform-bug" not in UNNEST(bugzilla_bugs.keywords)
91+
)
92+
93+
SELECT number FROM (
94+
SELECT number FROM site_reports
95+
UNION ALL
96+
SELECT number FROM core_bugs
97+
)
98+
LIMIT {self.normal_changes_max}
99+
"""
100+
101+
return list(row["number"] for row in client.query(query).result())
44102

45103

46104
if __name__ == "__main__":

0 commit comments

Comments
 (0)