|
| 1 | +from atlassian import Jira |
| 2 | + |
| 3 | +jira = Jira( |
| 4 | + url='http://localhost:8090', |
| 5 | + username='admin', |
| 6 | + password='admin') |
| 7 | + |
| 8 | + |
| 9 | +def compare_dicts(dict1, dict2, print_diffs=False): |
| 10 | + count = 0 |
| 11 | + hint = [] |
| 12 | + if len(dict1) != len(dict2) and len(dict1) != len(dict2) + 1 and len(dict2) != len(dict1) + 1: |
| 13 | + return False |
| 14 | + |
| 15 | + for key in dict1: |
| 16 | + if dict1[key] != dict2.get(key): |
| 17 | + count += 1 |
| 18 | + hint.append(key) |
| 19 | + if count > 1: |
| 20 | + return False |
| 21 | + line = None |
| 22 | + if len(dict1) != len(dict2): |
| 23 | + line = 'Different size' |
| 24 | + if count == 1: |
| 25 | + line = 'Different: ' + hint[0] |
| 26 | + if line and print_diffs: |
| 27 | + print(line) |
| 28 | + return True |
| 29 | + |
| 30 | + |
| 31 | +def review(): |
| 32 | + notification_scheme_dict = {} |
| 33 | + all_notification_schemes_dict = {} |
| 34 | + |
| 35 | + notification_schemes_ids = jira.get_notification_schemes() |
| 36 | + names = [] |
| 37 | + |
| 38 | + for notification_schemes_id in notification_schemes_ids['values']: |
| 39 | + |
| 40 | + notification_id = notification_schemes_id['id'] |
| 41 | + notification_schemes = jira.get_notification_scheme(notification_id, 'all') |
| 42 | + names.append(notification_schemes['name']) |
| 43 | + notification_scheme_dict = {} |
| 44 | + |
| 45 | + for scheme in notification_schemes['notificationSchemeEvents']: |
| 46 | + notification_types = [] |
| 47 | + |
| 48 | + for notificationType in scheme['notifications']: |
| 49 | + notification_types.append(notificationType['notificationType']) |
| 50 | + notification_scheme_dict[scheme['event']['name']] = notification_types |
| 51 | + all_notification_schemes_dict[notification_schemes['name']] = notification_scheme_dict |
| 52 | + |
| 53 | + show_diffs = False |
| 54 | + for i in range(len(names)): |
| 55 | + for j in range(len(names)): |
| 56 | + if names and i < j: |
| 57 | + if compare_dicts(all_notification_schemes_dict[names[i]], |
| 58 | + all_notification_schemes_dict[names[j]], |
| 59 | + print_diffs=show_diffs): |
| 60 | + print('| same |', names[i], ' | ', names[j], '|') |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == '__main__': |
| 64 | + review() |
0 commit comments