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

mozilla / relman-auto-nag / #5455

03 Apr 2025 07:47PM UTC coverage: 21.125% (-0.01%) from 21.136%
#5455

push

coveralls-python

suhaibmujahid
Rename "Fenix" to "Firefox for Android"

426 of 2968 branches covered (14.35%)

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

1 existing line in 1 file now uncovered.

1942 of 9193 relevant lines covered (21.12%)

0.21 hits per line

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

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

5
from libmozdata.bugzilla import Bugzilla
×
6

7
from bugbot import logger
×
8
from bugbot.bugbug_utils import get_bug_ids_classification
×
9
from bugbot.bzcleaner import BzCleaner
×
10
from bugbot.utils import get_config, nice_round
×
11

12

13
class Component(BzCleaner):
×
14
    def __init__(self):
×
15
        super().__init__()
×
16
        self.autofix_component = {}
×
17
        self.frequency = "daily"
×
18
        self.general_confidence_threshold = self.get_config(
×
19
            "general_confidence_threshold"
20
        )
21
        self.component_confidence_threshold = self.get_config("confidence_threshold")
×
22
        self.fenix_confidence_threshold = self.get_config("fenix_confidence_threshold")
×
23

24
    def add_custom_arguments(self, parser):
×
25
        parser.add_argument(
×
26
            "--frequency",
27
            help="Daily (noisy) or Hourly",
28
            choices=["daily", "hourly"],
29
            default="daily",
30
        )
31

32
    def parse_custom_arguments(self, args):
×
33
        self.frequency = args.frequency
×
34

35
    def description(self):
×
36
        return f"[Using ML] Assign a component to untriaged bugs ({self.frequency})"
×
37

38
    def columns(self):
×
39
        return ["id", "summary", "component", "confidence", "autofixed"]
×
40

41
    def sort_columns(self):
×
42
        return lambda p: (-p[3], -int(p[0]))
×
43

44
    def has_product_component(self):
×
45
        # Inject product and components when calling BzCleaner.get_bugs
46
        return True
×
47

48
    def get_bz_params(self, date):
×
49
        start_date, end_date = self.get_dates(date)
×
50

51
        bot = get_config("common", "bot_bz_mail")[0]
×
52

53
        return {
×
54
            "include_fields": ["id", "groups", "summary", "product", "component"],
55
            # Ignore bugs for which we ever modified the product or the component.
56
            "n1": 1,
57
            "f1": "product",
58
            "o1": "changedby",
59
            "v1": bot,
60
            "n2": 1,
61
            "f2": "component",
62
            "o2": "changedby",
63
            "v2": bot,
64
            # Ignore closed bugs.
65
            "bug_status": "__open__",
66
            # Get recent General bugs, and all Untriaged bugs.
67
            "j3": "OR",
68
            "f3": "OP",
69
            "j4": "AND",
70
            "f4": "OP",
71
            "f5": "component",
72
            "o5": "equals",
73
            "v5": "General",
74
            "f6": "creation_ts",
75
            "o6": "greaterthan",
76
            "v6": start_date,
77
            "f7": "CP",
78
            "f8": "component",
79
            "o8": "anyexact",
80
            "v8": "Untriaged,Foxfooding",
81
            "f9": "CP",
82
            "f10": "reporter",
83
            "o10": "notequals",
84
            "v10": "update-bot@bmo.tld",
85
        }
86

87
    def get_bugs(self, date="today", bug_ids=[]):
×
88
        def meets_threshold(bug_data):
×
89
            threshold = (
×
90
                self.general_confidence_threshold
91
                if bug_data["class"] == "Firefox for Android"
92
                or bug_data["class"] == "General"
93
                else self.component_confidence_threshold
94
            )
95
            return bug_data["prob"][bug_data["index"]] >= threshold
×
96

97
        # Retrieve the bugs with the fields defined in get_bz_params
98
        raw_bugs = super().get_bugs(date=date, bug_ids=bug_ids, chunk_size=7000)
×
99

100
        if len(raw_bugs) == 0:
×
101
            return {}
×
102

103
        # Extract the bug ids
104
        bug_ids = list(raw_bugs.keys())
×
105

106
        # Classify those bugs
107
        bugs = get_bug_ids_classification("component", bug_ids)
×
108

109
        fenix_general_bug_ids = []
×
110
        for bug_id, bug_data in bugs.items():
×
111
            if not bug_data.get("available", True):
×
112
                # The bug was not available, it was either removed or is a
113
                # security bug.
114
                continue
×
115
            if meets_threshold(bug_data):
×
NEW
116
                if bug_data.get("class") == "Firefox for Android":
×
117
                    fenix_general_bug_ids.append(bug_id)
×
118
            else:
119
                current_bug_data = raw_bugs[bug_id]
×
120
                if (
×
121
                    current_bug_data["product"] == "Firefox for Android"
122
                    and current_bug_data["component"] == "General"
123
                ):
124
                    fenix_general_bug_ids.append(bug_id)
×
125

126
        if fenix_general_bug_ids:
×
127
            fenix_general_classification = get_bug_ids_classification(
×
128
                "fenixcomponent", fenix_general_bug_ids
129
            )
130

131
            for bug_id, data in fenix_general_classification.items():
×
132
                confidence = data["prob"][data["index"]]
×
133

134
                if (
×
135
                    confidence > self.fenix_confidence_threshold
136
                    and data["class"] != "General"
137
                ):
