atlassian-python-api 3.41.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. atlassian/VERSION +1 -0
  2. atlassian/__init__.py +32 -0
  3. atlassian/bamboo.py +1343 -0
  4. atlassian/bitbucket/__init__.py +3572 -0
  5. atlassian/bitbucket/base.py +198 -0
  6. atlassian/bitbucket/cloud/__init__.py +24 -0
  7. atlassian/bitbucket/cloud/base.py +123 -0
  8. atlassian/bitbucket/cloud/common/__init__.py +1 -0
  9. atlassian/bitbucket/cloud/common/builds.py +85 -0
  10. atlassian/bitbucket/cloud/common/comments.py +50 -0
  11. atlassian/bitbucket/cloud/common/users.py +79 -0
  12. atlassian/bitbucket/cloud/repositories/__init__.py +437 -0
  13. atlassian/bitbucket/cloud/repositories/branchRestrictions.py +175 -0
  14. atlassian/bitbucket/cloud/repositories/commits.py +188 -0
  15. atlassian/bitbucket/cloud/repositories/defaultReviewers.py +94 -0
  16. atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py +264 -0
  17. atlassian/bitbucket/cloud/repositories/diffstat.py +92 -0
  18. atlassian/bitbucket/cloud/repositories/groupPermissions.py +81 -0
  19. atlassian/bitbucket/cloud/repositories/hooks.py +117 -0
  20. atlassian/bitbucket/cloud/repositories/issues.py +164 -0
  21. atlassian/bitbucket/cloud/repositories/pipelines.py +274 -0
  22. atlassian/bitbucket/cloud/repositories/pullRequests.py +483 -0
  23. atlassian/bitbucket/cloud/repositories/refs.py +136 -0
  24. atlassian/bitbucket/cloud/repositories/repositoryVariables.py +146 -0
  25. atlassian/bitbucket/cloud/workspaces/__init__.py +146 -0
  26. atlassian/bitbucket/cloud/workspaces/members.py +62 -0
  27. atlassian/bitbucket/cloud/workspaces/permissions.py +125 -0
  28. atlassian/bitbucket/cloud/workspaces/projects.py +215 -0
  29. atlassian/bitbucket/server/__init__.py +46 -0
  30. atlassian/bitbucket/server/base.py +63 -0
  31. atlassian/bitbucket/server/common/__init__.py +1 -0
  32. atlassian/bitbucket/server/common/permissions.py +220 -0
  33. atlassian/bitbucket/server/globalPermissions.py +198 -0
  34. atlassian/bitbucket/server/projects/__init__.py +244 -0
  35. atlassian/bitbucket/server/projects/repos/__init__.py +327 -0
  36. atlassian/cloud_admin.py +32 -0
  37. atlassian/confluence.py +3336 -0
  38. atlassian/crowd.py +266 -0
  39. atlassian/errors.py +27 -0
  40. atlassian/insight.py +678 -0
  41. atlassian/jira.py +5324 -0
  42. atlassian/marketplace.py +84 -0
  43. atlassian/portfolio.py +108 -0
  44. atlassian/request_utils.py +39 -0
  45. atlassian/rest_client.py +558 -0
  46. atlassian/service_desk.py +911 -0
  47. atlassian/statuspage.py +3133 -0
  48. atlassian/utils.py +327 -0
  49. atlassian/xray.py +632 -0
  50. atlassian_python_api-3.41.13.dist-info/LICENSE +201 -0
  51. atlassian_python_api-3.41.13.dist-info/METADATA +261 -0
  52. atlassian_python_api-3.41.13.dist-info/RECORD +54 -0
  53. atlassian_python_api-3.41.13.dist-info/WHEEL +5 -0
  54. atlassian_python_api-3.41.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,911 @@
