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

mozilla / relman-auto-nag / #5312

04 Nov 2024 08:22PM CUT coverage: 21.66% (+0.008%) from 21.652%
#5312

push

coveralls-python

benjaminmah
Moved filtering step to `handle_bug()`

426 of 2878 branches covered (14.8%)

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

3 existing lines in 1 file now uncovered.

1942 of 8966 relevant lines covered (21.66%)

0.22 hits per line

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

0.0
/bugbot/rules/uplift_beta.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 import utils as lmdutils
×
6
from libmozdata.bugzilla import Bugzilla
×
7

8
from bugbot import utils
×
9
from bugbot.bzcleaner import BzCleaner
×
10

11

12
class UpliftBeta(BzCleaner):
×
13
    def __init__(self):
×
14
        super(UpliftBeta, self).__init__()
×
15
        if not self.init_versions():
×
16
            return
×
17

18
        self.beta = self.versions["beta"]
×
19
        self.status_central = utils.get_flag(
×
20
            self.versions["central"], "status", "central"
21
        )
22
        self.status_beta = utils.get_flag(self.beta, "status", "beta")
×
23

24
        # Bugs will be added to `extra_ni` later after being fetched
25
        self.extra_ni = {"status_beta": f"status-firefox{self.beta}"}
×
26

27
    def description(self):
×
28
        return "Bugs fixed in nightly but still affecting beta"
×
29

30
    def has_assignee(self):
×
31
        return True
×
32

33
    def get_extra_for_needinfo_template(self):
×
34
        return self.extra_ni
×
35

36
    def columns(self):
×
37
        return ["id", "summary", "assignee"]
×
38

39
    def handle_bug(self, bug, data):
×
40
        bugid = str(bug["id"])
×
41

42
        assignee = bug.get("assigned_to", "")
×
43
        if utils.is_no_assignee(assignee):
×
44
            assignee = ""
×
45
            nickname = ""
×
46
        else:
47
            nickname = bug["assigned_to_detail"]["nick"]
×
48

NEW
49
        if self.is_needinfo_on_assignee(bug.get("flags", []), assignee):
×
NEW
50
            return None
×
51

UNCOV
52
        data[bugid] = {
×
53
            "id": bugid,
54
            "mail": assignee,
55
            "nickname": nickname,
56
            "summary": self.get_summary(bug),
57
            "regressions": bug["regressions"],
58
            "assigned_to": assignee,
59
            "flags": bug.get("flags", []),
60
        }
61

UNCOV
62
        return bug
×
63

64
    def filter_by_regr(self, bugs):
×
65
        # Filter the bugs which don't have any regression or where the regressions are all closed
66
        def bug_handler(bug, data):
×
67
            if bug["status"] in {"RESOLVED", "VERIFIED", "CLOSED"}:
×
68
                data.add(bug["id"])
×
69

70
        bugids = {r for info in bugs.values() for r in info["regressions"]}
×
71
        if not bugids:
×
72
            return bugs
×
73

74
        fixed_bugs = set()
×
75
        Bugzilla(
×
76
            bugids=list(bugids),
77
            include_fields=["id", "status"],
78
            bughandler=bug_handler,
79
            bugdata=fixed_bugs,
80
        ).get_data().wait()
81

82
        bugs_without_regr = {}
×
83
        for bugid, info in bugs.items():
×
84
            regs = set(info["regressions"])
×
85
            regs = regs - fixed_bugs
×
86
            if not regs:
×
87
                bugs_without_regr[bugid] = info
×
88

89
        return bugs_without_regr
×
90

NEW
91
    def is_needinfo_on_assignee(self, flags, assignee):
×
NEW
92
        for flag in flags:
×
NEW
93
            if (
×
94
                flag["name"] == "needinfo"
95
                and flag["status"] == "?"
96
                and flag["requestee"] == assignee
97
            ):
NEW
98
                return True
×
NEW
99
        return False
×
100

101
    def get_bz_params(self, date):
×
102
        self.date = lmdutils.get_date_ymd(date)
×
103
        fields = [
×
104
            self.status_beta,
105
            "regressions",
106
            "attachments.creation_time",
107
            "attachments.is_obsolete",
108
            "attachments.content_type",
109
            "cf_last_resolved",
110
            "assigned_to",
111
            "flags",
112
        ]
113
        params = {
×
114
            "include_fields": fields,
115
            "bug_type": "defect",
116
            "resolution": ["---", "FIXED"],
117
            "f1": self.status_central,
118
            "o1": "anyexact",
119
            "v1": ",".join(["fixed", "verified"]),
120
            "f2": self.status_beta,
121
            "o2": "anyexact",
122
            "v2": ["affected", "fix-optional"],
123
            "f3": "flagtypes.name",
124
            "o3": "notsubstring",
125
            "v3": "approval-mozilla-beta",
126
            # Don't nag several times
127
            "n5": 1,
128
            "f5": "longdesc",
129
            "o5": "casesubstring",
130
            # this a part of the comment we've in templates/uplift_beta_needinfo.txt
131
            "v5": ", is this bug important enough to require an uplift?",
132
            # Check if have at least one attachment which is a Phabricator request
133
            "f6": "attachments.mimetype",
134
            "o6": "anyexact",
135
            "v6": ["text/x-phabricator-request", "text/x-github-pull-request"],
136
            # skip if whiteboard contains checkin-needed-beta (e.g. test-only uplift)
137
            "f7": "status_whiteboard",
138
            "o7": "notsubstring",
139
            "v7": "[checkin-needed-beta]",
140
        }
141

142
        return params
×
143

144
    def get_bugs(self, date="today", bug_ids=[]):
×
145
        bugs = super(UpliftBeta, self).get_bugs(date=date, bug_ids=bug_ids)
×
146
        bugs = self.filter_by_regr(bugs)
×
147

UNCOV
148
        for bugid, data in bugs.items():
×
149
            if data["mail"] and data["nickname"]:
×
150
                self.extra_ni[bugid] = {"regression": len(data["regressions"])}
×
151
                self.add_auto_ni(
×
152
                    bugid, {"mail": data["mail"], "nickname": data["nickname"]}
153
                )
154

155
        return bugs
×
156

157

158
if __name__ == "__main__":
×
159
    UpliftBeta().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