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

mozilla / relman-auto-nag / #5323

05 Nov 2024 10:02PM CUT coverage: 21.402% (-0.1%) from 21.516%
#5323

push

coveralls-python

gmierz
Add new rule for monitoring perfalert resolution changes.

426 of 2910 branches covered (14.64%)

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

1942 of 9074 relevant lines covered (21.4%)

0.21 hits per line

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

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

NEW
6
from libmozdata.bugzilla import Bugzilla
×
7

NEW
8
from bugbot.bzcleaner import BzCleaner
×
9

10

NEW
11
class PerfAlertInactiveRegression(BzCleaner):
×
NEW
12
    def __init__(self, *args, **kwargs):
×
NEW
13
        super().__init__(*args, **kwargs)
×
NEW
14
        self.extra_email_info = {}
×
NEW
15
        self._bug_history = {}
×
NEW
16
        self._bug_comments = {}
×
17

NEW
18
    def description(self):
×
NEW
19
        return "PerfAlert regressions whose resolution has changed recently"
×
20

NEW
21
    def get_bz_params(self, date):
×
NEW
22
        fields = [
×
23
            "id",
24
            "resolution",
25
        ]
26

27
        # Find all bugs that have perf-alert, and regression in their keywords. Search
28
        # for bugs that have been changed in the last day. Only look for bugs after
29
        # October 1st, 2024 to prevent triggering comments on older performance regressions
NEW
30
        params = {
×
31
            "include_fields": fields,
32
            "f3": "creation_ts",
33
            "o3": "greaterthan",
34
            "v3": "2024-10-01T00:00:00Z",
35
            "f1": "regressed_by",
36
            "o1": "isnotempty",
37
            "f2": "keywords",
38
            "o2": "allwords",
39
            "v2": ["regression", "perf-alert"],
40
            "f4": "resolution",
41
            "o4": "changedafter",
42
            "v4": date,
43
        }
44

NEW
45
        return params
×
46

NEW
47
    def get_extra_for_template(self):
×
NEW
48
        return self.extra_email_info
×
49

NEW
50
    def get_resolution_comments(self, bugs):
×
51
        # Match all the resolutions with resolution comments if they exist
NEW
52
        for bug_id, bug in bugs.items():
×
NEW
53
            bug_comments = self._bug_comments.get(bug_id, [])
×
NEW
54
            bug_history = self._bug_history.get(bug_id, {})
×
55

56
            # Sometimes a resolution comment is not provided so use a default
NEW
57
            bug_history["resolution_comment"] = "No resolution comment provided."
×
NEW
58
            for comment in bug_comments[::-1]:
×
NEW
59
                if (
×
60
                    comment["creation_time"] == bug_history["resolution_time"]
61
                    and comment["author"] == bug_history["resolution_author"]
62
                ):
NEW
63
                    bug_history["resolution_comment"] = comment["text"]
×
NEW
64
                    break
×
65

NEW
66
            self.extra_email_info[bug_id] = bug_history
×
67

NEW
68
    def comment_handler(self, bug, bug_id, bugs):
×
69
        # Gather all comments to match them with the history after
NEW
70
        self._bug_comments[bug_id] = bug["comments"]
×
71

NEW
72
    def history_handler(self, bug):
×
NEW
73
        bug_info = self._bug_history.setdefault(str(bug["id"]), {})
×
74

75
        # Get the last resolution change that was made in this bug
NEW
76
        for change in bug["history"][::-1]:
×
NEW
77
            for specific_change in change["changes"]:
×
NEW
78
                if specific_change["field_name"] == "status" and specific_change[
×
79
                    "added"
80
                ] in ("RESOLVED", "REOPENED"):
NEW
81
                    bug_info["resolution_time"] = change["when"]
×
NEW
82
                    bug_info["resolution_author"] = change["who"]
×
NEW
83
                    bug_info["resolution"] = specific_change["added"]
×
NEW
84
                    break
×
NEW
85
            if bug_info.get("resolution_author"):
×
NEW
86
                break
×
87

NEW
88
    def gather_bugs_info(self, bugs):
×
NEW
89
        Bugzilla(
×
90
            bugids=self.get_list_bugs(bugs),
91
            historyhandler=self.history_handler,
92
            commenthandler=self.comment_handler,
93
            commentdata=bugs,
94
            comment_include_fields=["text", "creation_time", "author"],
95
        ).get_data().wait()
96

97
        # Match the history with comments to get resolution reasons
NEW
98
        self.get_resolution_comments(bugs)
×
99

NEW
100
    def get_bugs(self, *args, **kwargs):
×
NEW
101
        bugs = super().get_bugs(*args, **kwargs)
×
NEW
102
        self.gather_bugs_info(bugs)
×
NEW
103
        return bugs
×
104

105

NEW
106
if __name__ == "__main__":
×
NEW
107
    PerfAlertInactiveRegression().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