Skip to content

Commit 49f444a

Browse files
committed
added simple wrapper
1 parent 64e86be commit 49f444a

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed

atlassian/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from .portfolio import Portfolio
99
from .service_desk import ServiceDesk
1010
from .xray import Xray
11+
from .insight import Insight
12+
1113

1214
__all__ = [
1315
"Confluence",
@@ -20,4 +22,5 @@
2022
"ServiceDesk",
2123
"MarketPlace",
2224
"Xray",
25+
"Insight",
2326
]

atlassian/insight.py

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# coding=utf-8
2+
import logging
3+
4+
from .rest_client import AtlassianRestAPI
5+
6+
log = logging.getLogger(__name__)
7+
8+
9+
class Insight(AtlassianRestAPI):
10+
"""Insight for Jira API wrapper."""
11+
12+
# https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/
13+
14+
def __init__(self, *args, **kwargs):
15+
super(Insight, self).__init__(*args, **kwargs)
16+
17+
# Attachments
18+
def get_attachments_of_objects(self, object_id):
19+
"""
20+
Get Attachment info
21+
Example output:
22+
[
23+
{
24+
"id": 1,
25+
"author": "admin",
26+
"mimeType": "image/png",
27+
"filename": "astronaut.png",
28+
"filesize": "490 B",
29+
"created": "2019-11-27T11:42:22.283Z",
30+
"comment": "",
31+
"commentOutput": "",
32+
"url": "http://jira/rest/insight/1.0/attachments/1"
33+
}
34+
]
35+
36+
:param object_id Object ID
37+
:return list of object
38+
id: required(string)
39+
author: (string)
40+
mimeType: (string)
41+
filename: required(string)
42+
filesize: (string)
43+
created: required(datetime)
44+
comment: (string)
45+
commentOutput: (string)
46+
url: required(string)
47+
"""
48+
url = "rest/insight/1.0/attachments/object/{objectId}".format(objectId=object_id)
49+
return self.get(url)
50+
51+
def upload_attachment_to_object(self, object_id, filename):
52+
"""
53+
Add attachment to Object
54+
:param object_id: int
55+
:param filename: str, name, if file in current directory or full path to file
56+
"""
57+
log.warning("Adding attachment...")
58+
url = "rest/insight/1.0/attachments/object/{objectId}".format(objectId=object_id)
59+
with open(filename, "rb") as attachment:
60+
files = {"file": attachment}
61+
return self.post(url, headers=self.no_check_headers, files=files)
62+
63+
def delete_attachment(self, attachment_id):
64+
"""
65+
Add attachment to Object
66+
:param attachment_id: int
67+
"""
68+
log.warning("Adding attachment...")
69+
url = "rest/insight/1.0/attachments/{attachmentId}".format(attachmentId=attachment_id)
70+
return self.delete(url)
71+
72+
# Comments
73+
# Handle comments on objets
74+
def add_comment_to_object(self, comment, object_id, role):
75+
"""
76+
Add comment to Object
77+
78+
:param comment: str
79+
:param object_id: int
80+
:param role: int
81+
0 Insight Users
82+
1 Insight Managers
83+
2 Insight Administrators
84+
3 Insight Developers
85+
:return:
86+
{
87+
"created": "2019-11-27T12:37:41.492Z",
88+
"updated": "2019-11-27T12:37:41.492Z",
89+
"id": 1,
90+
"actor": {
91+
"avatarUrl": "https://www.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028?d=mm&s=48",
92+
"displayName": "admin",
93+
"name": "admin",
94+
"key": "admin",
95+
"renderedLink": "<a href=\"/jira/secure/ViewProfile.jspa?name=admin\">admin</a>",
96+
"isDeleted": false
97+
},
98+
"role": 0,
99+
"comment": "A comment to be added",
100+
"commentOutput": "A comment to be added",
101+
"objectId": 1,
102+
"canEdit": true,
103+
"canDelete": true
104+
}
105+
"""
106+
params = {"comment": comment, "objectId": object_id, "role": role}
107+
url = "rest/insight/1.0/comment/create"
108+
return self.post(url, params=params)
109+
110+
def get_comment_of_object(self, object_id):
111+
"""
112+
The object id to fetch comments from
113+
:param object_id:
114+
:return:
115+
"""
116+
url = "rest/insight/1.0/comment/object/{objectId}".format(objectId=object_id)
117+
return self.get(url)
118+
119+
# Icon
120+
# Resources dedicated to load and find icons
121+
def get_icon_by_id(self, id):
122+
"""
123+
Load a single icon by id
124+
:param id:
125+
:return:
126+
{
127+
"id": 1,
128+
"name": "Delete",
129+
"url16": "http://jira/rest/insight/1.0/icon/1/icon.png?size=16",
130+
"url48": "http://jira/rest/insight/1.0/icon/1/icon.png?size=48"
131+
}
132+
"""
133+
url = "rest/insight/1.0/icon/{id}".format(id=id)
134+
return self.get(url)
135+
136+
def get_all_global_icons(self):
137+
"""
138+
All existing global icons
139+
:return:
140+
"""
141+
url = "rest/insight/1.0/icon/global"
142+
return self.get(url)
143+
144+
# Import
145+
# Start configured imports. To see an ongoing import see the Progress resource
146+
def start_import_configuration(self, id):
147+
"""
148+
The id of the import configuration that should be started
149+
:param id:
150+
:return:
151+
"""
152+
url = "rest/insight/1.0/import/start/{id}".format(id=id)
153+
return self.post(url)
154+
155+
# Index
156+
# Handle the indexing of Insight
157+
def reindex_insight(self):
158+
"""
159+
Should the reindex clean the index before doing the reindex
160+
:return:
161+
"""
162+
url = "rest/insight/1.0/index/reindex/start"
163+
return self.post(url)
164+
165+
def reindex_current_node_insight(self):
166+
"""
167+
Should the reindex clean the index before doing the reindex
168+
:return:
169+
"""
170+
url = "rest/insight/1.0/index/reindex/currentnode"
171+
return self.post(url)
172+
173+
# IQL
174+
# Resource dedicated to finding objects based on the Insight Query Language (IQL)
175+
def iql(self, iql, object_schema_id, page=1, order_by_attribute_id=None, order_asc=True, result_per_page=25,
176+
include_attributes=True, include_attributes_deep=1, include_type_attributes=False,
177+
include_extended_info=False, extended=None):
178+
"""
179+
180+
:param iql:
181+
:param object_schema_id:
182+
:param page:
183+
:param order_by_attribute_id:
184+
:param order_asc:
185+
:param result_per_page:
186+
:param include_attributes:
187+
:param include_attributes_deep:
188+
:param include_type_attributes:
189+
:param include_extended_info:
190+
:param extended:
191+
:return:
192+
"""
193+
params = {"iql": iql, "objectSchemaId": object_schema_id, "page": page}
194+
if order_by_attribute_id:
195+
params["orderByAttributeId"] = order_by_attribute_id
196+
params["orderAsc"] = order_asc
197+
params["resultPerPage"] = result_per_page
198+
params["includeAttributes"] = include_attributes
199+
params["includeAttributesDeep"] = include_attributes_deep
200+
params["includeTypeAttributes"] = include_type_attributes
201+
params["includeExtendedInfo"] = include_extended_info
202+
if extended:
203+
params["extended"] = extended
204+
url = "rest/insight/1.0/iql/objects"
205+
return self.get(url, params=params)

0 commit comments

Comments
 (0)