File size: 2,040 Bytes
56d74b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from atlassian import Jira

jira = Jira(url="http://localhost:8090", username="admin", password="admin")


def compare_dicts(dict1, dict2, print_diffs=False):
    count = 0
    hint = []
    if len(dict1) != len(dict2) and len(dict1) != len(dict2) + 1 and len(dict2) != len(dict1) + 1:
        return False

    for key in dict1:
        if dict1[key] != dict2.get(key):
            count += 1
            hint.append(key)
            if count > 1:
                return False
    line = None
    if len(dict1) != len(dict2):
        line = "Different size"
    if count == 1:
        line = "Different: " + hint[0]
    if line and print_diffs:
        print(line)
    return True


def review():
    notification_scheme_dict = {}
    all_notification_schemes_dict = {}

    notification_schemes_ids = jira.get_notification_schemes()
    names = []

    for notification_schemes_id in notification_schemes_ids["values"]:

        notification_id = notification_schemes_id["id"]
        notification_schemes = jira.get_notification_scheme(notification_id, "all")
        names.append(notification_schemes["name"])
        notification_scheme_dict = {}

        for scheme in notification_schemes["notificationSchemeEvents"]:
            notification_types = []

            for notificationType in scheme["notifications"]:
                notification_types.append(notificationType["notificationType"])
                notification_scheme_dict[scheme["event"]["name"]] = notification_types
        all_notification_schemes_dict[notification_schemes["name"]] = notification_scheme_dict

    show_diffs = False
    for i in range(len(names)):
        for j in range(len(names)):
            if names and i < j:
                if compare_dicts(
                    all_notification_schemes_dict[names[i]],
                    all_notification_schemes_dict[names[j]],
                    print_diffs=show_diffs,
                ):
                    print("| same |", names[i], " | ", names[j], "|")


if __name__ == "__main__":
    review()