Skip to content

Commit

Permalink
Support for the new 'createmeta' API in Jira 8.4+ (#1527)
Browse files Browse the repository at this point in the history
* Support for the new 'createmeta' API in Jira 8.4+

* Accounting for Jira Cloud API differences.
  • Loading branch information
pmilosev committed Jan 29, 2023
1 parent 4c3e679 commit 2e14696
Showing 1 changed file with 67 additions and 4 deletions.
71 changes: 67 additions & 4 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,8 @@ def create_issue(
a complete Issue object to the caller; this behavior can be controlled through the 'prefetch' argument.
Jira projects may contain many different issue types. Some issue screens have different requirements for
fields in a new issue. This information is available through the 'createmeta' method. Further examples are
available here: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue
fields in a new issue. This information is available through the 'createmeta' set of methods. Further examples
are available here: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue
Args:
fields (Optional[Dict[str, Any]]): a dict containing field names and the values to use. If present, all other keyword arguments
Expand Down Expand Up @@ -1681,8 +1681,8 @@ def create_customer_request(
a complete Issue object to the caller; this behavior can be controlled through the 'prefetch' argument.
Jira projects may contain many different issue types. Some issue screens have different requirements for
fields in a new issue. This information is available through the 'createmeta' method. Further examples are
available here: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue
fields in a new issue. This information is available through the 'createmeta' set of methods. Further examples
are available here: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue
Args:
fields (Dict[str, Any]): a dict containing field names and the values to use. If present, all other keyword arguments
Expand Down Expand Up @@ -1722,6 +1722,54 @@ def create_customer_request(
else:
return Issue(self._options, self._session, raw=raw_issue_json)

def createmeta_issuetypes(
self,
projectIdOrKey: Union[str, int],
) -> Dict[str, Any]:
"""Get the issue types metadata for a given project, required to create issues.
This API was introduced in JIRA Server / DC 8.4 as a replacement for the more general purpose API 'createmeta'.
For details see: https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
Args:
projectIdOrKey (Union[str, int]): id or key of the project for which to get the metadata.
Returns:
Dict[str, Any]
"""
if self._is_cloud or self._version < (8, 4, 0):
raise JIRAError(
f"Unsupported JIRA deployment type: {self.deploymentType} or version: {self._version}. "
"Use 'createmeta' instead."
)

return self._get_json(f"issue/createmeta/{projectIdOrKey}/issuetypes")

def createmeta_fieldtypes(
self,
projectIdOrKey: Union[str, int],
issueTypeId: Union[str, int],
) -> Dict[str, Any]:
"""Get the field metadata for a given project and issue type, required to create issues.
This API was introduced in JIRA Server / DC 8.4 as a replacement for the more general purpose API 'createmeta'.
For details see: https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
Args:
projectIdOrKey (Union[str, int]): id or key of the project for which to get the metadata.
issueTypeId (Union[str, int]): id of the issue type for which to get the metadata.
Returns:
Dict[str, Any]
"""
if self._is_cloud or self._version < (8, 4, 0):
raise JIRAError(
f"Unsupported JIRA deployment type: {self.deploymentType} or version: {self._version}. "
"Use 'createmeta' instead."
)

return self._get_json(
f"issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}"
)

def createmeta(
self,
projectKeys: Optional[Union[Tuple[str, str], str]] = None,
Expand Down Expand Up @@ -1750,6 +1798,21 @@ def createmeta(
Dict[str, Any]
"""

if not self._is_cloud:
if self._version >= (9, 0, 0):
raise JIRAError(
f"Unsupported JIRA version: {self._version}. "
"Use 'createmeta_issuetypes' and 'createmeta_fieldtypes' instead."
)
elif self._version >= (8, 4, 0):
warnings.warn(
"This API have been deprecated in JIRA 8.4 and is removed in JIRA 9.0. "
"Use 'createmeta_issuetypes' and 'createmeta_fieldtypes' instead.",
DeprecationWarning,
stacklevel=2,
)

params: Dict[str, Any] = {}
if projectKeys is not None:
params["projectKeys"] = projectKeys
Expand Down

0 comments on commit 2e14696

Please sign in to comment.