• 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/copy_duplicate_info.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

10

11
class CopyDuplicateInfo(BzCleaner):
×
12
    def __init__(self):
×
13
        super(CopyDuplicateInfo, self).__init__()
×
14
        self.autofix_data = {}
×
15

16
    def description(self):
×
17
        return "Bugs which are DUPLICATE and some info haven't been moved"
×
18

19
    def has_product_component(self):
×
20
        return True
×
21

22
    def set_autofix(self, bugs, dups, signatures, pcs):
×
23
        for bugid, missed_sgns in signatures.items():
×
24
            sgns = dups[bugid]["signature"]
×
25
            sgns = utils.add_signatures(sgns, missed_sgns)
×
26
            self.autofix_data[bugid] = {
×
27
                "cf_crash_signature": sgns,
28
                "comment": {"body": "Copying crash signatures from duplicate bugs."},
29
            }
30

31
        for bugid, pc in pcs.items():
×
32
            if bugid in self.autofix_data:
×
33
                self.autofix_data[bugid].update(pc)
×
34
            else:
35
                self.autofix_data[bugid] = pc
×
36

37
    def get_fixed_bugs(self, bugs, dups, signatures, pcs):
×
38
        res = {}
×
39
        for bugid in signatures.keys():
×
40
            res[bugid] = info = dups[bugid]
×
41
            info["update_signature"] = "Yes"
×
42

43
        for bugid in pcs.keys():
×
44
            if bugid in res:
×
45
                res[bugid]["update_pc"] = "Yes"
×
46
            else:
47
                res[bugid] = info = bugs[bugid]
×
48
                info["update_pc"] = "Yes"
×
49

50
        for info in res.values():
×
51
            if "update_pc" not in info:
×
52
                info["update_pc"] = "No"
×
53
            if "update_signature" not in info:
×
54
                info["update_signature"] = "No"
×
55

56
        return res
×
57

58
    def columns(self):
×
59
        return ["id", "summary", "update_signature", "update_pc"]
×
60

61
    def sort_columns(self):
×
62
        return lambda p: (
×
63
            0 if p[2] == "Yes" else 1,
64
            0 if p[3] == "Yes" else 1,
65
            -int(p[0]),
66
        )
67

68
    def get_autofix_change(self):
×
69
        return self.autofix_data
×
70

71
    def handle_bug(self, bug, data):
×
72
        bugid = str(bug["id"])
×
73
        data[bugid] = {
×
74
            "id": bugid,
75
            "summary": self.get_summary(bug),
76
            "signature": bug.get("cf_crash_signature", ""),
77
            "dupe": str(bug["dupe_of"]),
78
            "product": bug["product"],
79
            "component": bug["component"],
80
            "version": bug["version"],
81
        }
82
        return bug
×
83

84
    def get_dups(self, bugs):
×
85
        def handler(bug, data):
×
86
            if bug["product"] in self.get_config("products"):
×
87
                self.handle_bug(bug, data)
×
88

89
        bugids = [info["dupe"] for info in bugs.values()]
×
90
        data = {}
×
91

92
        Bugzilla(
×
93
            bugids=bugids,
94
            include_fields=[
95
                "cf_crash_signature",
96
                "dupe_of",
97
                "product",
98
                "component",
99
                "id",
100
                "summary",
101
                "groups",
102
                "version",
103
            ],
104
            bughandler=handler,
105
            bugdata=data,
106
        ).get_data().wait()
107

108
        return data
×
109

110
    def compare(self, bugs, dups):
×
111
        # each bug in bugs is the dup of one in dups
112
        # so the characteristics of this bug should be in the dup
113
        signatures = {}
×
114
        pcs = {}
×
115
        for bugid, info in bugs.items():
×
116
            dupid = info["dupe"]
×
117
            if dupid not in dups:
×
118
                # the bug is unaccessible (sec bug for example)
119
                continue
×
120

121
            dup = dups[dupid]
×
122
            bs = utils.get_signatures(info["signature"])
×
123
            ds = utils.get_signatures(dup["signature"])
×
124
            if not bs.issubset(ds):
×
125
                signatures[dupid] = bs - ds
×
126

127
            pc = {}
×
128
            for x in ["product", "component"]:
×
129
                if info[x] != dup[x]:
×
130
                    pc[x] = dup[x]
×
131
            if pc:
×
132
                # when we change the product, we change the version too
133
                # to avoid incompatible version in the new product
134
                if "product" in pc and info["version"] != dup["version"]:
×
135
                    pc["version"] = dup["version"]
×
136
                pcs[bugid] = pc
×
137

138
        # Don't move product/component for now
139
        # return signatures, pcs
140
        return signatures, {}
×
141

142
    def get_bz_params(self, date):
×
143
        start_date, end_date = self.get_dates(date)
×
144
        fields = ["cf_crash_signature", "dupe_of", "version"]
×
145
        params = {
×
146
            "include_fields": fields,
147
            "resolution": "DUPLICATE",
148
            "f1": "resolution",
149
            "o1": "changedafter",
150
            "v1": start_date,
151
        }
152

153
        return params
×
154

155
    def get_bugs(self, date="today", bug_ids=[]):
×
156
        bugs = super(CopyDuplicateInfo, self).get_bugs(date=date, bug_ids=bug_ids)
×
157
        dups = self.get_dups(bugs)
×
158
        signatures, pcs = self.compare(bugs, dups)
×
159

160
        self.set_autofix(bugs, dups, signatures, pcs)
×
161
        bugs = self.get_fixed_bugs(bugs, dups, signatures, pcs)
×
162

163
        return bugs
×
164

165

166
if __name__ == "__main__":
×
167
    CopyDuplicateInfo().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