1
+ # coding=utf-8
2
+ import logging
3
+
4
+ from .rest_client import AtlassianRestAPI
5
+
6
+ log = logging.getLogger(__name__)
7
+
8
+
9
+ class ServiceDesk(AtlassianRestAPI):
10
+ """
11
+ JIRA ServiceDesk API object
12
+ """
13
+
14
+ # Information actions
15
+ def get_info(self):
16
+ """Get info about Service Desk app"""
17
+
18
+ return self.get("rest/servicedeskapi/info", headers=self.experimental_headers)
19
+
20
+ def get_service_desks(self):
21
+ """
22
+ Returns all service desks in the Jira Service Desk application
23
+ with the option to include archived service desks
24
+
25
+ :return: Service Desks
26
+ """
27
+ service_desks_list = self.get(
28
+ "rest/servicedeskapi/servicedesk",
29
+ headers=self.experimental_headers,
30
+ )
31
+ if self.advanced_mode:
32
+ return service_desks_list
33
+ else:
34
+ return (service_desks_list or {}).get("values")
35
+
36
+ def get_service_desk_by_id(self, service_desk_id):
37
+ """
38
+ Returns the service desk for a given service desk ID
39
+
40
+ :param service_desk_id: str
41
+ :return: Service Desk
42
+ """
43
+
44
+ return self.get(
45
+ "rest/servicedeskapi/servicedesk/{}".format(service_desk_id),
46
+ headers=self.experimental_headers,
47
+ )
48
+
49
+ # Customers actions
50
+ def create_customer(self, full_name, email):
51
+ """
52
+ Creating customer user.
53
+ :param full_name: str - full name
54
+ :param email: str - email address
55
+ :return: New customer
56
+ """
57
+ log.warning("Creating customer...")
58
+ data = {"fullName": full_name, "email": email}
59
+
60
+ return self.post(
61
+ "rest/servicedeskapi/customer",
62
+ headers=self.experimental_headers,
63
+ data=data,
64
+ )
65
+
66
+ def get_customer_request(self, issue_id_or_key):
67
+ """
68
+ Get single request
69
+
70
+ :param issue_id_or_key: str
71
+ :return: Customer request
72
+ """
73
+
74
+ return self.get(
75
+ "rest/servicedeskapi/request/{}".format(issue_id_or_key),
76
+ headers=self.experimental_headers,
77
+ )
78
+
79
+ def get_my_customer_requests(self):
80
+ """Returning requests where you are the assignee"""
81
+ response = self.get("rest/servicedeskapi/request", headers=self.experimental_headers)
82
+ if self.advanced_mode:
83
+ return response
84
+ return (response or {}).get("values")
85
+
86
+ def create_customer_request(
87
+ self,
88
+ service_desk_id,
89
+ request_type_id,
90
+ values_dict,
91
+ raise_on_behalf_of=None,
92
+ request_participants=None,
93
+ ):
94
+ """
95
+ Creating customer request
96
+
97
+ :param service_desk_id: str
98
+ :param request_type_id: str
99
+ :param values_dict: str/dict
100
+ :param raise_on_behalf_of: str
101
+ :param request_participants: list
102
+ :return: New request
103
+ """
104
+ log.info("Creating request...")
105
+ data = {
106
+ "serviceDeskId": service_desk_id,
107
+ "requestTypeId": request_type_id,
108
+ "requestFieldValues": values_dict,
109
+ }
110
+
111
+ if raise_on_behalf_of:
112
+ data["raiseOnBehalfOf"] = raise_on_behalf_of
113
+
114
+ if request_participants:
115
+ data["requestParticipants"] = request_participants
116
+
117
+ param_map = {"headers": self.experimental_headers}
118
+
119
+ if isinstance(values_dict, dict):
120
+ param_map["json"] = data
121
+ elif isinstance(values_dict, str):
122
+ param_map["data"] = data
123
+
124
+ return self.post("rest/servicedeskapi/request", **param_map)
125
+
126
+ def get_customer_request_status(self, issue_id_or_key):
127
+ """
128
+ Get customer request status name
129
+
130
+ :param issue_id_or_key: str
131
+ :return: Status name
132
+ """
133
+ request = self.get(
134
+ "rest/servicedeskapi/request/{}/status".format(issue_id_or_key),
135
+ headers=self.experimental_headers,
136
+ )
137
+ if self.advanced_mode:
138
+ return request
139
+ if request:
140
+ if request.get("values", []):
141
+ return request.get("values", [])[0].get("status", {})
142
+ return {}
143
+
144
+ def get_customer_transitions(self, issue_id_or_key):
145
+ """
146
+ Returns a list of transitions that customers can perform on the request
147
+
148
+ :param issue_id_or_key: str
149
+ :return:
150
+ """
151
+ url = "rest/servicedeskapi/request/{}/transition".format(issue_id_or_key)
152
+
153
+ return self.get(url, headers=self.experimental_headers)
154
+
155
+ def get_request_types(self, service_desk_id):
156
+ """
157
+ Gets request types
158
+
159
+ :param service_desk_id: str
160
+ :return: all service desk request types
161
+ """
162
+
163
+ return self.get(
164
+ "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id),
165
+ headers=self.experimental_headers,
166
+ )
167
+
168
+ # Participants actions
169
+ def get_request_participants(self, issue_id_or_key, start=0, limit=50):
170
+ """
171
+ Get request participants
172
+
173
+ :param issue_id_or_key: str
174
+ :param start: OPTIONAL: int
175
+ :param limit: OPTIONAL: int
176
+ :return: Request participants
177
+ """
178
+ url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
179
+ params = {}
180
+ if start is not None:
181
+ params["start"] = int(start)
182
+ if limit is not None:
183
+ params["limit"] = int(limit)
184
+
185
+ response = self.get(url, params=params, headers=self.experimental_headers)
186
+ if self.advanced_mode:
187
+ return response
188
+ return (response or {}).get("values")
189
+
190
+ def add_request_participants(self, issue_id_or_key, users_list=None, account_list=None):
191
+ """
192
+ Add users as participants to an existing customer request
193
+ The calling user must have permission to manage participants for this customer request
194
+
195
+ :param issue_id_or_key: str
196
+ :param users_list: list
197
+ :return:
198
+ """
199
+ url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
200
+ data = {}
201
+ if users_list is not None:
202
+ data["usernames"] = users_list
203
+ if account_list is not None:
204
+ data["accountIds"] = account_list
205
+
206
+ return self.post(url, data=data, headers=self.experimental_headers)
207
+
208
+ def remove_request_participants(self, issue_id_or_key, users_list=None, account_list=None):
209
+ """
210
+ Remove participants from an existing customer request
211
+ The calling user must have permission to manage participants for this customer request
212
+
213
+ :param issue_id_or_key: str
214
+ :param users_list: list
215
+ :return:
216
+ """
217
+ url = "rest/servicedeskapi/request/{}/participant".format(issue_id_or_key)
218
+ data = {}
219
+ if users_list is not None:
220
+ data["usernames"] = users_list
221
+ if account_list is not None:
222
+ data["accountIds"] = account_list
223
+
224
+ return self.delete(url, data=data, headers=self.experimental_headers)
225
+
226
+ # Transitions actions
227
+ def perform_transition(self, issue_id_or_key, transition_id, comment=None):
228
+ """
229
+ Perform a customer transition for a given request and transition ID.
230
+ An optional comment can be included to provide a reason for the transition.
231
+
232
+ :param issue_id_or_key: str
233
+ :param transition_id: str
234
+ :param comment: OPTIONAL: str
235
+ :return: None
236
+ """
237
+ log.warning("Performing transition...")
238
+ data = {"id": transition_id, "additionalComment": {"body": comment}}
239
+ url = "rest/servicedeskapi/request/{}/transition".format(issue_id_or_key)
240
+
241
+ return self.post(url, headers=self.experimental_headers, data=data)
242
+
243
+ # Comments actions
244
+ def create_request_comment(self, issue_id_or_key, body, public=True):
245
+ """
246
+ Creating request comment
247
+
248
+ :param issue_id_or_key: str
249
+ :param body: str
250
+ :param public: OPTIONAL: bool (default is True)
251
+ :return: New comment
252
+ """
253
+ log.info("Creating comment...")
254
+ data = {"body": body, "public": public}
255
+ url = "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key)
256
+
257
+ return self.post(path=url, data=data, headers=self.experimental_headers)
258
+
259
+ def get_request_comments(self, issue_id_or_key, start=0, limit=50, public=True, internal=True):
260
+ """
261
+ Get all comments in issue
262
+
263
+ :param issue_id_or_key: str
264
+ :param start: OPTIONAL: int
265
+ :param limit: OPTIONAL: int
266
+ :param public: OPTIONAL: bool
267
+ :param internal: OPTIONAL: bool
268
+ :return: Issue comments
269
+ """
270
+ url = "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key)
271
+ params = {}
272
+ if start is not None:
273
+ params["start"] = int(start)
274
+ if limit is not None:
275
+ params["limit"] = int(limit)
276
+ if public is not None:
277
+ params["public"] = bool(public)
278
+ if internal is not None:
279
+ params["internal"] = bool(internal)
280
+
281
+ response = self.get(url, params=params, headers=self.experimental_headers)
282
+ if self.advanced_mode:
283
+ return response
284
+ return (response or {}).get("values")
285
+
286
+ # return self.get(
287
+ # "rest/servicedeskapi/request/{}/comment".format(issue_id_or_key),
288
+ # headers=self.experimental_headers,
289
+ # )
290
+
291
+ def get_request_comment_by_id(self, issue_id_or_key, comment_id):
292
+ """
293
+ Get single comment by ID
294
+
295
+ :param issue_id_or_key: str
296
+ :param comment_id: str
297
+ :return: Single comment
298
+ """
299
+
300
+ return self.get(
301
+ "rest/servicedeskapi/request/{}/comment/{}".format(issue_id_or_key, comment_id),
302
+ headers=self.experimental_headers,
303
+ )
304
+
305
+ # Organizations actions
306
+ def get_organisations(self, service_desk_id=None, start=0, limit=50):
307
+ """
308
+ Returns a list of organizations in the Jira instance. If the user is not an agent,
309
+ the resource returns a list of organizations the user is a member of.
310
+
311
+ :param service_desk_id: OPTIONAL: str Get organizations from single Service Desk
312
+ :param start: OPTIONAL: int The starting index of the returned objects.
313
+ Base index: 0. See the Pagination section for more details.
314
+ :param limit: OPTIONAL: int The maximum number of users to return per page.
315
+ Default: 50. See the Pagination section for more details.
316
+ :return:
317
+ """
318
+ url_without_sd_id = "rest/servicedeskapi/organization"
319
+ url_with_sd_id = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
320
+ params = {}
321
+ if start is not None:
322
+ params["start"] = int(start)
323
+ if limit is not None:
324
+ params["limit"] = int(limit)
325
+
326
+ if service_desk_id is None:
327
+ return self.get(
328
+ url_without_sd_id,
329
+ headers=self.experimental_headers,
330
+ params=params,
331
+ )
332
+ return self.get(url_with_sd_id, headers=self.experimental_headers, params=params)
333
+
334
+ # add alias for spelling consistency
335
+ get_organizations = get_organisations
336
+
337
+ def get_organization(self, organization_id):
338
+ """
339
+ Get an organization for a given organization ID
340
+
341
+ :param organization_id: str
342
+ :return: Organization
343
+ """
344
+ url = "rest/servicedeskapi/organization/{}".format(organization_id)
345
+
346
+ return self.get(url, headers=self.experimental_headers)
347
+
348
+ def get_users_in_organization(self, organization_id, start=0, limit=50):
349
+ """
350
+ Get all the users of a specified organization
351
+
352
+ :param organization_id: str
353
+ :param start: OPTIONAL: int
354
+ :param limit: OPTIONAL: int
355
+ :return: Users list in organization
356
+ """
357
+ url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
358
+ params = {}
359
+ if start is not None:
360
+ params["start"] = int(start)
361
+ if limit is not None:
362
+ params["limit"] = int(limit)
363
+
364
+ return self.get(url, headers=self.experimental_headers, params=params)
365
+
366
+ def create_organization(self, name):
367
+ """
368
+ To create an organization Jira administrator global or agent
369
+ permission is required depending on the settings
370
+
371
+ :param name: str
372
+ :return: Organization data
373
+ """
374
+ log.warning("Creating organization...")
375
+ url = "rest/servicedeskapi/organization"
376
+ data = {"name": name}
377
+
378
+ return self.post(url, headers=self.experimental_headers, data=data)
379
+
380
+ def add_organization(self, service_desk_id, organization_id):
381
+ """
382
+ Adds an organization to a servicedesk for a given servicedesk ID and organization ID
383
+
384
+ :param service_desk_id: str
385
+ :param organization_id: int
386
+ :return:
387
+ """
388
+ log.warning("Adding organization...")
389
+ url = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
390
+ data = {"organizationId": organization_id}
391
+
392
+ return self.post(url, headers=self.experimental_headers, data=data)
393
+
394
+ def remove_organization(self, service_desk_id, organization_id):
395
+ """
396
+ Removes an organization from a servicedesk for a given servicedesk ID and organization ID
397
+
398
+ :param service_desk_id: str
399
+ :param organization_id: int
400
+ :return:
401
+ """
402
+ log.warning("Removing organization...")
403
+ url = "rest/servicedeskapi/servicedesk/{}/organization".format(service_desk_id)
404
+ data = {"organizationId": organization_id}
405
+
406
+ return self.delete(url, headers=self.experimental_headers, data=data)
407
+
408
+ def delete_organization(self, organization_id):
409
+ """
410
+ Deletes an organization for a given organization ID
411
+
412
+ :param organization_id:
413
+ :return:
414
+ """
415
+ log.warning("Deleting organization...")
416
+ url = "rest/servicedeskapi/organization/{}".format(organization_id)
417
+
418
+ return self.delete(url, headers=self.experimental_headers)
419
+
420
+ def add_users_to_organization(self, organization_id, users_list=[], account_list=[]):
421
+ """
422
+ Adds users to an organization
423
+ users_list is a list of strings
424
+ account_list is a list of accountIds
425
+
426
+ :param account_list:
427
+ :param organization_id: str
428
+ :param users_list: list
429
+ :return:
430
+ """
431
+ log.warning("Adding users...")
432
+ url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
433
+ data = {"usernames": users_list, "accountIds": account_list}
434
+
435
+ return self.post(url, headers=self.experimental_headers, data=data)
436
+
437
+ def remove_users_from_organization(self, organization_id, users_list=[], account_list=[]):
438
+ """
439
+ Removes users from an organization
440
+ users_list is a list of strings
441
+ account_list is a list of accountIds
442
+
443
+ :param organization_id: str
444
+ :param users_list: list
445
+ :param account_list: list
446
+ :return:
447
+ """
448
+ log.warning("Removing users...")
449
+ url = "rest/servicedeskapi/organization/{}/user".format(organization_id)
450
+ data = {"usernames": users_list, "accountIds": account_list}
451
+
452
+ return self.delete(url, headers=self.experimental_headers, data=data)
453
+
454
+ # Attachments actions
455
+ def create_attachments(
456
+ self,
457
+ service_desk_id,
458
+ issue_id_or_key,
459
+ filenames,
460
+ public=True,
461
+ comment=None,
462
+ ):
463
+ """
464
+ Add attachment as a comment.
465
+ Setting attachment visibility is dependent on the user's permission. For example,
466
+ Agents can create either public or internal attachments,
467
+ while Unlicensed users can only create internal attachments,
468
+ and Customers can only create public attachments.
469
+ An additional comment may be provided which will be prepended to the attachments.
470
+ :param service_desk_id: str
471
+ :param issue_id_or_key: str
472
+ :param filenames: Union(List[str], str), name, if file in current directory or full path to file
473
+ :param public: OPTIONAL: bool (default is True)
474
+ :param comment: OPTIONAL: str (default is None)
475
+ :return: Request info
476
+ """
477
+ # Create temporary attachment
478
+ temp_attachment_ids = []
479
+ if not isinstance(filenames, list):
480
+ filenames = [filenames]
481
+
482
+ for filename in filenames:
483
+ temp_attachment_id = self.attach_temporary_file(service_desk_id, filename)
484
+ temp_attachment_ids.append(temp_attachment_id)
485
+
486
+ # Add attachments
487
+ return self.add_attachments(issue_id_or_key, temp_attachment_ids, public, comment)
488
+
489
+ def create_attachment(
490
+ self,
491
+ service_desk_id,
492
+ issue_id_or_key,
493
+ filename,
494
+ public=True,
495
+ comment=None,
496
+ ):
497
+ """
498
+ Add attachment as a comment.
499
+ Setting attachment visibility is dependent on the user's permission. For example,
500
+ Agents can create either public or internal attachments,
501
+ while Unlicensed users can only create internal attachments,
502
+ and Customers can only create public attachments.
503
+ An additional comment may be provided which will be prepended to the attachments.
504
+ :param service_desk_id: str
505
+ :param issue_id_or_key: str
506
+ :param filename: str, name, if file in current directory or full path to file
507
+ :param public: OPTIONAL: bool (default is True)
508
+ :param comment: OPTIONAL: str (default is None)
509
+ :return: Request info
510
+ """
511
+ log.info("Creating attachment...")
512
+ return self.create_attachments(
513
+ service_desk_id,
514
+ issue_id_or_key,
515
+ filename,
516
+ public=public,
517
+ comment=comment,
518
+ )
519
+
520
+ def attach_temporary_file(self, service_desk_id, filename):
521
+ """
522
+ Create temporary attachment, which can later be converted into permanent attachment
523
+ :param service_desk_id: str
524
+ :param filename: str
525
+ :return: Temporary Attachment ID
526
+ """
527
+ url = "rest/servicedeskapi/servicedesk/{}/attachTemporaryFile".format(service_desk_id)
528
+
529
+ # no application/json content type and an additional X-Atlassian-Token header
530
+ # https://docs.atlassian.com/jira-servicedesk/REST/4.14.1/#servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile-attachTemporaryFile
531
+ experimental_headers = self.experimental_headers.copy()
532
+ del experimental_headers["Content-Type"]
533
+ experimental_headers["X-Atlassian-Token"] = "no-check"
534
+
535
+ with open(filename, "rb") as file:
536
+ # bug https://github.com/atlassian-api/atlassian-python-api/issues/1056
537
+ # in advanced_mode it returns the raw response therefore .json() is needed
538
+ # in normal mode this is not needed and would fail
539
+ if self.advanced_mode:
540
+ result = (
541
+ self.post(path=url, headers=experimental_headers, files={"file": file})
542
+ .json()
543
+ .get("temporaryAttachments")
544
+ )
545
+ else:
546
+ result = self.post(path=url, headers=experimental_headers, files={"file": file}).get(
547
+ "temporaryAttachments"
548
+ )
549
+ temp_attachment_id = result[0].get("temporaryAttachmentId")
550
+
551
+ return temp_attachment_id
552
+
553
+ def add_attachments(self, issue_id_or_key, temp_attachment_ids, public=True, comment=None):
554
+ """
555
+ Adds temporary attachment to customer request using attach_temporary_file function
556
+ :param issue_id_or_key: str
557
+ :param temp_attachment_ids: List[str], ID from result attach_temporary_file function
558
+ :param public: bool (default is True)
559
+ :param comment: str (default is None)
560
+ :return:
561
+ """
562
+ data = {
563
+ "temporaryAttachmentIds": temp_attachment_ids,
564
+ "public": public,
565
+ "additionalComment": {"body": comment},
566
+ }
567
+ url = "rest/servicedeskapi/request/{}/attachment".format(issue_id_or_key)
568
+
569
+ return self.post(url, headers=self.experimental_headers, data=data)
570
+
571
+ def add_attachment(self, issue_id_or_key, temp_attachment_id, public=True, comment=None):
572
+ """
573
+ Adds temporary attachment to customer request using attach_temporary_file function
574
+ :param issue_id_or_key: str
575
+ :param temp_attachment_id: str, ID from result attach_temporary_file function
576
+ :param public: bool (default is True)
577
+ :param comment: str (default is None)
578
+ :return:
579
+ """
580
+ log.info("Adding attachment")
581
+ return self.add_attachments(
582
+ issue_id_or_key,
583
+ [temp_attachment_id],
584
+ public=public,
585
+ comment=comment,
586
+ )
587
+
588
+ # SLA actions
589
+ def get_sla(self, issue_id_or_key, start=0, limit=50):
590
+ """
591
+ Get the SLA information for a customer request for a given request ID or key
592
+ A request can have zero or more SLA values
593
+ IMPORTANT: The calling user must be an agent
594
+
595
+ :param issue_id_or_key: str
596
+ :param start: OPTIONAL: int
597
+ :param limit: OPTIONAL: int
598
+ :return: SLA information
599
+ """
600
+ url = "rest/servicedeskapi/request/{}/sla".format(issue_id_or_key)
601
+ params = {}
602
+ if start is not None:
603
+ params["start"] = int(start)
604
+ if limit is not None:
605
+ params["limit"] = int(limit)
606
+
607
+ response = self.get(url, params=params, headers=self.experimental_headers)
608
+ if self.advanced_mode:
609
+ return response
610
+ return (response or {}).get("values")
611
+
612
+ def get_sla_by_id(self, issue_id_or_key, sla_id):
613
+ """
614
+ Get customer request SLA information for given request ID or key and SLA metric ID
615
+ IMPORTANT: The calling user must be an agent
616
+
617
+ :param issue_id_or_key: str
618
+ :param sla_id: str
619
+ :return: SLA information
620
+ """
621
+ url = "rest/servicedeskapi/request/{0}/sla/{1}".format(issue_id_or_key, sla_id)
622
+
623
+ return self.get(url, headers=self.experimental_headers)
624
+
625
+ def sla_rebuild(self, tickets=None):
626
+ """
627
+ Fix corrupted or missing sla
628
+ https://confluence.atlassian.com/jirakb/missing-or-corrupted-sla-data-in-jira-service-management-828790603.html
629
+ :param tickets: list of tickets like [XXX-123, XXX-124]
630
+ :return:
631
+ """
632
+ if tickets is None:
633
+ tickets = []
634
+ url = "rest/servicedesk/1/servicedesk/sla/admin/task/destructive/reconstruct"
635
+ return self.post(url, data=tickets)
636
+
637
+ # Approvals
638
+
639
+ def get_approvals(self, issue_id_or_key, start=0, limit=50):
640
+ """
641
+ Get all approvals on a request, for a given request ID/Key
642
+
643
+ :param issue_id_or_key: str
644
+ :param start: OPTIONAL: int
645
+ :param limit: OPTIONAL: int
646
+ :return:
647
+ """
648
+ url = "rest/servicedeskapi/request/{}/approval".format(issue_id_or_key)
649
+ params = {}
650
+ if start is not None:
651
+ params["start"] = int(start)
652
+ if limit is not None:
653
+ params["limit"] = int(limit)
654
+
655
+ response = self.get(url, headers=self.experimental_headers, params=params)
656
+ if self.advanced_mode:
657
+ return response
658
+ return (response or {}).get("values")
659
+
660
+ def get_approval_by_id(self, issue_id_or_key, approval_id):
661
+ """
662
+ Get an approval for a given approval ID
663
+
664
+ :param issue_id_or_key: str
665
+ :param approval_id: str
666
+ :return:
667
+ """
668
+ url = "rest/servicedeskapi/request/{0}/approval/{1}".format(issue_id_or_key, approval_id)
669
+
670
+ return self.get(url, headers=self.experimental_headers)
671
+
672
+ def answer_approval(self, issue_id_or_key, approval_id, decision):
673
+ """
674
+ Answer a pending approval
675
+
676
+ :param issue_id_or_key: str
677
+ :param approval_id: str
678
+ :param decision: str
679
+ :return:
680
+ """
681
+ url = "rest/servicedeskapi/request/{0}/approval/{1}".format(issue_id_or_key, approval_id)
682
+ data = {"decision": decision}
683
+
684
+ return self.post(url, headers=self.experimental_headers, data=data)
685
+
686
+ def get_queue_settings(self, project_key):
687
+ """
688
+ Get queue settings on project
689
+
690
+ :param project_key: str
691
+ :return:
692
+ """
693
+ url = "rest/servicedeskapi/queues/{}".format(project_key)
694
+
695
+ return self.get(url, headers=self.experimental_headers)
696
+
697
+ def get_customers(self, service_desk_id, query=None, start=0, limit=50):
698
+ """
699
+ Returns a list of the customers on a service desk.
700
+
701
+ The returned list of customers can be filtered using the query parameter.
702
+ The parameter is matched against customers' displayName, name, or email.
703
+ For example, searching for "John", "Jo", "Smi", or "Smith" will match a
704
+ user with display name "John Smith"..
705
+
706
+ :param query:
707
+ :param start:
708
+ :param limit:
709
+ :param service_desk_id: str
710
+ :return: the customers added to the service desk
711
+ """
712
+ url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
713
+ params = {}
714
+ if start is not None:
715
+ params["start"] = int(start)
716
+ if limit is not None:
717
+ params["limit"] = int(limit)
718
+ if query is not None:
719
+ params["query"] = query
720
+
721
+ return self.get(url, headers=self.experimental_headers, params=params)
722
+
723
+ def add_customers(self, service_desk_id, list_of_usernames=[], list_of_accountids=[]):
724
+ """
725
+ Adds one or more existing customers to the given service desk.
726
+ If you need to create a customer, see Create customer method.
727
+
728
+ Administer project permission is required, or agents if public signups
729
+ and invites are enabled for the Service Desk project.
730
+
731
+ :param service_desk_id: str
732
+ :param list_of_usernames: list
733
+ :param list_of_accountids: list
734
+ :return: the customers added to the service desk
735
+ """
736
+ url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
737
+ data = {
738
+ "usernames": list_of_usernames,
739
+ "accountIds": list_of_accountids,
740
+ }
741
+
742
+ log.info("Adding customers...")
743
+ return self.post(url, headers=self.experimental_headers, data=data)
744
+
745
+ def remove_customers(self, service_desk_id, list_of_usernames=[], list_of_accountids=[]):
746
+ """
747
+ Removes one or more customers from a service desk. The service
748
+ desk must have closed access. If any of the passed customers are
749
+ not associated with the service desk, no changes will be made for
750
+ those customers and the resource returns a 204 success code.
751
+
752
+ :param service_desk_id: str
753
+ :param list_of_usernames: list
754
+ :param list_of_accountids: list
755
+ :return: the customers added to the service desk
756
+ """
757
+ url = "rest/servicedeskapi/servicedesk/{}/customer".format(service_desk_id)
758
+ data = {
759
+ "usernames": list_of_usernames,
760
+ "accountIds": list_of_accountids,
761
+ }
762
+
763
+ log.info("Removing customers...")
764
+ return self.delete(url, headers=self.experimental_headers, data=data)
765
+
766
+ def get_queues(self, service_desk_id, include_count=False, start=0, limit=50):
767
+ """
768
+ Returns a page of queues defined inside a service desk, for a given service desk ID.
769
+ The returned queues will include issue counts for each queue (issueCount field)
770
+ if the query param includeCount is set to true (default=false).
771
+
772
+ Permissions: The calling user must be an agent of the given service desk.
773
+
774
+ :param service_desk_id: str
775
+ :param include_count: bool
776
+ :param start: int
777
+ :param limit: int
778
+ :return: a page of queues
779
+ """
780
+ url = "rest/servicedeskapi/servicedesk/{}/queue".format(service_desk_id)
781
+ params = {}
782
+
783
+ if include_count is not None:
784
+ params["includeCount"] = bool(include_count)
785
+ if start is not None:
786
+ params["start"] = int(start)
787
+ if limit is not None:
788
+ params["limit"] = int(limit)
789
+
790
+ return self.get(url, headers=self.experimental_headers, params=params)
791
+
792
+ def get_issues_in_queue(self, service_desk_id, queue_id, start=0, limit=50):
793
+ """
794
+ Returns a page of issues inside a queue for a given queue ID.
795
+ Only fields that the queue is configured to show are returned.
796
+ For example, if a queue is configured to show only Description and Due Date,
797
+ then only those two fields are returned for each issue in the queue.
798
+
799
+ Permissions: The calling user must have permission to view the requested queue,
800
+ i.e. they must be an agent of the service desk that the queue belongs to.
801
+
802
+ :param service_desk_id: str
803
+ :param queue_id: str
804
+ :param start: int
805
+ :param limit: int
806
+ :return: a page of issues
807
+ """
808
+ url = "rest/servicedeskapi/servicedesk/{0}/queue/{1}/issue".format(service_desk_id, queue_id)
809
+ params = {}
810
+
811
+ if start is not None:
812
+ params["start"] = int(start)
813
+ if limit is not None:
814
+ params["limit"] = int(limit)
815
+
816
+ return self.get(url, headers=self.experimental_headers, params=params)
817
+
818
+ def get_plugins_info(self):
819
+ """
820
+ Provide plugins info
821
+ :return a json of installed plugins
822
+ """
823
+ url = "rest/plugins/1.0/"
824
+ return self.get(url, headers=self.no_check_headers, trailing=True)
825
+
826
+ def get_plugin_info(self, plugin_key):
827
+ """
828
+ Provide plugin info
829
+ :return a json of installed plugins
830
+ """
831
+ url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
832
+ return self.get(url, headers=self.no_check_headers, trailing=True)
833
+
834
+ def get_plugin_license_info(self, plugin_key):
835
+ """
836
+ Provide plugin license info
837
+ :return a json specific License query
838
+ """
839
+ url = "rest/plugins/1.0/{plugin_key}-key/license".format(plugin_key=plugin_key)
840
+ return self.get(url, headers=self.no_check_headers, trailing=True)
841
+
842
+ def upload_plugin(self, plugin_path):
843
+ """
844
+ Provide plugin path for upload into Jira e.g. useful for auto deploy
845
+ :param plugin_path:
846
+ :return:
847
+ """
848
+ files = {"plugin": open(plugin_path, "rb")}
849
+ upm_token = self.request(
850
+ method="GET",
851
+ path="rest/plugins/1.0/",
852
+ headers=self.no_check_headers,
853
+ trailing=True,
854
+ ).headers["upm-token"]
855
+ url = "rest/plugins/1.0/?token={upm_token}".format(upm_token=upm_token)
856
+ return self.post(url, files=files, headers=self.no_check_headers)
857
+
858
+ def delete_plugin(self, plugin_key):
859
+ """
860
+ Delete plugin
861
+ :param plugin_key:
862
+ :return:
863
+ """
864
+ url = "rest/plugins/1.0/{}-key".format(plugin_key)
865
+ return self.delete(url)
866
+
867
+ def check_plugin_manager_status(self):
868
+ url = "rest/plugins/latest/safe-mode"
869
+ return self.request(method="GET", path=url, headers=self.safe_mode_headers)
870
+
871
+ def update_plugin_license(self, plugin_key, raw_license):
872
+ """
873
+ Update license for plugin
874
+ :param plugin_key:
875
+ :param raw_license:
876
+ :return:
877
+ """
878
+ app_headers = {
879
+ "X-Atlassian-Token": "nocheck",
880
+ "Content-Type": "application/vnd.atl.plugins+json",
881
+ }
882
+ url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
883
+ data = {"rawLicense": raw_license}
884
+ return self.put(url, data=data, headers=app_headers)
885
+
886
+ def create_request_type(
887
+ self,
888
+ service_desk_id,
889
+ request_type_id,
890
+ request_name,
891
+ request_description,
892
+ request_help_text,
893
+ ):
894
+ """
895
+ Creating a request type
896
+ :param request_type_id:
897
+ :param request_help_text:
898
+ :param service_desk_id: str
899
+ :param request_name: str
900
+ :param request_description: str
901
+ """
902
+ log.warning("Creating request type...")
903
+ data = {
904
+ "issueTypeId": request_type_id,
905
+ "name": request_name,
906
+ "description": request_description,
907
+ "helpText": request_help_text,
908
+ }
909
+
910
+ url = "rest/servicedeskapi/servicedesk/{}/requesttype".format(service_desk_id)
911
+ return self.post(url, headers=self.experimental_headers, data=data)