Skip to content

Commit

Permalink
Make webcompat platform bugs without keyword use BQ data (#2480)
Browse files Browse the repository at this point in the history
Co-authored-by: Suhaib Mujahid <[email protected]>
  • Loading branch information
jgraham and suhaibmujahid authored Oct 24, 2024
1 parent 684d3c8 commit d66b9f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 42 deletions.
73 changes: 31 additions & 42 deletions bugbot/rules/webcompat_platform_without_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,58 @@
# 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


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

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__":
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d66b9f0

Please sign in to comment.