forked from igniteflow/codebase-python-api-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
58 lines (47 loc) · 1.98 KB
/
utils.py
File metadata and controls
58 lines (47 loc) · 1.98 KB
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
import sys
from codebase import logger
from codebase.client import CodeBaseAPI
class CodeBaseAPIUtils(CodeBaseAPI):
def bulk_update_ticket_statuses(self, current_status_name, target_status_name):
"""
Example usage to set all "Approved for Dev" tp "Deployed to Dev":
STATUS_TRANSITIONS = {
'dev': ('Approved for Dev', 'Deployed to Dev'),
'uat': ('Approved for UAT', 'Deployed to UAT'),
'prod': ('Approved for Prod', 'Deployed to Prod'),
}
env = 'dev'
current_status_name = STATUS_TRANSITIONS[env][0]
target_status_name = STATUS_TRANSITIONS[env][1]
codebase_utils.bulk_update_ticket_statuses(current_status_name, target_status_name)
"""
# get the status ids because Codebase search doesn't support searching on status id
new_status_id = None
statuses = self.statuses()
for status in statuses:
if status['ticketing_status']['name'] == target_status_name:
new_status_id = status['ticketing_status']['id']
# exit if the ticket status was not found
if target_status_name is None:
logger.info('Status {} not found in project statuses. Options are: {}'.format(
[status['ticketing_status']['name'] for status in statuses]
))
# update the tickets
items = self.search('status:{}'.format(current_status_name))
for item in items:
ticket_id = item['ticket']['ticket_id']
data = {
'ticket_note': {
u'changes': {
u'status_id': unicode(new_status_id),
},
},
}
self.add_note(ticket_id, data)
# print output
sys.stdout.write('[{}] {} {} --> {}\n'.format(
ticket_id,
item['ticket']['summary'],
current_status_name,
target_status_name
))