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

mozilla / relman-auto-nag / #4666

pending completion
#4666

push

coveralls-python

suhaibmujahid
Revert "[patch_closed_bug] Re-enable the rule"

This reverts commit 50095e869.

716 of 3562 branches covered (20.1%)

1924 of 8713 relevant lines covered (22.08%)

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
        # XXX: This is a temporary workaround, should be dropped after
41
        # fixing https://github.com/mozilla/bugbot/issues/1953
42
        if self._has_patch_after_closed(bug):
×
43
            return
×
44

45
        bugid = str(bug["id"])
×
46

47
        assignee = bug.get("assigned_to", "")
×
48
        if utils.is_no_assignee(assignee):
×
49
            assignee = ""
×
50
            nickname = ""
×
51
        else:
52
            nickname = bug["assigned_to_detail"]["nick"]
×
53

54
        data[bugid] = {
×
55
            "id": bugid,
56
            "mail": assignee,
57
            "nickname": nickname,
58
            "summary": self.get_summary(bug),
59
            "regressions": bug["regressions"],
60
        }
61
        return bug
×
62

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

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

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

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

88
        return bugs_without_regr
×
89

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

132
        return params
×
133

134
    def _has_patch_after_closed(self, bug):
×
135
        patches = [
×
136
            attachment["creation_time"]
137
            for attachment in bug["attachments"]
138
            if attachment["content_type"] == "text/x-phabricator-request"
139
            and not attachment["is_obsolete"]
140
        ]
141
        if len(patches) == 0:
×
142
            return False
×
143

144
        latest_patch_at = max(patches)
×
145
        resolved_at = bug["cf_last_resolved"]
×
146

147
        return latest_patch_at > resolved_at
×
148

149
    def get_bugs(self, date="today", bug_ids=[]):
×
150
        bugs = super(UpliftBeta, self).get_bugs(date=date, bug_ids=bug_ids)
×
151
        bugs = self.filter_by_regr(bugs)
×
152

153
        for bugid, data in bugs.items():
×
154
            if data["mail"] and data["nickname"]:
×
155
                self.extra_ni[bugid] = {"regression": len(data["regressions"])}
×
156
                self.add_auto_ni(
×
157
                    bugid, {"mail": data["mail"], "nickname": data["nickname"]}
158
                )
159

160
        return bugs
×
161

162

163
if __name__ == "__main__":
×
164
    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