From d66b9f0407012ed38938de1d466ce11a37ddcc0f Mon Sep 17 00:00:00 2001 From: jgraham Date: Thu, 24 Oct 2024 14:30:56 +0100 Subject: [PATCH] Make webcompat platform bugs without keyword use BQ data (#2480) Co-authored-by: Suhaib Mujahid --- .../webcompat_platform_without_keyword.py | 73 ++++++++----------- requirements.txt | 1 + 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/bugbot/rules/webcompat_platform_without_keyword.py b/bugbot/rules/webcompat_platform_without_keyword.py index 8f79e14b3..7d2b2e37f 100644 --- a/bugbot/rules/webcompat_platform_without_keyword.py +++ b/bugbot/rules/webcompat_platform_without_keyword.py @@ -2,8 +2,10 @@ # 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 libmozdata.bugzilla import Bugzilla +from google.cloud import bigquery +from google.oauth2 import service_account +from bugbot import utils from bugbot.bzcleaner import BzCleaner @@ -11,7 +13,7 @@ class WebcompatPlatformWithoutKeyword(BzCleaner): normal_changes_max = 200 def description(self): - return "Core bugs blocking webcompat knowledge base entries without webcompat:platform-bug" + return "Web Compat platform bugs without webcompat:platform-bug keyword" def filter_no_nag_keyword(self): return False @@ -19,52 +21,39 @@ def filter_no_nag_keyword(self): def has_default_products(self): return False - def handle_bug(self, bug, data): - data[bug["id"]] = {"depends_on": set(bug.get("depends_on", []))} - return bug - - def get_core_bugs(self, bugs): - core_bugs = set() - for bug_data in bugs.values(): - core_bugs |= bug_data.get("depends_on", set()) - - def bug_handler(bug, data): - if "webcompat:platform-bug" not in bug["keywords"]: - data[bug["id"]] = bug - - core_bug_data = {} - - Bugzilla( - bugids=list(core_bugs), - include_fields=["id", "summary", "keywords"], - bughandler=bug_handler, - bugdata=core_bug_data, - ).get_data().wait() - - return core_bug_data - def get_autofix_change(self): return { "keywords": {"add": ["webcompat:platform-bug"]}, } def get_bz_params(self, date): - fields = [ - "id", - "depends_on", - ] - params = { - "include_fields": fields, - "product": "Web Compatibility", - "component": "Knowledge Base", - } - - return params - - def get_bugs(self, *args, **kwargs): - bugs = super().get_bugs(*args, **kwargs) - bugs = self.get_core_bugs(bugs) - return bugs + fields = ["id", "summary", "keywords"] + return {"include_fields": fields, "id": self.get_core_bug_ids()} + + def get_core_bug_ids(self): + project = "moz-fx-dev-dschubert-wckb" + dataset = "webcompat_knowledge_base" + + credentials = service_account.Credentials.from_service_account_info( + utils.get_gcp_service_account_info() + ).with_scopes( + [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/drive", + ] + ) + + client = bigquery.Client(project=project, credentials=credentials) + + query = f""" + SELECT core_bug + FROM `{project}.{dataset}.prioritized_kb_entries` as kb_entries + JOIN `moz-fx-dev-dschubert-wckb.webcompat_knowledge_base.bugzilla_bugs` as bugzilla_bugs ON bugzilla_bugs.number = kb_entries.core_bug + WHERE "webcompat:platform-bug" not in UNNEST(bugzilla_bugs.keywords) + LIMIT {self.normal_changes_max} + """ + + return list(row["core_bug"] for row in client.query(query).result()) if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt index f7b91f124..d348b1031 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ alembic==1.13.3 argparse==1.4.0 filelock==3.16.1 +google-cloud-bigquery==3.24.0 gspread==6.1.3 humanize>=0.5.1 icalendar==6.0.1