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

mozilla / relman-auto-nag / #4870

21 Dec 2023 01:37PM CUT coverage: 21.807% (-0.09%) from 21.899%
#4870

push

coveralls-python

jpangas
Refactor autofix code

716 of 3604 branches covered (0.0%)

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

1928 of 8841 relevant lines covered (21.81%)

0.22 hits per line

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

0.0
/bugbot/rules/accessibility.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 bugbot import people
×
NEW
6
from bugbot.bugbug_utils import get_bug_ids_classification
×
NEW
7
from bugbot.bzcleaner import BzCleaner
×
NEW
8
from bugbot.utils import nice_round
×
9

10

NEW
11
class Accessibility(BzCleaner):
×
NEW
12
    def __init__(self):
×
NEW
13
        super().__init__()
×
NEW
14
        self.autofix_bugs = {}
×
NEW
15
        self.people = people.People.get_instance()
×
16

NEW
17
    def description(self):
×
NEW
18
        return "[Using ML] Detected accessibility bugs"
×
19

NEW
20
    def columns(self):
×
NEW
21
        return ["id", "summary", "confidence", "auto_fixed", "comments"]
×
22

NEW
23
    def get_bz_params(self, date):
×
NEW
24
        start_date, _ = self.get_dates(date)
×
25

NEW
26
        return {
×
27
            "include_fields": ["id", "summary", "comments"],
28
            "f1": "creation_ts",
29
            "o1": "greaterthan",
30
            "v1": start_date,
31
            "f2": "cf_accessibility_severity",
32
            "o2": "equals",
33
            "v2": "---",
34
            "f3": "keywords",
35
            "o3": "notsubstring",
36
            "v3": "access",
37
        }
38

NEW
39
    def get_bugs(self, date="today", bug_ids=[]):
×
40
        # Retrieve the bugs with the fields defined in get_bz_params
NEW
41
        raw_bugs = super().get_bugs(date=date, bug_ids=bug_ids, chunk_size=7000)
×
42

NEW
43
        if len(raw_bugs) == 0:
×
NEW
44
            return {}
×
45

46
        # Extract the bug ids
NEW
47
        bug_ids = list(raw_bugs.keys())
×
48

49
        # Classify those bugs
NEW
50
        bugs = get_bug_ids_classification("accessibility", bug_ids)
×
51

NEW
52
        for bug_id in sorted(bugs.keys()):
×
NEW
53
            bug_data = bugs[bug_id]
×
54

NEW
55
            if not bug_data.get("available", True):
×
56
                # The bug was not available, it was either removed or is a
57
                # security bug
NEW
58
                continue
×
59

NEW
60
            if not {"prob", "index"}.issubset(bug_data.keys()):
×
NEW
61
                raise Exception(f"Invalid bug response {bug_id}: {bug_data!r}")
×
62

NEW
63
            bug = raw_bugs[bug_id]
×
NEW
64
            prob = bug_data["prob"]
×
65

NEW
66
            if prob[1] > self.get_config("confidence_threshold"):
×
NEW
67
                self.autofix_bugs[bug_id] = {
×
68
                    "id": bug_id,
69
                    "summary": bug["summary"],
70
                    "confidence": nice_round(prob[1]),
71
                }
72

NEW
73
        return self.autofix_bugs
×
74

NEW
75
    def get_autofix_change(self):
×
NEW
76
        return {
×
77
            bug_id: (
78
                data.update(
79
                    {
80
                        "keywords": {"add": "access"},
81
                        "comment": {
82
                            "body": "The [Bugbug](https://github.com/mozilla/bugbug/) bot thinks this bug is an accessibility bug, and is adding the access keyword to the bug. Please correct in case you think the bot is wrong."
83
                        },
84
                    }
85
                )
86
                or data
87
            )
88
            for bug_id, data in self.autofix_bugs.items()
89
        }
90

91

NEW
92
if __name__ == "__main__":
×
NEW
93
    Accessibility().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