Skip to content

Commit 4e68f4a

Browse files
authored
Add [webcompat:japan] to whiteboard for bugs in Japan Top 1000 (#2697)
1 parent cc67e1c commit 4e68f4a

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

bugbot/rules/webcompat_sightline.py

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@
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 typing import Any, Optional
5+
from dataclasses import dataclass
6+
from typing import Any, Mapping, Optional
67

78
from bugbot import gcp
89
from bugbot.bzcleaner import BzCleaner
910

1011

11-
class WebcompatSightline(BzCleaner):
12-
WHITEBOARD_ENTRY = "[webcompat:sightline]"
12+
@dataclass(frozen=True)
13+
class MetricType:
14+
field: str
15+
whiteboard_entry: str
16+
17+
18+
metrics = [
19+
MetricType("is_sightline", "[webcompat:sightline]"),
20+
MetricType("is_japan_1000", "[webcompat:japan]"),
21+
]
1322

23+
24+
class WebcompatSightline(BzCleaner):
1425
def __init__(self):
1526
super().__init__()
16-
self.sightline_ids = set()
27+
self.metric_bugs = {}
1728

1829
def description(self) -> str:
19-
return "Bugs with the [webcompat:sightline] whiteboard tag updated"
30+
return "Bugs with the [webcompat:<metric name>] whiteboard tag updated"
2031

2132
def filter_no_nag_keyword(self) -> bool:
2233
return False
@@ -30,47 +41,58 @@ def handle_bug(
3041
bug_id = str(bug["id"])
3142
whiteboard = bug["whiteboard"]
3243

33-
if bug["id"] in self.sightline_ids:
34-
if self.WHITEBOARD_ENTRY not in whiteboard:
35-
self.autofix_changes[bug_id] = {
36-
"whiteboard": whiteboard + self.WHITEBOARD_ENTRY
37-
}
38-
return bug
39-
else:
40-
if self.WHITEBOARD_ENTRY in whiteboard:
41-
self.autofix_changes[bug_id] = {
42-
"whiteboard": whiteboard.replace(self.WHITEBOARD_ENTRY, "")
43-
}
44-
return bug
44+
bug_metrics = self.metric_bugs[bug["id"]]
45+
46+
for metric, include in bug_metrics.items():
47+
if include and metric.whiteboard_entry not in whiteboard:
48+
whiteboard += metric.whiteboard_entry
49+
elif not include and metric.whiteboard_entry in whiteboard:
50+
whiteboard = whiteboard.replace(metric.whiteboard_entry, "")
51+
52+
if whiteboard != bug["whiteboard"]:
53+
self.autofix_changes[bug_id] = {"whiteboard": whiteboard}
54+
return bug
4555

4656
return None
4757

4858
def get_bz_params(self, date) -> dict[str, Any]:
4959
fields = ["id", "summary", "whiteboard"]
50-
self.sightline_ids = self.get_sightline_bug_ids()
60+
self.metric_bugs = self.get_metric_bugs()
5161
# Get all bugs that either have, or should have, the [webcompat:sightline]
5262
# whiteboard entry
5363
return {
5464
"include_fields": fields,
5565
"j_top": "OR",
5666
"f1": "bug_id",
5767
"o1": "anyexact",
58-
"v1": ",".join(str(item) for item in self.sightline_ids),
59-
"f2": "status_whiteboard",
60-
"o2": "substring",
61-
"v2": self.WHITEBOARD_ENTRY,
68+
"v1": ",".join(str(item) for item in self.metric_bugs.keys()),
6269
}
6370

64-
def get_sightline_bug_ids(self) -> set[int]:
71+
def get_metric_bugs(self) -> Mapping[int, Mapping[MetricType, bool]]:
6572
project = "moz-fx-dev-dschubert-wckb"
6673
dataset = "webcompat_knowledge_base"
6774

75+
fields = []
76+
conditions = []
77+
78+
for metric in metrics:
79+
fields.append(metric.field)
80+
conditions.append(
81+
f"""({metric.field} != CONTAINS_SUBSTR(bugs.whiteboard, "{metric.whiteboard_entry}"))"""
82+
)
83+
6884
client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
6985
query = f"""
70-
SELECT number FROM `{project}.{dataset}.webcompat_topline_metric_site_reports` as bugs
86+
SELECT number, {", ".join(fields)} FROM `{project}.{dataset}.scored_site_reports` as bugs
87+
WHERE bugs.resolution = "" AND ({" OR ".join(conditions)})
7188
"""
7289

73-
return {row["number"] for row in client.query(query).result()}
90+
results = {}
91+
for row in client.query(query).result():
92+
result = {metric: row[metric.field] for metric in metrics}
93+
results[row.number] = result
94+
95+
return results
7496

7597

7698
if __name__ == "__main__":

0 commit comments

Comments
 (0)