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

mozilla / relman-auto-nag / #4077

pending completion
#4077

push

coveralls-python

suhaibmujahid
Merge remote-tracking branch 'upstream/master' into wiki-missed

549 of 3109 branches covered (17.66%)

615 of 615 new or added lines in 27 files covered. (100.0%)

1773 of 8016 relevant lines covered (22.12%)

0.22 hits per line

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

0.0
/auto_nag/scripts/severity_higher_dups.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 auto_nag import utils
×
8
from auto_nag.bzcleaner import BzCleaner
×
9
from auto_nag.severity import Severity
×
10

11

12
class SeverityHigherDuplicates(BzCleaner):
×
13
    def __init__(self):
×
14
        super().__init__()
×
15
        self.extra_ni = None
×
16

17
    def description(self):
×
18
        return "Bugs with duplicates that have higher severity"
×
19

20
    def handle_bug(self, bug, data):
×
21
        bugid = str(bug["id"])
×
22
        data[bugid] = {
×
23
            "severity": Severity(bug["severity"]),
24
            "duplicates": bug["duplicates"],
25
        }
26

27
        return bug
×
28

29
    def get_bugs(self, date="today", bug_ids=[], chunk_size=None):
×
30
        bugs = super().get_bugs(date, bug_ids, chunk_size)
×
31

32
        dup_bug_ids = {bug_id for bug in bugs.values() for bug_id in bug["duplicates"]}
×
33
        dup_bugs = {}
×
34

35
        Bugzilla(
×
36
            dup_bug_ids,
37
            include_fields=["id", "severity", "cf_last_resolved"],
38
            bughandler=self._handle_dup_bug,
39
            bugdata=dup_bugs,
40
        ).wait()
41

42
        # Keep only bugs that have duplicates with higher severity than them
43
        for bug_id, bug in list(bugs.items()):
×
44
            higher_severity_dups = [
×
45
                dup_bugs[dup_id]
46
                for dup_id in bug["duplicates"]
47
                if dup_id in dup_bugs and dup_bugs[dup_id]["severity"] > bug["severity"]
48
            ]
49

50
            if higher_severity_dups:
×
51
                bug["duplicates"] = higher_severity_dups
×
52
            else:
53
                del bugs[bug_id]
×
54

55
        # Exclude duplicate bugs that were linked before downgrading the severity
56
        Bugzilla(
×
57
            bugs.keys(),
58
            include_fields=["id", "triage_owner", "assigned_to", "history"],
59
            bughandler=self._handle_final_bug_filtering,
60
            bugdata=bugs,
61
        ).wait()
62

63
        self.extra_ni = bugs
×
64

65
        return bugs
×
66

67
    def _handle_dup_bug(self, bug, data):
×
68
        if bug["severity"] not in Severity.ACCEPTED_VALUES:
×
69
            return
×
70

71
        bug["severity"] = Severity(bug["severity"])
×
72
        data[bug["id"]] = bug
×
73

74
    def _get_last_severity_downgrade_time(self, bug):
×
75
        for entry in reversed(bug["history"]):
×
76
            for change in entry["changes"]:
×
77
                if (
×
78
                    change["field_name"] == "severity"
79
                    and change["added"] in Severity.SEVERITY_LEVELS
80
                    and change["removed"] in Severity.SEVERITY_LEVELS
81
                    and Severity(change["added"]) < Severity(change["removed"])
82
                ):
83
                    return entry["when"]
×
84
        return None
×
85

86
    def _handle_final_bug_filtering(self, bug, data):
×
87
        bugid = str(bug["id"])
×
88
        duplicates = data[bugid]["duplicates"]
×
89
        downgrade_time = self._get_last_severity_downgrade_time(bug)
×
90
        if downgrade_time:
×
91
            duplicates = [
×
92
                dup_bug
93
                for dup_bug in duplicates
94
                # cf_last_resolved reflects when it was linked as a duplicate
95
                if dup_bug["cf_last_resolved"] > downgrade_time
96
            ]
97

98
        if duplicates and self.add_auto_ni(bugid, utils.get_mail_to_ni(bug)):
×
99
            data[bugid]["duplicates"] = duplicates
×
100
            data[bugid]["suggested_severity"] = max(
×
101
                dup_bug["severity"] for dup_bug in duplicates
102
            )
103
        else:
104
            del data[bugid]
×
105

106
    def get_extra_for_needinfo_template(self):
×
107
        return self.extra_ni
×
108

109
    def columns(self):
×
110
        return ["id", "summary", "severity", "suggested_severity"]
×
111

112
    def get_bz_params(self, date):
×
113
        fields = ["severity", "duplicates"]
×
114

115
        params = {
×
116
            "include_fields": fields,
117
            "resolution": "---",
118
            "f1": "bug_severity",
119
            "o1": "anyexact",
120
            "v1": "S2,S3,S4,S5",
121
            "f2": "bug_type",
122
            "o2": "equals",
123
            "v2": "defect",
124
            "f3": "duplicates",
125
            "o3": "isnotempty",
126
            "n4": 1,
127
            "f4": "longdesc",
128
            "o4": "casesubstring",
129
            "v4": "could you consider increasing the severity of this bug to",
130
        }
131

132
        return params
×
133

134

135
if __name__ == "__main__":
×
136
    SeverityHigherDuplicates().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