Skip to content

Commit 044e0be

Browse files
author
Gonchik Tsymzhitov
committed
Jira: reorder the methods and set comments to easy match with Atlassian docs
1 parent 3ebeb1a commit 044e0be

File tree

1 file changed

+186
-102
lines changed

1 file changed

+186
-102
lines changed

atlassian/jira.py

Lines changed: 186 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -655,51 +655,6 @@ def get_server_info(self, do_health_check=False):
655655
check = False
656656
return self.get('rest/api/2/serverInfo', params={"doHealthCheck": check})
657657

658-
def reindex_status(self):
659-
return self.get('rest/api/2/reindex')
660-
661-
def reindex(self, comments=True, change_history=True, worklogs=True):
662-
"""
663-
Reindex the Jira instance
664-
Kicks off a reindex. Need Admin permissions to perform this reindex.
665-
:param comments: Indicates that comments should also be reindexed. Not relevant for foreground reindex,
666-
where comments are always reindexed.
667-
:param change_history: Indicates that changeHistory should also be reindexed.
668-
Not relevant for foreground reindex, where changeHistory is always reindexed.
669-
:param worklogs: Indicates that changeHistory should also be reindexed.
670-
Not relevant for foreground reindex, where changeHistory is always reindexed.
671-
:return:
672-
"""
673-
params = {}
674-
if not comments:
675-
params['indexComments'] = comments
676-
if not change_history:
677-
params['indexChangeHistory'] = change_history
678-
if not worklogs:
679-
params['indexWorklogs'] = worklogs
680-
return self.post('rest/api/2/reindex', params=params)
681-
682-
def reindex_with_type(self, indexing_type="BACKGROUND_PREFERRED"):
683-
"""
684-
Reindex the Jira instance
685-
Type of re-indexing available:
686-
FOREGROUND - runs a lock/full reindexing
687-
BACKGROUND - runs a background reindexing.
688-
If Jira fails to finish the background reindexing, respond with 409 Conflict (error message).
689-
BACKGROUND_PREFERRED - If possible do a background reindexing.
690-
If it's not possible (due to an inconsistent index), do a foreground reindexing.
691-
:param indexing_type: OPTIONAL: The default value for the type is BACKGROUND_PREFFERED
692-
:return:
693-
"""
694-
return self.post('rest/api/2/reindex?type={}'.format(indexing_type))
695-
696-
def reindex_project(self, project_key):
697-
return self.post('secure/admin/IndexProject.jspa', data='confirmed=true&key={}'.format(project_key),
698-
headers=self.form_token_headers)
699-
700-
def reindex_issue(self, list_of_):
701-
pass
702-
703658
def jql(self, jql, fields='*all', start=0, limit=None, expand=None):
704659
"""
705660
Get issues from jql search result with all related fields
@@ -1671,6 +1626,61 @@ def get_issue_status_id(self, issue_key):
16711626
url = 'rest/api/2/issue/{issue_key}?fields=status'.format(issue_key=issue_key)
16721627
return (self.get(url) or {}).get('fields').get('status').get('id')
16731628

1629+
#######################################################################################################
1630+
# The Link Issue Resource provides functionality to manage issue links.
1631+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/issueLink
1632+
#######################################################################################################
1633+
def create_issue_link(self, data):
1634+
"""
1635+
Creates an issue link between two issues.
1636+
The user requires the link issue permission for the issue which will be linked to another issue.
1637+
The specified link type in the request is used to create the link and will create a link from
1638+
the first issue to the second issue using the outward description. It also create a link from
1639+
the second issue to the first issue using the inward description of the issue link type.
1640+
It will add the supplied comment to the first issue. The comment can have a restriction who can view it.
1641+
If group is specified, only users of this group can view this comment, if roleLevel is specified only users
1642+
who have the specified role can view this comment.
1643+
The user who creates the issue link needs to belong to the specified group or have the specified role.
1644+
:param data: i.e.
1645+
{
1646+
"type": {"name": "Duplicate" },
1647+
"inwardIssue": { "key": "HSP-1"},
1648+
"outwardIssue": {"key": "MKY-1"},
1649+
"comment": { "body": "Linked related issue!",
1650+
"visibility": { "type": "group", "value": "jira-software-users" }
1651+
}
1652+
}
1653+
:return:
1654+
"""
1655+
log.info(
1656+
'Linking issue {inward} and {outward}'.format(inward=data['inwardIssue'], outward=data['outwardIssue']))
1657+
url = 'rest/api/2/issueLink'
1658+
return self.post(url, data=data)
1659+
1660+
def get_issue_link(self, link_id):
1661+
"""
1662+
Returns an issue link with the specified id.
1663+
:param link_id: the issue link id.
1664+
:return:
1665+
"""
1666+
url = 'rest/api/2/issueLink/{}'.format(link_id)
1667+
return self.get(url)
1668+
1669+
def remove_issue_link(self, link_id):
1670+
"""
1671+
Deletes an issue link with the specified id.
1672+
To be able to delete an issue link you must be able to view both issues
1673+
and must have the link issue permission for at least one of the issues.
1674+
:param link_id: the issue link id.
1675+
:return:
1676+
"""
1677+
url = 'rest/api/2/issueLink/{}'.format(link_id)
1678+
return self.delete(url)
1679+
1680+
#######################################################################################################
1681+
# Rest resource to retrieve a list of issue link types.
1682+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/issueLinkType
1683+
#######################################################################################################
16741684
def get_issue_link_types(self):
16751685
"""Returns a list of available issue link types,
16761686
if issue linking is enabled.
@@ -1742,53 +1752,6 @@ def update_issue_link_type(self, issue_link_type_id, data):
17421752
url = 'rest/api/2/issueLinkType/{issueLinkTypeId}'.format(issueLinkTypeId=issue_link_type_id)
17431753
return self.put(url, data=data)
17441754

