Skip to content

Commit 02cc3dc

Browse files
Add methods for notification schemes (#539)
* Notification schemes * Notification schemes * file * Search the same notification schemes Search the same notification schemes
1 parent 27d073d commit 02cc3dc

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

atlassian/jira.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,33 @@ def get_project_permission_scheme(self, project_id_or_key, expand=None):
530530
:param expand: str
531531
:return: data of project permission scheme
532532
"""
533-
if expand is None:
534-
url = 'rest/api/2/project/{}/permissionscheme'.format(project_id_or_key)
535-
else:
536-
url = 'rest/api/2/project/{0}/permissionscheme?expand={1}'.format(project_id_or_key, expand)
533+
url = 'rest/api/2/project/{}/permissionscheme'.format(project_id_or_key)
534+
params={}
535+
if expand:
536+
params['expand'] = expand
537+
return self.get(url, params=params)
537538

539+
def get_notification_schemes(self):
540+
"""
541+
Returns a paginated list of notification schemes
542+
"""
543+
url = 'rest/api/2/notificationscheme'
538544
return self.get(url)
539545

546+
def get_notification_scheme(self, notification_scheme_id, expand=None):
547+
"""
548+
Returns a full representation of the notification scheme for the given id.
549+
Use 'expand' to get details
550+
:param notification_scheme_id: Id of scheme u wanna work with
551+
:param expand: str
552+
:return: full representation of the notification scheme for the given id
553+
"""
554+
url = 'rest/api/2/notificationscheme/{}'.format(notification_scheme_id)
555+
params = {}
556+
if expand:
557+
params['expand'] = expand
558+
return self.get(url, params=params)
559+
540560
def create_issue_type(self, name, description='', type='standard'):
541561
"""
542562
Create a new issue type
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from atlassian import Jira
2+
import requests
3+
4+
jira = Jira(
5+
url='http://localhost:8090',
6+
username='admin',
7+
password='admin')
8+
9+
10+
def compare_dicts(dict1, dict2):
11+
count = 0
12+
hint = []
13+
if len(dict1) != len(dict2) and len(dict1) != len(dict2) + 1 and len(dict2) != len(dict1) + 1:
14+
return False
15+
16+
for key in dict1:
17+
if dict1[key] != dict2.get(key):
18+
count += 1
19+
hint.append(key)
20+
if count > 1:
21+
return False
22+
if len(dict1) != len(dict2):
23+
print('(Different size')
24+
if count == 1:
25+
print('(Different: ', hint[0])
26+
27+
return True
28+
29+
notificationscheme_dict = {}
30+
all_notificationschemes_dict = {}
31+
32+
notificationschemes_ids = jira.get_notification_schemes()
33+
names = []
34+
35+
for notificationschemes_id in notificationschemes_ids['values']:
36+
37+
id = notificationschemes_id['id']
38+
notificationschemes = jira.get_notification_scheme(id, 'all')
39+
names.append(notificationschemes['name'])
40+
notificationscheme_dict = {}
41+
42+
for scheme in notificationschemes['notificationSchemeEvents']:
43+
notificationTypes = []
44+
45+
for notificationType in scheme['notifications']:
46+
notificationTypes.append(notificationType['notificationType'])
47+
notificationscheme_dict[scheme['event']['name']] = notificationTypes
48+
all_notificationschemes_dict[notificationschemes['name']] = notificationscheme_dict
49+
50+
for i in range(len(names)):
51+
for j in range(len(names)):
52+
if names and i < j:
53+
if compare_dicts(all_notificationschemes_dict[names[i]], all_notificationschemes_dict[names[j]]):
54+
print(names[i], '/', names[j])
55+
print('same) \n -----------------------------------------------------------------')

0 commit comments

Comments
 (0)