-
-
Notifications
You must be signed in to change notification settings - Fork 896
add createmeta_84age implementation #1503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8d90b35
f5a4752
5708df1
09505e2
e3b7a81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ | |
| Filter, | ||
| Group, | ||
| Issue, | ||
| IssueField, | ||
| IssueLink, | ||
| IssueLinkType, | ||
| IssueProperty, | ||
|
|
@@ -1722,6 +1723,82 @@ def create_customer_request( | |
| else: | ||
| return Issue(self._options, self._session, raw=raw_issue_json) | ||
|
|
||
| def _get_project_createmeta_issuetype( | ||
| self, | ||
| project: Union[str, int], | ||
| issueTypeName: str = None, | ||
| issueTypeId: int = None, | ||
| ) -> Dict[str, Any]: | ||
| """Returns createmeta fields for project+issuetype. if issuetypeId specifyies it skips list of issuetypes""" | ||
|
|
||
| issuetype_id = issueTypeId | ||
| if issueTypeId is None: | ||
| try: | ||
| f: ResultList[IssueType] = self._fetch_pages( | ||
| IssueType, | ||
| "values", | ||
| f"issue/createmeta/{project}/issuetypes", | ||
| 0, | ||
| 0, | ||
| None, | ||
| ) | ||
| _meta = [v.id for v in f if v.name == issueTypeName] | ||
| if len(_meta) == 1: | ||
| issuetype_id = _meta[0] | ||
| except JIRAError: | ||
| raise JIRAError( | ||
| status_code=500, | ||
| text=f"JIRA: There is no such project {project}", | ||
| ) | ||
| if issuetype_id is None: | ||
| raise JIRAError( | ||
| status_code=500, | ||
dshvedchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| text=f"JIRA: There is no such issueType {issueTypeName} in {project} project", | ||
| ) | ||
| meta_source: ResultList[IssueField] = self._fetch_pages( | ||
| IssueField, | ||
| "values", | ||
| f"issue/createmeta/{project}/issuetypes/{issuetype_id}", | ||
| 0, | ||
| 0, | ||
| None, | ||
| ) | ||
| return {v.fieldId: v for v in meta_source} | ||
|
|
||
| def is_84_and_later(self): | ||
| return self._version >= (8, 4, 0) | ||
|
|
||
| def createmeta_v2( | ||
| self, | ||
| projectKey: Optional[str] = None, | ||
|
||
| projectId: Optional[int] = None, | ||
| issueTypeName: Optional[str] = None, | ||
| issueTypeId: Optional[int] = None, | ||
| ) -> Dict[str, IssueField]: | ||
| """Get the metadata required to create issues for particular project and issue type | ||
|
|
||
| Args: | ||
| projectKey (Optional[str]): key of project to find issue type. | ||
| It is single value string. Has precedence over `projectId` | ||
| projectId (Optional[int]): id of project to find issue type. | ||
| It is single value int | ||
| issueTypeName (Optional[str]): issueType to find fields metadata | ||
| It is single value string. Has precedence over `issueTypeId` | ||
| issueTypeId (Optional[int]): issueType to find fields metadata | ||
| It is single value int. | ||
| Returns: | ||
| Dict[str, IssueField]: dict fieldId:IssueField | ||
| """ | ||
|
|
||
| if self.is_84_and_later(): | ||
| project: Union[str, int] = projectKey or projectId | ||
| meta = self._get_project_createmeta_issuetype( | ||
| project=project, issueTypeName=issueTypeName, issueTypeId=issueTypeId | ||
| ) | ||
| return meta | ||
| else: | ||
| raise JIRAError("Not supported REST API in pre 8.4 versions") | ||
|
|
||
| def createmeta( | ||
| self, | ||
| projectKeys: Optional[Union[Tuple[str, str], str]] = None, | ||
|
|
@@ -1750,6 +1827,15 @@ def createmeta( | |
| Dict[str, Any] | ||
|
|
||
| """ | ||
|
|
||
| if self._version >= (9, 0, 0): | ||
| raise NotImplementedError( | ||
| "Support for createmeta search in server" ">= 9.0.0 has been removed." | ||
| ) | ||
|
|
||
| if self.is_84_and_later(): | ||
| DeprecationWarning("The `createmeta` is deprecated, use createmeta_v2") | ||
|
||
|
|
||
| params: Dict[str, Any] = {} | ||
| if projectKeys is not None: | ||
| params["projectKeys"] = projectKeys | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't try and set our own status code. I would just let this exception bubble up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could instead use the existing methods on the client to check if a project exists, for example like so:
jira/tests/conftest.py
Line 202 in 7846ac3
Might be making this its own method, and use it in the test harness as well.