@@ -1722,6 +1722,94 @@ def create_customer_request(
17221722 else :
17231723 return Issue (self ._options , self ._session , raw = raw_issue_json )
17241724
1725+ def _createmeta_issuetypes (self , project : Union [str , int ]) -> Dict [str , int ]:
1726+ """Find all issuetypes for createmeta in project"""
1727+
1728+ def _iter ():
1729+ params = {"startAt" : 0 }
1730+ while True :
1731+ try :
1732+ resp = self ._get_json (
1733+ f"issue/createmeta/{ project } /issuetypes" , params
1734+ )
1735+ except JIRAError :
1736+ raise JIRAError (
1737+ status_code = 500 ,
1738+ text = f"JIRA: There is no such project { project } " ,
1739+ )
1740+ yield from resp ["values" ]
1741+ params ["startAt" ] = params ["startAt" ] + resp ["maxResults" ]
1742+ if resp ["total" ] < params ["startAt" ]:
1743+ break
1744+
1745+ meta_source = _iter ()
1746+ return {v ["name" ]: v ["id" ] for v in meta_source }
1747+
1748+ def _get_project_createmeta_issuetype (
1749+ self ,
1750+ project : Union [str , int ],
1751+ issueTypeName : str = None ,
1752+ issueTypeId : int = None ,
1753+ ) -> Dict [str , Any ]:
1754+ """Returns createmeta fields for project+issuetype. if issuetypeId specifyies it skips list of issuetypes"""
1755+
1756+ def _iter (issuetypeid : int ):
1757+ params = {"startAt" : 0 }
1758+ while True :
1759+ resp = self ._get_json (
1760+ f"issue/createmeta/{ project } /issuetypes/{ issuetypeid } " , params
1761+ )
1762+ yield from resp ["values" ]
1763+ params ["startAt" ] = params ["startAt" ] + resp ["maxResults" ]
1764+ if resp ["total" ] < params ["startAt" ]:
1765+ break
1766+
1767+ issuetype_id = issueTypeId
1768+ if issueTypeId is None :
1769+ _meta = self ._createmeta_issuetypes (project )
1770+ issuetype_id = _meta .get (issueTypeName )
1771+ if issuetype_id is None :
1772+ raise JIRAError (
1773+ status_code = 500 ,
1774+ text = f"JIRA:There is no such issueType { issueTypeName } in { project } project" ,
1775+ )
1776+ meta_source = _iter (issuetype_id )
1777+ return {v ["fieldId" ]: v for v in meta_source }
1778+
1779+ def is_84_and_later (self ):
1780+ return self ._version >= (8 , 4 , 0 )
1781+
1782+ def createmeta_v2 (
1783+ self ,
1784+ projectKey : Optional [str ] = None ,
1785+ projectId : Optional [int ] = None ,
1786+ issueTypeName : Optional [str ] = None ,
1787+ issueTypeId : Optional [int ] = None ,
1788+ ) -> Dict [str , Any ]:
1789+ """Get the metadata required to create issues for particular project and issue type
1790+
1791+ Args:
1792+ projectKey (Optional[str]): key of project to find issue type.
1793+ It is single value string. Has precedence over `projectId`
1794+ projectId (Optional[int]): id of project to find issue type.
1795+ It is single value int
1796+ issueTypeName (Optional[str]): issueType to find fields metadata
1797+ It is single value string. Has precedence over `issueTypeId`
1798+ issueTypeId (Optional[int]): issueType to find fields metadata
1799+ It is single value int.
1800+ Returns:
1801+ Dict[str, Any]: Dictionary similar todeperecated createmeta returns in project[0].issuetype[0].fields
1802+ """
1803+
1804+ if self .is_84_and_later ():
1805+ project : Union [str , int ] = projectKey or projectId
1806+ meta = self ._get_project_createmeta_issuetype (
1807+ project = project , issueTypeName = issueTypeName , issueTypeId = issueTypeId
1808+ )
1809+ return meta
1810+ else :
1811+ raise JIRAError ("Not supported REST API in pre 8.4 versions" )
1812+
17251813 def createmeta (
17261814 self ,
17271815 projectKeys : Optional [Union [Tuple [str , str ], str ]] = None ,
@@ -1750,6 +1838,10 @@ def createmeta(
17501838 Dict[str, Any]
17511839
17521840 """
1841+
1842+ if self .is_84_and_later ():
1843+ DeprecationWarning ("The `createmeta` is deprecated, use createmeta_v2" )
1844+
17531845 params : Dict [str , Any ] = {}
17541846 if projectKeys is not None :
17551847 params ["projectKeys" ] = projectKeys
0 commit comments