NEW
138
                    data["class"] = f"Firefox for Android::{data['class']}"
×
139
                    bugs[bug_id] = data
×
140

141
        results = {}
×
142

143
        for bug_id in sorted(bugs.keys()):
×
144
            bug_data = bugs[bug_id]
×
145

146
            if not bug_data.get("available", True):
×
147
                # The bug was not available, it was either removed or is a
148
                # security bug
149
                continue
×
150

151
            if not {"prob", "index", "class", "extra_data"}.issubset(bug_data.keys()):
×
152
                raise Exception(f"Invalid bug response {bug_id}: {bug_data!r}")
×
153

154
            bug = raw_bugs[bug_id]
×
155
            prob = bug_data["prob"]
×
156
            index = bug_data["index"]
×
157
            suggestion = bug_data["class"]
×
158

159
            conflated_components_mapping = bug_data["extra_data"].get(
×
160
                "conflated_components_mapping", {}
161
            )
162

163
            # Skip product-only suggestions that are not useful.
164
            if "::" not in suggestion and bug["product"] == suggestion:
×
165
                continue
×
166

167
            # No need to move a bug to the same component.
168
            if f"{bug['product']}::{bug['component']}" == suggestion:
×
169
                continue
×
170

171
            suggestion = conflated_components_mapping.get(suggestion, suggestion)
×
172

173
            if "::" not in suggestion:
×
174
                logger.error(
×
175
                    f"There is something wrong with this component suggestion! {suggestion}"
176
                )
177
                continue
×
178

179
            i = suggestion.index("::")
×
180
            suggested_product = suggestion[:i]
×
181
            suggested_component = suggestion[i + 2 :]
×
182

183
            # When moving bugs out of the 'General' component, we don't want to change the product (unless it is Firefox).
184
            if bug["component"] == "General" and bug["product"] not in {
×
185
                suggested_product,
186
                "Firefox",
187
            }:
188
                continue
×
189

190
            # Don't move bugs from Firefox::General to Core::Internationalization.
191
            if (
×
192
                bug["product"] == "Firefox"
193
                and bug["component"] == "General"
194
                and suggested_product == "Core"
195
                and suggested_component == "Internationalization"
196
            ):
197
                continue
×
198

199
            result = {
×
200
                "id": bug_id,
201
                "summary": bug["summary"],
202
                "component": suggestion,
203
                "confidence": nice_round(prob[index]),
204
                "autofixed": False,
205
            }
206

207
            # In daily mode, we send an email with all results.
208
            if self.frequency == "daily":
×
209
                results[bug_id] = result
×
210

211
            confidence_threshold_conf = (
×
212
                "confidence_threshold"
213
                if bug["component"] != "General"
214
                else "general_confidence_threshold"
215
            )
216

217
            if prob[index] >= self.get_config(confidence_threshold_conf):
×
218
                self.autofix_component[bug_id] = {
×
219
                    "product": suggested_product,
220
                    "component": suggested_component,
221
                }
222

223
                result["autofixed"] = True
×
224

225
                # In hourly mode, we send an email with only the bugs we acted upon.
226
                if self.frequency == "hourly":
×
227
                    results[bug_id] = result
×
228

229
        # Don't move bugs back into components they were moved out of.
230
        # TODO: Use the component suggestion from the service with the second highest confidence instead.
231
        def history_handler(bug):
×
232
            bug_id = str(bug["id"])
×
233

234
            previous_product_components = set()
×
235

236
            current_product = raw_bugs[bug_id]["product"]
×
237
            current_component = raw_bugs[bug_id]["component"]
×
238

239
            for history in bug["history"]:
×
240
                for change in history["changes"][::-1]:
×
241
                    if change["field_name"] == "product":
×
242
                        current_product = change["removed"]
×
243
                    elif change["field_name"] == "component":
×
244
                        current_component = change["removed"]
×
245

246
                previous_product_components.add((current_product, current_component))
×
247

248
            suggested_product = self.autofix_component[bug_id]["product"]
×
249
            suggested_component = self.autofix_component[bug_id]["component"]
×
250

251
            if (suggested_product, suggested_component) in previous_product_components:
×
252
                results[bug_id]["autofixed"] = False
×
253
                del self.autofix_component[bug_id]
×
254

255
        bugids = list(self.autofix_component.keys())
×
256
        Bugzilla(
×
257
            bugids=bugids,
258
            historyhandler=history_handler,
259
        ).get_data().wait()
260

261
        return results
×
262

263
    def get_autofix_change(self):
×
264
        cc = self.get_config("cc")
×
265
        return {
×
266
            bug_id: (
267
                data.update(
268
                    {
269
                        "cc": {"add": cc},
270
                        "comment": {
271
                            "body": f"The [Bugbug](https://github.com/mozilla/bugbug/) bot thinks this bug should belong to the '{data['product']}::{data['component']}' component, and is moving the bug to that component. Please correct in case you think the bot is wrong."
272
                        },
273
                    }
274
                )
275
                or data
276
            )
277
            for bug_id, data in self.autofix_component.items()
278
        }
279

280
    def get_db_extra(self):
×
281
        return {
×
282
            bugid: "{}::{}".format(v["product"], v["component"])
283
            for bugid, v in self.get_autofix_change().items()
284
        }
285

286

287
if __name__ == "__main__":
×
288
    Component().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