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

mozilla / relman-auto-nag / #4349

pending completion
#4349

push

coveralls-python

sosa-e
Revert "Minimizing config file"

This reverts commit 614159597.

564 of 3081 branches covered (18.31%)

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

1804 of 7980 relevant lines covered (22.61%)

0.23 hits per line

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

0.0
/auto_nag/scripts/prod_comp_changed_with_priority.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
import dateutil.parser
×
6
from libmozdata.bugzilla import Bugzilla
×
7

8
from auto_nag.bzcleaner import BzCleaner
×
9

10

11
class ProdCompChangedWithPriority(BzCleaner):
×
12

13
    CHANGE = {
×
14
        (True, False): "product",
15
        (True, True): "product::component",
16
        (False, True): "component",
17
    }
18

19
    def __init__(self):
×
20
        super(ProdCompChangedWithPriority, self).__init__()
×
21
        self.autofix_priority = {}
×
22
        self.skiplist = set(self.get_config("skiplist"))
×
23

24
    def description(self):
×
25
        return "Bugs with a priority set before product::component changed"
×
26

27
    def filter_bugs(self, bugs):
×
28
        def history_handler(bug, data):
×
29
            priority_date = None
×
30
            prod_comp_date = None
×
31
            priority_who = None
×
32
            prod_comp_who = None
×
33
            prod = False
×
34
            comp = False
×
35
            bugid = str(bug["id"])
×
36
            for h in bug["history"]:
×
37
                for change in h["changes"]:
×
38
                    if change["field_name"] == "priority":
×
39
                        priority_date = dateutil.parser.parse(h["when"])
×
40
                        priority_who = h["who"]
×
41
                    elif (
×
42
                        change["field_name"] in {"product", "component"}
43
                        and h["who"] not in self.skiplist
44
                    ):
45
                        prod_comp_date = dateutil.parser.parse(h["when"])
×
46
                        prod_comp_who = h["who"]
×
47
                        if priority_date is not None and priority_date < prod_comp_date:
×
48
                            if change["field_name"] == "product":
×
49
                                prod = True
×
50
                            else:
51
                                comp = True
×
52

53
            if (
×
54
                priority_date is None
55
                or prod_comp_date is None
56
                or priority_date >= prod_comp_date
57
                or priority_who == prod_comp_who
58
            ):
59
                del data[bugid]
×
60
            else:
61
                data[bugid]["change_type"] = ProdCompChangedWithPriority.CHANGE[
×
62
                    (prod, comp)
63
                ]
64

65
        bugids = list(bugs.keys())
×
66
        Bugzilla(
×
67
            bugids=bugids, historyhandler=history_handler, historydata=bugs
68
        ).get_data().wait()
69

70
        return bugs
×
71

72
    def set_autofix(self, bugs):
×
73
        doc = self.get_documentation()
×
74
        body = "The {} has been changed since the backlog priority was decided, so we're resetting it.\n{}"
×
75
        for bugid, info in bugs.items():
×
76
            typ = info["change_type"]
×
77
            self.autofix_priority[bugid] = {
×
78
                "comment": {"body": body.format(typ, doc)},
79
                "priority": "--",
80
            }
81

82
    def get_bz_params(self, date):
×
83
        start_date, _ = self.get_dates(date)
×
84
        params = {
×
85
            "bug_status": "__open__",
86
            "f1": "priority",
87
            "o1": "nowords",
88
            "v1": "--,P1,P2",
89
            "j2": "OR",
90
            "f2": "OP",
91
            "f3": "product",
92
            "o3": "everchanged",
93
            "f4": "component",
94
            "o4": "everchanged",
95
            "f5": "CP",
96
            "f6": "creation_ts",
97
            "o6": "greaterthan",
98
            "v6": start_date,
99
        }
100

101
        return params
×
102

103
    def get_bugs(self, date="today", bug_ids=[]):
×
104
        bugs = super(ProdCompChangedWithPriority, self).get_bugs(
×
105
            date=date, bug_ids=bug_ids
106
        )
107
        bugs = self.filter_bugs(bugs)
×
108
        self.set_autofix(bugs)
×
109

110
        return bugs
×
111

112
    def get_autofix_change(self):
×
113
        return self.autofix_priority
×
114

115

116
if __name__ == "__main__":
×
117
    ProdCompChangedWithPriority().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