Skip to content

Commit

Permalink
Jira: update insight related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gonchik committed Jan 3, 2023
1 parent 5a891c7 commit b475aab
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
16 changes: 13 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ Atlassian Python API wrapper

What is it?
___________
This package is used to provide a **simple** python interface for interacting with Atlassian products
(Server, Data Center and Cloud) and apps from ecosystem (Portfolio, XRay).
It is based on the official public Rest API documentation and private methods (+ xml+rpc, raw http request).
The **atlassian-python-api** library provides a **simple** and convenient way to interact with Atlassian products
(such as Jira Service management, Jira Software, Confluence, Bitbucket and apps Insight, X-Ray) using Python.
It is based on the official REST APIs of these products, as well as additional private methods and protocols
(such as xml+rpc and raw HTTP requests).
This library can be used to automate tasks, integrate with other tools and systems,
and build custom applications that interact with Atlassian products.
It supports a wide range of Atlassian products, including Jira, Confluence, Bitbucket, and others,
and is compatible with both Atlassian Server and Cloud instances.

Overall, the **atlassian-python-api** is a useful tool for Python developers who want to work with Atlassian products.
It is well-documented and actively maintained, and provides a convenient way to access the full range of
functionality offered by the Atlassian REST APIs.


Documentation
_____________
Expand Down
42 changes: 42 additions & 0 deletions atlassian/insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def __get_workspace_id(self):
0
]["workspaceId"]

def _get_insight_workspace_ids(self):
"""
Returns all Insight workspace Ids.
:return: List
"""
result = self.get(
"rest/servicedeskapi/insight/workspace",
headers=self.experimental_headers,
)
return [i["workspaceId"] for i in result["values"]]

def _get_insight_workspace_id(self):
"""
Returns the first Insight workspace ID.
:return: str
"""
return next(iter(self._get_insight_workspace_ids()))

# Attachments
def get_attachments_of_objects(self, object_id):
"""
Expand Down Expand Up @@ -600,3 +618,27 @@ def get_progress_of_import(self, import_id):
# https://developer.atlassian.com/cloud/insight/rest/api-group-config/#api-config-statustype-id-put
# TODO: Delete config statustype {id}:
# https://developer.atlassian.com/cloud/insight/rest/api-group-config/#api-config-statustype-id-delete

# Update Issue with Insight Field
def update_issue_insight_field(self, key, field_id, insight_keys, add=False):
"""
Set the value of an Insight field.
Args:
key (str): Jira issue key, eg. SFT-446
field_id (str): The internal Jira name of the Insight field, eg. customfield_10200
insight_keys (list): List of Insight objects to associate with the field. Limited
to 20 objects. If the field only takes a single object pass a single value list.
add (bool, optional): Add to the existing field rather than setting the field value.
Defaults to False.
Returns:
[type]: The insight object updated.
"""
base_url = self.resource_url("issue")
action = "add" if add else "set"
data = {
"update": {
field_id: [{action: [{"key": i} for i in insight_keys]}],
}
}
data = {"fields": {field_id: [{"key": i} for i in insight_keys]}}
return self.put("{base_url}/{key}".format(base_url=base_url, key=key), data=data)
23 changes: 20 additions & 3 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,10 +1872,27 @@ def user_get_websudo(self):

def invalidate_websudo(self):
"""
This method invalidates the any current WebSudo session.
This method invalidates any current WebSudo session.
"""
return self.delete("rest/auth/1/websudo")

def users_get_all(
self,
start=0,
limit=50,
):
"""
:param start:
:param limit:
:return:
"""
url = self.resource_url("users/search")
params = {
"startAt": start,
"maxResults": limit,
}
return self.get(url, params=params)

def user_find_by_user_string(
self,
username=None,
Expand Down Expand Up @@ -1909,8 +1926,8 @@ def user_find_by_user_string(
"""
url = self.resource_url("user/search")
params = {
"includeActive": include_active_users,
"includeInactive": include_inactive_users,
"includeActive": str(include_active_users).lower(),
"includeInactive": str(include_inactive_users).lower(),
"startAt": start,
"maxResults": limit,
}
Expand Down

0 comments on commit b475aab

Please sign in to comment.