• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / relman-auto-nag / #5375

12 Dec 2024 08:13PM CUT coverage: 21.203% (-0.07%) from 21.274%
#5375

push

coveralls-python

jgraham
Add webcompat_score rule

This sets the cf_webcompat_score field to match a value computed in BigQuery.

426 of 2950 branches covered (14.44%)

0 of 31 new or added lines in 1 file covered. (0.0%)

1943 of 9164 relevant lines covered (21.2%)

0.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/bugbot/rules/webcompat_score.py
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

NEW
5
from typing import Any, Optional
×
6

NEW
7
from bugbot import gcp
×
NEW
8
from bugbot.bzcleaner import BzCleaner
×
9

10

NEW
11
class WebcompatScore(BzCleaner):
×
NEW
12
    def __init__(self):
×
NEW
13
        super().__init__()
×
NEW
14
        self.scored_bugs = {}
×
15

NEW
16
    def description(self) -> str:
×
NEW
17
        return "Update WebCompat score fields"
×
18

NEW
19
    def filter_no_nag_keyword(self) -> bool:
×
NEW
20
        return False
×
21

NEW
22
    def has_default_products(self) -> bool:
×
NEW
23
        return False
×
24

NEW
25
    def handle_bug(
×
26
        self, bug: dict[str, Any], data: dict[str, Any]
27
    ) -> Optional[dict[str, Any]]:
NEW
28
        bug_id = bug["id"]
×
29

NEW
30
        if (
×
31
            bug_id in self.scored_bugs
32
            and bug["cf_webcompat_score"] != self.scored_bugs[bug_id]
33
        ):
NEW
34
            self.autofix_changes[str(bug_id)] = {
×
35
                "cf_webcompat_score": self.scored_bugs[bug_id]
36
            }
NEW
37
            return bug
×
38

NEW
39
        return None
×
40

NEW
41
    def get_bz_params(self, date) -> dict[str, Any]:
×
NEW
42
        fields = ["id", "cf_webcompat_score"]
×
NEW
43
        self.scored_bugs = self.get_bug_scores()
×
NEW
44
        return {
×
45
            "include_fields": fields,
46
            "resolution": "---",
47
            "j_top": "OR",
48
            "f1": "OP",
49
            "f2": "product",
50
            "o2": "equals",
51
            "v2": "Web Compatibility",
52
            "f3": "component",
53
            "o3": "equals",
54
            "v3": "Site Reports",
55
            "f4": "CP",
56
            "f5": "OP",
57
            "f6": "product",
58
            "o6": "notequals",
59
            "v6": "Web Compatibility",
60
            "f7": "keywords",
61
            "o7": "equals",
62
            "v7": "webcompat:site-report",
63
            "f8": "CP",
64
        }
65

NEW
66
    def get_bug_scores(self) -> dict[int, str]:
×
NEW
67
        project = "moz-fx-dev-dschubert-wckb"
×
NEW
68
        dataset = "webcompat_knowledge_base"
×
69

NEW
70
        client = gcp.get_bigquery_client(project, ["cloud-platform", "drive"])
×
NEW
71
        query = f"""
×
72
        SELECT bugs.number, cast(buckets.score_bucket as string) as score_bucket FROM `{project}.{dataset}.site_reports_bugzilla_buckets` as buckets
73
        JOIN `{project}.{dataset}.bugzilla_bugs` as bugs ON bugs.number = buckets.number
74
        WHERE bugs.resolution = ""
75
        """
76

NEW
77
        return {
×
78
            row["number"]: row["score_bucket"] for row in client.query(query).result()
79
        }
80

81

NEW
82
if __name__ == "__main__":
×
NEW
83
    WebcompatScore().run()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc