From b686d78d8d1b8545040c1bd7052df1ed9b532a78 Mon Sep 17 00:00:00 2001 From: Vasiliy Grizel Date: Mon, 20 Jul 2020 12:37:45 +0300 Subject: [PATCH 1/4] Notification schemes --- atlassian/jira.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/atlassian/jira.py b/atlassian/jira.py index 52160e16d..33ba451bb 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -536,6 +536,28 @@ def get_project_permission_scheme(self, project_id_or_key, expand=None): url = 'rest/api/2/project/{0}/permissionscheme?expand={1}'.format(project_id_or_key, expand) return self.get(url) + def get_notification_schemes(self): + """ + Returns a paginated list of notification schemes + """ + url = '/rest/api/2/notificationscheme' + return self.get(url) + + def get_notification_scheme(self, notification_scheme_id, expand=None): + """ + Returns a full representation of the notification scheme for the given id. + Use 'expand' to get details + + :param notification_scheme_id: Id of scheme u wanna work with + :param expand: str + :return: full representation of the notification scheme for the given id + """ + if expand is None: + url = '/rest/api/2/notificationscheme/{}'.format(notification_scheme_id) + else: + url = '/rest/api/2/notificationscheme/{0}?expand={1}'.format(notification_scheme_id, expand) + return self.get(url) + def create_issue_type(self, name, description='', type='standard'): """ From 440d9426b204fab764f073fefc0cdaf4cfc72ba9 Mon Sep 17 00:00:00 2001 From: Vasiliy Grizel Date: Mon, 20 Jul 2020 13:03:06 +0300 Subject: [PATCH 2/4] Notification schemes --- atlassian/jira.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/atlassian/jira.py b/atlassian/jira.py index 33ba451bb..abf89b9ca 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -530,34 +530,32 @@ def get_project_permission_scheme(self, project_id_or_key, expand=None): :param expand: str :return: data of project permission scheme """ - if expand is None: - url = 'rest/api/2/project/{}/permissionscheme'.format(project_id_or_key) - else: - url = 'rest/api/2/project/{0}/permissionscheme?expand={1}'.format(project_id_or_key, expand) + url = 'rest/api/2/project/{}/permissionscheme'.format(project_id_or_key) + params={} + if expand: + params['expand'] = expand + return self.get(url, params=params) - return self.get(url) def get_notification_schemes(self): """ Returns a paginated list of notification schemes """ - url = '/rest/api/2/notificationscheme' + url = 'rest/api/2/notificationscheme' return self.get(url) def get_notification_scheme(self, notification_scheme_id, expand=None): """ Returns a full representation of the notification scheme for the given id. Use 'expand' to get details - :param notification_scheme_id: Id of scheme u wanna work with :param expand: str :return: full representation of the notification scheme for the given id """ - if expand is None: - url = '/rest/api/2/notificationscheme/{}'.format(notification_scheme_id) - else: - url = '/rest/api/2/notificationscheme/{0}?expand={1}'.format(notification_scheme_id, expand) - return self.get(url) - + url = 'rest/api/2/notificationscheme/{}'.format(notification_scheme_id) + params = {} + if expand: + params['expand'] = expand + return self.get(url, params=params) def create_issue_type(self, name, description='', type='standard'): """ From 3e9dc41b741ffcd282cf99becfb4b02ac33924c2 Mon Sep 17 00:00:00 2001 From: Vasiliy Grizel Date: Mon, 20 Jul 2020 13:20:23 +0300 Subject: [PATCH 3/4] file --- .../jira-notification_schemes_duplicates.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 examples/jira/jira-notification_schemes_duplicates.py diff --git a/examples/jira/jira-notification_schemes_duplicates.py b/examples/jira/jira-notification_schemes_duplicates.py new file mode 100644 index 000000000..4e06c2a4f --- /dev/null +++ b/examples/jira/jira-notification_schemes_duplicates.py @@ -0,0 +1,56 @@ +from atlassian import Jira +import requests + +jira = Jira( + url='http://localhost:8090', + username='admin', + password='admin') + + +def compare_dicts(dict1, dict2): + 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 + if len(dict1) != len(dict2): + print('(Different size') + if count == 1: + print('(Different: ', hint[0]) + + return True + +notificationscheme_dict = {} +all_notificationschemes_dict = {} + +notificationschemes_ids = jira.get_notification_schemes() +names = [] + +for notificationschemes_id in notificationschemes_ids['values']: + + id = notificationschemes_id['id'] + notificationschemes = jira.get_notification_scheme(id, 'all') + names.append(notificationschemes['name']) + notificationscheme_dict = {} + + for scheme in notificationschemes['notificationSchemeEvents']: + notificationTypes = [] + + for notificationType in scheme['notifications']: + notificationTypes.append(notificationType['notificationType']) + notificationscheme_dict[scheme['event']['name']] = notificationTypes + + all_notificationschemes_dict[notificationschemes['name']] = notificationscheme_dict + +for i in range(len(names)): + for j in range(len(names)): + if names and i < j: + if compare_dicts(all_notificationschemes_dict[names[i]], all_notificationschemes_dict[names[j]]): + print(names[i], '/', names[j]) + print('same) \n -----------------------------------------------------------------') From fb3f6e9faec320a31f64c7c8c91d3114c475d2f6 Mon Sep 17 00:00:00 2001 From: VasiliyGrizel <66676075+VasiliyGrizel@users.noreply.github.com> Date: Mon, 20 Jul 2020 13:40:37 +0300 Subject: [PATCH 4/4] Search the same notification schemes Search the same notification schemes --- examples/jira/jira-notification_schemes_duplicates.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/jira/jira-notification_schemes_duplicates.py b/examples/jira/jira-notification_schemes_duplicates.py index 4e06c2a4f..96fec4d8b 100644 --- a/examples/jira/jira-notification_schemes_duplicates.py +++ b/examples/jira/jira-notification_schemes_duplicates.py @@ -45,7 +45,6 @@ def compare_dicts(dict1, dict2): for notificationType in scheme['notifications']: notificationTypes.append(notificationType['notificationType']) notificationscheme_dict[scheme['event']['name']] = notificationTypes - all_notificationschemes_dict[notificationschemes['name']] = notificationscheme_dict for i in range(len(names)):