1745-
def create_issue_link(self, data):
1746-
"""
1747-
Creates an issue link between two issues.
1748-
The user requires the link issue permission for the issue which will be linked to another issue.
1749-
The specified link type in the request is used to create the link and will create a link from
1750-
the first issue to the second issue using the outward description. It also create a link from
1751-
the second issue to the first issue using the inward description of the issue link type.
1752-
It will add the supplied comment to the first issue. The comment can have a restriction who can view it.
1753-
If group is specified, only users of this group can view this comment, if roleLevel is specified only users
1754-
who have the specified role can view this comment.
1755-
The user who creates the issue link needs to belong to the specified group or have the specified role.
1756-
:param data: i.e.
1757-
{
1758-
"type": {"name": "Duplicate" },
1759-
"inwardIssue": { "key": "HSP-1"},
1760-
"outwardIssue": {"key": "MKY-1"},
1761-
"comment": { "body": "Linked related issue!",
1762-
"visibility": { "type": "group", "value": "jira-software-users" }
1763-
}
1764-
}
1765-
:return:
1766-
"""
1767-
log.info(
1768-
'Linking issue {inward} and {outward}'.format(inward=data['inwardIssue'], outward=data['outwardIssue']))
1769-
url = 'rest/api/2/issueLink'
1770-
return self.post(url, data=data)
1771-
1772-
def remove_issue_link(self, link_id):
1773-
"""
1774-
Deletes an issue link with the specified id.
1775-
To be able to delete an issue link you must be able to view both issues
1776-
and must have the link issue permission for at least one of the issues.
1777-
:param link_id: the issue link id.
1778-
:return:
1779-
"""
1780-
url = 'rest/api/2/issueLink/{}'.format(link_id)
1781-
return self.delete(url)
1782-
1783-
def get_issue_link(self, link_id):
1784-
"""
1785-
Returns an issue link with the specified id.
1786-
:param link_id: the issue link id.
1787-
:return:
1788-
"""
1789-
url = 'rest/api/2/issueLink/{}'.format(link_id)
1790-
return self.get(url)
1791-
17921755
def get_resolution_by_id(self, resolution_id):
17931756
"""
17941757
Get Resolution info by id
@@ -1941,6 +1904,12 @@ def set_permissionscheme_grant(self, permission_id, new_permission):
19411904

19421905
return self.post(url, data=new_permission)
19431906

1907+
#######################################################################################################
1908+
# REST resource that allows to view security schemes defined in the product.
1909+
# Resource for managing priority schemes.
1910+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/issuesecurityschemes
1911+
# https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/priorityschemes
1912+
#######################################################################################################
19441913
def get_issue_security_schemes(self):
19451914
"""
19461915
Returns all issue security schemes that are defined
@@ -2003,7 +1972,6 @@ def get_project_issue_security_scheme(self, project_id_or_key, only_levels=False
20031972
return response.get('levels') or None
20041973
return response
20051974

2006-
# Priority Schemes
20071975
def get_all_priority_schemes(self, start=0, limit=100, expand=None):
20081976
"""
20091977
Returns all priority schemes.
@@ -2042,8 +2010,11 @@ def create_priority_scheme(self, data):
20422010
"""
20432011
return self.post(path="rest/api/2/priorityschemes", data=data)
20442012

2045-
# api/2/project/{projectKeyOrId}/priorityscheme
2013+
#######################################################################################################
20462014
# Resource for associating priority schemes and projects.
2015+
# Reference:
2016+
# https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/project/{projectKeyOrId}/priorityscheme
2017+
#######################################################################################################
20472018
def get_priority_scheme_of_project(self, project_key_or_id, expand=None):
20482019
"""
20492020
Gets a full representation of a priority scheme in JSON format used by specified project.
@@ -2074,12 +2045,128 @@ def assign_priority_scheme_for_project(self, project_key_or_id, priority_scheme_
20742045
data = {"id": priority_scheme_id}
20752046
return self.put(url, data=data)
20762047

2077-
"""
2048+
#######################################################################################################
2049+
# Provide security level information of the given project for the current user.
2050+
# Reference:
2051+
# https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/project/{projectKeyOrId}/securitylevel
2052+
#######################################################################################################
2053+
def get_security_level_for_project(self, project_key_or_id):
2054+
"""
2055+
Returns all security levels for the project that the current logged in user has access to.
2056+
If the user does not have the Set Issue Security permission, the list will be empty.
2057+
:param project_key_or_id:
2058+
:return: Returns a list of all security levels in a project for which the current user has access.
2059+
"""
2060+
url = 'rest/api/2/project/{projectKeyOrId}/securitylevel'.format(projectKeyOrId=project_key_or_id)
2061+
return self.get(url)
2062+
2063+
#######################################################################################################
2064+
# Provide project type
2065+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/project/type
2066+
#######################################################################################################
2067+
def get_all_project_types(self):
2068+
"""
2069+
Returns all the project types defined on the Jira instance,
2070+
not taking into account whether the license to use those project types is valid or not.
2071+
:return: Returns a list with all the project types defined on the Jira instance.
2072+
"""
2073+
url = 'rest/api/2/project/type'
2074+
return self.get(url)
2075+
2076+
#######################################################################################################
2077+
# Provide project categories
2078+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/projectCategory
2079+
#######################################################################################################
2080+
def get_all_project_categories(self):
2081+
"""
2082+
Returns all project categories
2083+
:return: Returns a list of project categories.
2084+
"""
2085+
url = 'rest/api/2/projectCategory'
2086+
return self.get(url)
2087+
2088+
#######################################################################################################
2089+
# Project validates
2090+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/projectvalidate
2091+
#######################################################################################################
2092+
def get_project_validated_key(self, key):
2093+
"""
2094+
Validates a project key.
2095+
:param key: the project key
2096+
:return:
2097+
"""
2098+
params = {'key': key}
2099+
url = 'rest/api/2/projectvalidate/key'
2100+
return self.get(url, params=params)
2101+
2102+
#######################################################################################################
2103+
# REST resource for starting/stopping/querying indexing.
2104+
# Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/reindex
2105+
#######################################################################################################
2106+
def reindex(self, comments=True, change_history=True, worklogs=True, indexing_type="BACKGROUND_PREFERRED"):
2107+
"""
2108+
Reindex the Jira instance
2109+
Kicks off a reindex. Need Admin permissions to perform this reindex.
2110+
Type of re-indexing available:
2111+
FOREGROUND - runs a lock/full reindexing
2112+
BACKGROUND - runs a background reindexing.
2113+
If Jira fails to finish the background reindexing, respond with 409 Conflict (error message).
2114+
BACKGROUND_PREFERRED - If possible do a background reindexing.
2115+
If it's not possible (due to an inconsistent index), do a foreground reindexing.
2116+
:param comments: Indicates that comments should also be reindexed. Not relevant for foreground reindex,
2117+
where comments are always reindexed.
2118+
:param change_history: Indicates that changeHistory should also be reindexed.
2119+
Not relevant for foreground reindex, where changeHistory is always reindexed.
2120+
:param worklogs: Indicates that changeHistory should also be reindexed.
2121+
Not relevant for foreground reindex, where changeHistory is always reindexed.
2122+
:param indexing_type: OPTIONAL: The default value for the type is BACKGROUND_PREFFERED
2123+
:return:
2124+
"""
2125+
params = {}
2126+
if not comments:
2127+
params['indexComments'] = comments
2128+
if not change_history:
2129+
params['indexChangeHistory'] = change_history
2130+
if not worklogs:
2131+
params['indexWorklogs'] = worklogs
2132+
if not indexing_type:
2133+
params['type'] = indexing_type
2134+
return self.post('rest/api/2/reindex', params=params)
2135+
2136+
def reindex_with_type(self, indexing_type="BACKGROUND_PREFERRED"):
2137+
"""
2138+
Reindex the Jira instance
2139+
Type of re-indexing available:
2140+
FOREGROUND - runs a lock/full reindexing
2141+
BACKGROUND - runs a background reindexing.
2142+
If Jira fails to finish the background reindexing, respond with 409 Conflict (error message).
2143+
BACKGROUND_PREFERRED - If possible do a background reindexing.
2144+
If it's not possible (due to an inconsistent index), do a foreground reindexing.
2145+
:param indexing_type: OPTIONAL: The default value for the type is BACKGROUND_PREFFERED
2146+
:return:
2147+
"""
2148+
return self.reindex(indexing_type=indexing_type)
2149+
2150+
def reindex_status(self):
2151+
"""
2152+
Returns information on the system reindexes.
2153+
If a reindex is currently taking place then information about this reindex is returned.
2154+
If there is no active index task, then returns information about the latest reindex task run,
2155+
otherwise returns a 404 indicating that no reindex has taken place.
2156+
:return:
2157+
"""
2158+
return self.get('rest/api/2/reindex')
2159+
2160+
def reindex_project(self, project_key):
2161+
return self.post('secure/admin/IndexProject.jspa', data='confirmed=true&key={}'.format(project_key),
2162+
headers=self.form_token_headers)
2163+
2164+
def reindex_issue(self, list_of_):
2165+
pass
2166+
20782167
#######################################################################
2079-
# Tempo Account REST API implements #
2168+
# Tempo Account REST API implements
20802169
#######################################################################
2081-
"""
2082-
20832170
def tempo_account_get_accounts(self, skip_archived=None, expand=None):
20842171
"""
20852172
Get all Accounts that the logged in user has permission to browse.
@@ -2602,12 +2689,9 @@ def tempo_timesheets_get_private_configuration(self):
26022689
def tempo_teams_get_memberships_for_member(self, username):
26032690
return self.get('rest/tempo-teams/2/user/{}/memberships'.format(username))
26042691

2605-
"""
26062692
#######################################################################
2607-
# Agile(Formerly Greenhopper) REST API implements #
2693+
# Agile(Formerly Greenhopper) REST API implements
26082694
#######################################################################
2609-
"""
2610-
26112695
def get_all_agile_boards(self, board_name=None, project_key=None, board_type=None, start=0, limit=50):
26122696
"""
26132697
Returns all boards. This only includes boards that the user has permission to view.

0 commit comments

Comments
 (0)