Skip to content

Commit d66e5d5

Browse files
Add whiteboard flag to webcompat sightline bugs (#2498)
Co-authored-by: Suhaib Mujahid <[email protected]>
1 parent 8ede0c2 commit d66e5d5

File tree

5 files changed

+142
-15
lines changed

5 files changed

+142
-15
lines changed

bugbot/gcp.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from typing import Iterable, Optional
2+
3+
from google.cloud import bigquery
4+
from google.oauth2 import service_account
5+
6+
from bugbot import utils
7+
8+
SCOPES = {
9+
"cloud-platform": "https://www.googleapis.com/auth/cloud-platform",
10+
"drive": "https://www.googleapis.com/auth/drive",
11+
}
12+
13+
14+
def get_bigquery_client(
15+
project: str, scopes: Optional[Iterable[str]] = None
16+
) -> bigquery.Client:
17+
"""Get a bigquery.Client for a given project
18+
19+
Args:
20+
project: Name of the project.
21+
scopes: Optional iterable containing the scopes the client should have.
22+
By default this will be the cloud-platform scopes required to
23+
run queries.
24+
Returns:
25+
bigquery.Client
26+
"""
27+
scope_urls = (
28+
[SCOPES["cloud-platform"]]
29+
if scopes is None
30+
else [SCOPES.get(item, item) for item in scopes]
31+
)
32+
33+
credentials = service_account.Credentials.from_service_account_info(
34+
utils.get_gcp_service_account_info()
35+
).with_scopes(scope_urls)
36+
37+
return bigquery.Client(project=project, credentials=credentials)

bugbot/rules/webcompat_platform_without_keyword.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
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 google.cloud import bigquery
6-
from google.oauth2 import service_account
7-
8-
from bugbot import utils
5+
from bugbot import gcp
96
from bugbot.bzcleaner import BzCleaner
107

118

@@ -34,17 +31,7 @@ def get_core_bug_ids(self):
3431
project = "moz-fx-dev-dschubert-wckb"
3532
dataset = "webcompat_knowledge_base"
3633

37-
credentials = service_account.Credentials.from_service_account_info(
38-
utils.get_gcp_service_account_info()
39-
).with_scopes(
40-
[
41-
"https://www.googleapis.com/auth/cloud-platform",
42-
"https://www.googleapis.com/auth/drive",
43-
]
44-
)
45-
46-
client = bigquery.Client(project=project, credentials=credentials)
47-
34+
client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
4835
query = f"""
4936
SELECT core_bug
5037
FROM `{project}.{dataset}.prioritized_kb_entries` as kb_entries
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 WebcompatSightline(BzCleaner):
12+
WHITEBOARD_ENTRY = "[webcompat:sightline]"
13+
14+
def __init__(self):
15+
super().__init__()
16+
self.sightline_ids = set()
17+
18+
def description(self) -> str:
19+
return "Bugs with the [webcompat:sightline] whiteboard tag updated"
20+
21+
def filter_no_nag_keyword(self) -> bool:
22+
return False
23+
24+
def has_default_products(self) -> bool:
25+
return False
26+
27+
def handle_bug(
28+
self, bug: dict[str, Any], data: dict[str, Any]
29+
) -> Optional[dict[str, Any]]:
30+
bug_id = str(bug["id"])
31+
whiteboard = bug["whiteboard"]
32+
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
45+
46+
return None
47+
48+
def get_bz_params(self, date) -> dict[str, Any]:
49+
fields = ["id", "summary", "whiteboard"]
50+
self.sightline_ids = self.get_sightline_bug_ids()
51+
# Get all bugs that either have, or should have, the [webcompat:sightline]
52+
# whiteboard entry
53+
return {
54+
"include_fields": fields,
55+
"j_top": "OR",
56+
"f1": "bug_id",
57+
"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,
62+
}
63+
64+
def get_sightline_bug_ids(self) -> set[int]:
65+
project = "moz-fx-dev-dschubert-wckb"
66+
dataset = "webcompat_knowledge_base"
67+
68+
client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
69+
query = f"""
70+
SELECT number FROM `{project}.{dataset}.webcompat_topline_metric_site_reports` as bugs
71+
"""
72+
73+
return {row["number"] for row in client.query(query).result()}
74+
75+
76+
if __name__ == "__main__":
77+
WebcompatSightline().run()

scripts/cron_run_hourly.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ python -m bugbot.rules.duplicate_copy_metadata --production
7575
# Add `webcompat:platform-bug` keyword to bugs without a platform keyword
7676
python -m bugbot.rules.webcompat_platform_without_keyword --production
7777

78+
# Update `[webcompat:sightline]` whiteboard entry to bugs in sightline metric set
79+
python -m bugbot.rules.webcompat_sightline --production
80+
7881
source ./scripts/cron_common_end.sh

templates/webcompat_sightline.html

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

0 commit comments

Comments
 (0)